From 8d8cba7faa9520be58bb3a81ffb89e627c583f68 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 3 Apr 2017 17:26:22 +0530 Subject: [PATCH] Validate total advance against grand total considering write off amount --- erpnext/controllers/taxes_and_totals.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index bec57f4efbd..40748df6308 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -404,11 +404,14 @@ class calculate_taxes_and_totals(object): self.doc.total_advance = flt(total_allocated_amount, self.doc.precision("total_advance")) if self.doc.party_account_currency == self.doc.currency: - invoice_total = self.doc.grand_total - else: - invoice_total = flt(self.doc.grand_total * self.doc.conversion_rate, + invoice_total = flt(self.doc.grand_total - self.write_off_amount, self.doc.precision("grand_total")) - + else: + base_write_off_amount = flt(self.doc.write_off_amount * self.doc.conversion_rate, + self.doc.precision("base_write_off_amount")) + invoice_total = flt(self.doc.grand_total * self.doc.conversion_rate, + self.doc.precision("grand_total")) - base_write_off_amount + if invoice_total > 0 and self.doc.total_advance > invoice_total: frappe.throw(_("Advance amount cannot be greater than {0} {1}") .format(self.doc.party_account_currency, invoice_total))