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
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js
index f8969b8..ed6d0a7 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.js
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js
@@ -970,29 +970,47 @@
},
callback: function(r, rt) {
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; });
- var row = [];
-
- var difference_amount = flt(frm.doc.difference_amount,
+ const difference_amount = flt(frm.doc.difference_amount,
precision("difference_amount"));
- if (!write_off_row.length && difference_amount) {
- row = frm.add_child("deductions");
- row.account = r.message[account];
- row.cost_center = r.message["cost_center"];
- } else {
- row = write_off_row[0];
- }
+ const add_deductions = (details) => {
+ if (!write_off_row.length && difference_amount) {
+ row = frm.add_child("deductions");
+ row.account = details[account];
+ row.cost_center = details["cost_center"];
+ } else {
+ row = write_off_row[0];
+ }
- if (row) {
- row.amount = flt(row.amount) + difference_amount;
- } else {
- frappe.msgprint(__("No gain or loss in the exchange rate"))
- }
+ if (row) {
+ row.amount = flt(row.amount) + difference_amount;
+ } else {
+ 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);
}
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index c34bddd..f8a2653 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -1594,17 +1594,7 @@
@frappe.whitelist()
def get_company_defaults(company):
fields = ["write_off_account", "exchange_gain_loss_account", "cost_center"]
- ret = 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
+ return frappe.get_cached_value("Company", company, fields, as_dict=1)
def get_outstanding_on_journal_entry(name):