From e8d22bb999fdc399af13d5774c5c73a3a6be9ff4 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Mon, 5 Feb 2018 18:13:29 +0530 Subject: [PATCH] [Fix] Incorrect change amount if enabled rounded total --- erpnext/controllers/taxes_and_totals.py | 6 ++++-- erpnext/public/js/controllers/taxes_and_totals.js | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 4547ac1113..0e35cb89e6 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -491,11 +491,13 @@ class calculate_taxes_and_totals(object): if self.doc.doctype == "Sales Invoice" \ and self.doc.paid_amount > self.doc.grand_total and not self.doc.is_return \ and any([d.type == "Cash" for d in self.doc.payments]): + grand_total = self.doc.rounded_total or self.doc.grand_total + base_grand_total = self.doc.base_rounded_total or self.doc.base_grand_total - self.doc.change_amount = flt(self.doc.paid_amount - self.doc.grand_total + + self.doc.change_amount = flt(self.doc.paid_amount - grand_total + self.doc.write_off_amount, self.doc.precision("change_amount")) - self.doc.base_change_amount = flt(self.doc.base_paid_amount - self.doc.base_grand_total + + self.doc.base_change_amount = flt(self.doc.base_paid_amount - base_grand_total + self.doc.base_write_off_amount, self.doc.precision("base_change_amount")) def calculate_write_off_amount(self): diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index 4847dae555..c1b020bbe5 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -653,11 +653,14 @@ erpnext.taxes_and_totals = erpnext.payments.extend({ var payment_types = $.map(this.frm.doc.payments, function(d) { return d.type; }); if (in_list(payment_types, 'Cash')) { - this.frm.doc.change_amount = flt(this.frm.doc.paid_amount - this.frm.doc.grand_total + + var grand_total = this.frm.doc.rounded_total || this.frm.doc.grand_total; + var base_grand_total = this.frm.doc.base_rounded_total || this.frm.doc.base_grand_total; + + this.frm.doc.change_amount = flt(this.frm.doc.paid_amount - grand_total + this.frm.doc.write_off_amount, precision("change_amount")); this.frm.doc.base_change_amount = flt(this.frm.doc.base_paid_amount - - this.frm.doc.base_grand_total + this.frm.doc.base_write_off_amount, + base_grand_total + this.frm.doc.base_write_off_amount, precision("base_change_amount")); } }