From 25bd84dfccc54a6cde66d44c72d4ec262be78516 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 4 Mar 2015 15:06:56 +0530 Subject: [PATCH] Discount amount loss adjustment if no taxes or discount applied on net total --- erpnext/controllers/taxes_and_totals.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index dc3f9433be..9637f39f50 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -229,7 +229,7 @@ class calculate_taxes_and_totals(object): # adjust Discount Amount loss in last tax iteration if i == (len(self.doc.get("taxes")) - 1) and self.discount_amount_applied \ - and self.doc.apply_discount_on == "Grand Total": + and self.doc.discount_amount: self.adjust_discount_amount_loss(tax) def get_current_tax_amount(self, item, tax, item_tax_map): @@ -326,14 +326,28 @@ class calculate_taxes_and_totals(object): self.doc.precision("base_discount_amount")) total_for_discount_amount = self.get_total_for_discount_amount() + taxes = self.doc.get("taxes") + net_total = 0 if total_for_discount_amount: # calculate item amount after Discount Amount - for item in self.doc.get("items"): - distributed_amount = flt(self.doc.discount_amount) * item.net_amount / total_for_discount_amount + for i, item in enumerate(self.doc.get("items")): + distributed_amount = flt(self.doc.discount_amount) * \ + item.net_amount / total_for_discount_amount + item.net_amount = flt(item.net_amount - distributed_amount, item.precision("net_amount")) + net_total += item.net_amount + + # discount amount rounding loss adjustment if no taxes + if (not taxes or self.doc.apply_discount_on == "Net Total") \ + and i == len(self.doc.get("items")) - 1: + discount_amount_loss = flt(self.doc.total - net_total - self.doc.discount_amount, + self.doc.precision("net_total")) + item.net_amount = flt(item.net_amount + discount_amount_loss, + item.precision("net_amount")) + item.net_rate = flt(item.net_amount / item.qty, item.precision("net_rate")) - + self._set_in_company_currency(item, ["net_rate", "net_amount"]) self.discount_amount_applied = True