Merge pull request #12773 from rohitwaghchaure/change_amount_issue
[Fix] Incorrect change amount if enabled rounded total
diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py
index 4547ac1..0e35cb8 100644
--- a/erpnext/controllers/taxes_and_totals.py
+++ b/erpnext/controllers/taxes_and_totals.py
@@ -491,11 +491,13 @@
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 4847dae..c1b020b 100644
--- a/erpnext/public/js/controllers/taxes_and_totals.js
+++ b/erpnext/public/js/controllers/taxes_and_totals.js
@@ -653,11 +653,14 @@
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"));
}
}