Rounding issue and divisional loss adjustment
diff --git a/controllers/accounts_controller.py b/controllers/accounts_controller.py
index 8d33327..e5b0b9d 100644
--- a/controllers/accounts_controller.py
+++ b/controllers/accounts_controller.py
@@ -223,20 +223,22 @@
_on_previous_row_error("1 - %d" % (tax.row_id,))
def calculate_taxes(self):
- for item in self.item_doclist:
+ # maintain actual tax rate based on idx
+ actual_tax_dict = dict([[tax.idx, tax.rate] for tax in self.tax_doclist
+ if tax.charge_type == "Actual"])
+
+ for n, item in enumerate(self.item_doclist):
item_tax_map = self._load_item_tax_rate(item.item_tax_rate)
for i, tax in enumerate(self.tax_doclist):
# tax_amount represents the amount of tax for the current step
current_tax_amount = self.get_current_tax_amount(item, tax, item_tax_map)
-
- # case when net total is 0 but there is an actual type charge
- # in this case add the actual amount to tax.tax_amount
- # and tax.grand_total_for_current_item for the first such iteration
- if tax.charge_type=="Actual" and \
- not (current_tax_amount or self.doc.net_total or tax.tax_amount):
- zero_net_total_adjustment = flt(tax.rate, self.precision("tax_amount", tax))
- current_tax_amount += zero_net_total_adjustment
+
+ # Adjust divisional loss to the last item
+ if tax.charge_type == "Actual":
+ actual_tax_dict[tax.idx] -= current_tax_amount
+ if n == len(self.item_doclist) - 1:
+ current_tax_amount += actual_tax_dict[tax.idx]
# store tax_amount for current item as it will be used for
# charge type = 'On Previous Row Amount'
@@ -248,7 +250,8 @@
if tax.category:
# if just for valuation, do not add the tax amount in total
# hence, setting it as 0 for further steps
- current_tax_amount = 0.0 if (tax.category == "Valuation") else current_tax_amount
+ current_tax_amount = 0.0 if (tax.category == "Valuation") \
+ else current_tax_amount
current_tax_amount *= -1.0 if (tax.add_deduct_tax == "Deduct") else 1.0
@@ -267,6 +270,11 @@
# in tax.total, accumulate grand total of each item
tax.total += tax.grand_total_for_current_item
+ # set precision in the last item iteration
+ if n == len(self.item_doclist) - 1:
+ tax.total = flt(tax.total, self.precision("total", tax))
+ tax.tax_amount = flt(tax.tax_amount, self.precision("tax_amount", tax))
+
def get_current_tax_amount(self, item, tax, item_tax_map):
tax_rate = self._get_tax_rate(tax, item_tax_map)
current_tax_amount = 0.0