From 3c9155e406a5132abaf2d1e25c2d4e0e0fcd4ece Mon Sep 17 00:00:00 2001 From: Saif Date: Thu, 18 Oct 2018 17:27:56 +0500 Subject: [PATCH] [Minor Fix] Force toggle display Net Total field when default taxes are fetched (#15532) * Minor fix for the problem that Net Total, Net Rate, Net Amount field would not be shown when default taxes were fetched * Prevent net_rate from becoming NaN * -Fixed problem that party_account_currency was not set in mapped document -Fixed problem that discount amount was not recalculated (in mapped document) -Fixed problem that set_dynamic_fields would work only on certain condition that led to showing Total (Company Currency) field even when using company currency --- .../doctype/purchase_invoice/purchase_invoice.py | 1 + .../doctype/sales_invoice/sales_invoice.py | 1 + erpnext/controllers/taxes_and_totals.py | 1 + erpnext/public/js/controllers/taxes_and_totals.js | 4 ++-- erpnext/public/js/controllers/transaction.js | 15 +++++---------- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 7219d875ad4..8e55514194e 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -123,6 +123,7 @@ class PurchaseInvoice(BuyingController): def set_missing_values(self, for_validate=False): if not self.credit_to: self.credit_to = get_party_account("Supplier", self.supplier, self.company) + self.party_account_currency = frappe.db.get_value("Account", self.credit_to, "account_currency", cache=True) if not self.due_date: self.due_date = get_due_date(self.posting_date, "Supplier", self.supplier, self.company, self.bill_date) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index d730e8859f2..7f755dd92bd 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -310,6 +310,7 @@ class SalesInvoice(SellingController): if not self.debit_to: self.debit_to = get_party_account("Customer", self.customer, self.company) + self.party_account_currency = frappe.db.get_value("Account", self.debit_to, "account_currency", cache=True) if not self.due_date and self.customer: self.due_date = get_due_date(self.posting_date, "Customer", self.customer, self.company) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index bf1c13954c1..6985c80bc1d 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -70,6 +70,7 @@ class calculate_taxes_and_totals(object): if item.rate_with_margin > 0 else item.rate item.net_rate = item.rate + item.discount_amount = item.price_list_rate - item.rate item.amount = flt(item.rate * item.qty, item.precision("amount")) item.net_amount = item.amount diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index ecf1d955bad..21e02b7c80b 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -161,7 +161,7 @@ erpnext.taxes_and_totals = erpnext.payments.extend({ if(cumulated_tax_fraction && !me.discount_amount_applied) { item.net_amount = flt(item.amount / (1 + cumulated_tax_fraction)); - item.net_rate = flt(item.net_amount / item.qty, precision("net_rate", item)); + item.net_rate = item.qty ? flt(item.net_amount / item.qty, precision("net_rate", item)) : 0; me.set_in_company_currency(item, ["net_rate", "net_amount"]); } @@ -521,7 +521,7 @@ erpnext.taxes_and_totals = erpnext.payments.extend({ item.net_amount = flt(item.net_amount + discount_amount_loss, precision("net_amount", item)); } - item.net_rate = flt(item.net_amount / item.qty, precision("net_rate", item)); + item.net_rate = item.qty ? flt(item.net_amount / item.qty, precision("net_rate", item)) : 0; me.set_in_company_currency(item, ["net_rate", "net_amount"]); }); diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index a27161f0127..3e27d5638d0 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -286,6 +286,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ me.frm.set_value("taxes", r.message.taxes); } }, + () => me.set_dynamic_labels(), () => me.calculate_taxes_and_totals() ]); } @@ -845,16 +846,10 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ this.frm.toggle_reqd("plc_conversion_rate", !!(this.frm.doc.price_list_name && this.frm.doc.price_list_currency)); - if(this.frm.doc_currency!==this.frm.doc.currency - || this.frm.doc_currency!==this.frm.doc.price_list_currency) { - // reset names only when the currency is different - - var company_currency = this.get_company_currency(); - this.change_form_labels(company_currency); - this.change_grid_labels(company_currency); - this.frm.refresh_fields(); - this.frm.doc_currency = this.frm.doc.currency; - } + var company_currency = this.get_company_currency(); + this.change_form_labels(company_currency); + this.change_grid_labels(company_currency); + this.frm.refresh_fields(); }, change_form_labels: function(company_currency) {