Tax breakup for actual amount and fixes in itemised purchase register (#10515)

* Tax breakup for actual amount and fixes in itemised pur register

* Rounding of itemised tax breakup amount
This commit is contained in:
Nabin Hait
2017-08-24 16:22:28 +05:30
committed by Makarand Bauskar
parent 6b651d734e
commit caab582943
4 changed files with 53 additions and 19 deletions

View File

@@ -270,7 +270,7 @@ class calculate_taxes_and_totals(object):
if tax.item_wise_tax_detail.get(key):
item_wise_tax_amount += tax.item_wise_tax_detail[key][1]
tax.item_wise_tax_detail[key] = [tax_rate,flt(item_wise_tax_amount, tax.precision("base_tax_amount"))]
tax.item_wise_tax_detail[key] = [tax_rate,flt(item_wise_tax_amount)]
def round_off_totals(self, tax):
tax.tax_amount = flt(tax.tax_amount, tax.precision("tax_amount"))
@@ -521,12 +521,20 @@ def get_itemised_tax_breakup_html(doc):
frappe.flags.company = doc.company
# get headers
tax_accounts = list(set([d.description for d in doc.taxes]))
tax_accounts = []
for tax in doc.taxes:
if getattr(tax, "category", None) and tax.category=="Valuation":
continue
if tax.description not in tax_accounts:
tax_accounts.append(tax.description)
headers = get_itemised_tax_breakup_header(doc.doctype + " Item", tax_accounts)
# get tax breakup data
itemised_tax, itemised_taxable_amount = get_itemised_tax_breakup_data(doc)
get_rounded_tax_amount(itemised_tax, doc.precision("tax_amount", "taxes"))
frappe.flags.company = None
return frappe.render_template(
@@ -554,6 +562,9 @@ def get_itemised_tax_breakup_data(doc):
def get_itemised_tax(taxes):
itemised_tax = {}
for tax in taxes:
if getattr(tax, "category", None) and tax.category=="Valuation":
continue
tax_amount_precision = tax.precision("tax_amount")
tax_rate_precision = tax.precision("rate")
@@ -562,16 +573,16 @@ def get_itemised_tax(taxes):
for item_code, tax_data in item_tax_map.items():
itemised_tax.setdefault(item_code, frappe._dict())
if isinstance(tax_data, list) and tax_data[0]:
if isinstance(tax_data, list):
precision = tax_amount_precision if tax.charge_type == "Actual" else tax_rate_precision
itemised_tax[item_code][tax.description] = frappe._dict(dict(
tax_rate=flt(tax_data[0], precision),
tax_amount=flt(tax_data[1], tax_amount_precision)
tax_rate=flt(tax_data[0]),
tax_amount=flt(tax_data[1])
))
else:
itemised_tax[item_code][tax.description] = frappe._dict(dict(
tax_rate=flt(tax_data, tax_rate_precision),
tax_rate=flt(tax_data),
tax_amount=0.0
))
@@ -584,4 +595,10 @@ def get_itemised_taxable_amount(items):
itemised_taxable_amount.setdefault(item_code, 0)
itemised_taxable_amount[item_code] += item.net_amount
return itemised_taxable_amount
return itemised_taxable_amount
def get_rounded_tax_amount(itemised_tax, precision):
# Rounding based on tax_amount precision
for taxes in itemised_tax.values():
for tax_account in taxes:
taxes[tax_account]["tax_amount"] = flt(taxes[tax_account]["tax_amount"], precision)