From ea7533fa751468f02cdc3dcefae5727c76c5dc11 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Mon, 11 Jun 2018 13:31:33 +0530 Subject: [PATCH] [tax-breakup] store itemized tax by item_name when can --- erpnext/controllers/taxes_and_totals.py | 19 +++++++++++-------- .../public/js/controllers/taxes_and_totals.js | 16 +++++++++++----- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index b44f597ed7..41ba61b231 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -600,16 +600,19 @@ def get_itemised_tax(taxes): for item_code, tax_data in item_tax_map.items(): itemised_tax.setdefault(item_code, frappe._dict()) + tax_rate = 0.0 + tax_amount = 0.0 + if isinstance(tax_data, list): - itemised_tax[item_code][tax.description] = frappe._dict(dict( - tax_rate=flt(tax_data[0]), - tax_amount=flt(tax_data[1]) - )) + 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_amount=0.0 - )) + tax_rate = flt(tax_data) + + itemised_tax[item_code][tax.description] = frappe._dict(dict( + tax_rate = tax_rate, + tax_amount = tax_amount + )) return itemised_tax diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index f00b84f368..865a5ffd77 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -338,12 +338,18 @@ erpnext.taxes_and_totals = erpnext.payments.extend({ set_item_wise_tax: function(item, tax, tax_rate, current_tax_amount) { // store tax breakup for each item - var key = item.item_code || item.item_name; - var item_wise_tax_amount = current_tax_amount * this.frm.doc.conversion_rate; - if (tax.item_wise_tax_detail && tax.item_wise_tax_detail[key]) - item_wise_tax_amount += tax.item_wise_tax_detail[key][1]; + let tax_detail = tax.item_wise_tax_detail; - tax.item_wise_tax_detail[key] = [tax_rate, flt(item_wise_tax_amount, precision("base_tax_amount", tax))]; + let key = item.item_code; + if(item.item_name && !Object.keys(tax_detail).includes(item.item_name)) { + key = item.item_name; + } + + let item_wise_tax_amount = current_tax_amount * this.frm.doc.conversion_rate; + if (tax_detail && tax_detail[key]) + item_wise_tax_amount += tax_detail[key][1]; + + tax_detail[key] = [tax_rate, flt(item_wise_tax_amount, precision("base_tax_amount", tax))]; }, round_off_totals: function(tax) {