2019-01-22 12:52:20 +00:00
|
|
|
from __future__ import unicode_literals
|
2020-05-26 12:32:21 +00:00
|
|
|
import frappe
|
2017-12-28 08:50:13 +00:00
|
|
|
from frappe.utils import flt
|
|
|
|
from erpnext.controllers.taxes_and_totals import get_itemised_tax
|
2020-05-26 12:32:21 +00:00
|
|
|
from six import iteritems
|
2017-12-28 08:50:13 +00:00
|
|
|
|
|
|
|
def update_itemised_tax_data(doc):
|
|
|
|
if not doc.taxes: return
|
|
|
|
|
|
|
|
itemised_tax = get_itemised_tax(doc.taxes)
|
|
|
|
|
|
|
|
for row in doc.items:
|
2018-01-01 10:46:16 +00:00
|
|
|
tax_rate = 0.0
|
2020-05-26 12:32:21 +00:00
|
|
|
item_tax_rate = frappe.parse_json(row.item_tax_rate)
|
|
|
|
|
|
|
|
# First check if tax rate is present
|
|
|
|
# If not then look up in item_wise_tax_detail
|
|
|
|
if item_tax_rate:
|
|
|
|
for account, rate in iteritems(item_tax_rate):
|
|
|
|
tax_rate += rate
|
|
|
|
elif itemised_tax.get(row.item_code):
|
2018-01-01 10:46:16 +00:00
|
|
|
tax_rate = sum([tax.get('tax_rate', 0) for d, tax in itemised_tax.get(row.item_code).items()])
|
2017-12-28 08:50:13 +00:00
|
|
|
|
|
|
|
row.tax_rate = flt(tax_rate, row.precision("tax_rate"))
|
|
|
|
row.tax_amount = flt((row.net_amount * tax_rate) / 100, row.precision("net_amount"))
|
|
|
|
row.total_amount = flt((row.net_amount + row.tax_amount), row.precision("total_amount"))
|