From f57f4af1d95a3cec186793f6b27462d469a511ae Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Thu, 24 Mar 2022 12:31:37 +0530 Subject: [PATCH] fix: Write off amount wrongly calculated in POS Invoice (cherry picked from commit ee4258e42c33899fae7b7add8a676274259a40e0) --- erpnext/controllers/taxes_and_totals.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 29da5f11ab..884deb302c 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -581,6 +581,7 @@ class calculate_taxes_and_totals(object): if self.doc.docstatus == 0: self.calculate_outstanding_amount() + self.calculate_write_off_amount() def is_internal_invoice(self): """ @@ -621,7 +622,6 @@ class calculate_taxes_and_totals(object): change_amount = 0 if self.doc.doctype == "Sales Invoice" and not self.doc.get('is_return'): - self.calculate_write_off_amount() self.calculate_change_amount() change_amount = self.doc.change_amount \ if self.doc.party_account_currency == self.doc.currency else self.doc.base_change_amount @@ -671,19 +671,20 @@ class calculate_taxes_and_totals(object): and self.doc.paid_amount > grand_total and not self.doc.is_return \ and any(d.type == "Cash" for d in self.doc.payments): - self.doc.change_amount = flt(self.doc.paid_amount - grand_total + - self.doc.write_off_amount, self.doc.precision("change_amount")) + self.doc.change_amount = flt(self.doc.paid_amount - grand_total, + self.doc.precision("change_amount")) - 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")) + self.doc.base_change_amount = flt(self.doc.base_paid_amount - base_grand_total, + self.doc.precision("base_change_amount")) def calculate_write_off_amount(self): - if flt(self.doc.change_amount) > 0: - self.doc.write_off_amount = flt(self.doc.grand_total - self.doc.paid_amount - + self.doc.change_amount, self.doc.precision("write_off_amount")) + if self.doc.write_off_outstanding_amount_automatically: + self.doc.write_off_amount = flt(self.doc.outstanding_amount, self.doc.precision("write_off_amount")) self.doc.base_write_off_amount = flt(self.doc.write_off_amount * self.doc.conversion_rate, self.doc.precision("base_write_off_amount")) + self.calculate_outstanding_amount() + def calculate_margin(self, item): rate_with_margin = 0.0 base_rate_with_margin = 0.0