fix(ux): don't throw error when company defaults aren't set (#34825)

fix(ux): don't throw error when company defaults aren't set (#34825)

* fix(ux): don't throw error when company defaults aren't set; instead prompt account input.

* fix: translate label and title

(cherry picked from commit 51c4338661)

Co-authored-by: Devin Slauenwhite <devin.slauenwhite@gmail.com>
This commit is contained in:
mergify[bot]
2023-04-14 16:42:12 +05:30
committed by GitHub
parent 3738ea5794
commit 15f5e8d4ff
2 changed files with 36 additions and 28 deletions

View File

@@ -971,29 +971,47 @@ frappe.ui.form.on('Payment Entry', {
}, },
callback: function(r, rt) { callback: function(r, rt) {
if(r.message) { if(r.message) {
var write_off_row = $.map(frm.doc["deductions"] || [], function(t) { const write_off_row = $.map(frm.doc["deductions"] || [], function(t) {
return t.account==r.message[account] ? t : null; }); return t.account==r.message[account] ? t : null; });
var row = []; const difference_amount = flt(frm.doc.difference_amount,
var difference_amount = flt(frm.doc.difference_amount,
precision("difference_amount")); precision("difference_amount"));
if (!write_off_row.length && difference_amount) { const add_deductions = (details) => {
row = frm.add_child("deductions"); if (!write_off_row.length && difference_amount) {
row.account = r.message[account]; row = frm.add_child("deductions");
row.cost_center = r.message["cost_center"]; row.account = details[account];
} else { row.cost_center = details["cost_center"];
row = write_off_row[0]; } else {
} row = write_off_row[0];
}
if (row) { if (row) {
row.amount = flt(row.amount) + difference_amount; row.amount = flt(row.amount) + difference_amount;
} else { } else {
frappe.msgprint(__("No gain or loss in the exchange rate")) frappe.msgprint(__("No gain or loss in the exchange rate"))
} }
refresh_field("deductions");
};
refresh_field("deductions"); if (!r.message[account]) {
frappe.prompt({
label: __("Please Specify Account"),
fieldname: account,
fieldtype: "Link",
options: "Account",
get_query: () => ({
filters: {
company: frm.doc.company,
}
})
}, (values) => {
const details = Object.assign({}, r.message, values);
add_deductions(details);
}, __(frappe.unscrub(account)));
} else {
add_deductions(r.message);
}
frm.events.set_unallocated_amount(frm); frm.events.set_unallocated_amount(frm);
} }

View File

@@ -1594,17 +1594,7 @@ def get_account_details(account, date, cost_center=None):
@frappe.whitelist() @frappe.whitelist()
def get_company_defaults(company): def get_company_defaults(company):
fields = ["write_off_account", "exchange_gain_loss_account", "cost_center"] fields = ["write_off_account", "exchange_gain_loss_account", "cost_center"]
ret = frappe.get_cached_value("Company", company, fields, as_dict=1) return frappe.get_cached_value("Company", company, fields, as_dict=1)
for fieldname in fields:
if not ret[fieldname]:
frappe.throw(
_("Please set default {0} in Company {1}").format(
frappe.get_meta("Company").get_label(fieldname), company
)
)
return ret
def get_outstanding_on_journal_entry(name): def get_outstanding_on_journal_entry(name):