mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-27 00:44:45 +00:00
refactor!: store item wise tax details as a more flexible dict
This commit is contained in:
@@ -6,7 +6,7 @@ from frappe import _
|
||||
from frappe.utils import cstr, flt
|
||||
from frappe.utils.file_manager import remove_file
|
||||
|
||||
from erpnext.controllers.taxes_and_totals import get_itemised_tax
|
||||
from erpnext.controllers.taxes_and_totals import ItemWiseTaxDetail, get_itemised_tax
|
||||
from erpnext.regional.italy import state_codes
|
||||
|
||||
|
||||
@@ -214,16 +214,16 @@ def get_invoice_summary(items, taxes):
|
||||
|
||||
else:
|
||||
item_wise_tax_detail = json.loads(tax.item_wise_tax_detail)
|
||||
for rate_item in [
|
||||
tax_item for tax_item in item_wise_tax_detail.items() if tax_item[1][0] == tax.rate
|
||||
]:
|
||||
# TODO: with net_amount stored inside item_wise_tax_detail, this entire block seems obsolete and redundant
|
||||
for _item_code, tax_data in item_wise_tax_detail.items():
|
||||
tax_data = ItemWiseTaxDetail(**tax_data)
|
||||
if tax_data.tax_rate != tax.rate:
|
||||
continue
|
||||
key = cstr(tax.rate)
|
||||
if not summary_data.get(key):
|
||||
summary_data.setdefault(key, {"tax_amount": 0.0, "taxable_amount": 0.0})
|
||||
summary_data[key]["tax_amount"] += rate_item[1][1]
|
||||
summary_data[key]["taxable_amount"] += sum(
|
||||
[item.net_amount for item in items if item.item_code == rate_item[0]]
|
||||
)
|
||||
summary_data[key]["tax_amount"] += tax_data.tax_amount
|
||||
summary_data[key]["taxable_amount"] += tax_data.net_amount
|
||||
|
||||
for item in items:
|
||||
key = cstr(tax.rate)
|
||||
|
||||
@@ -8,6 +8,8 @@ import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import formatdate, get_link_to_form
|
||||
|
||||
from erpnext.controllers.taxes_and_totals import ItemWiseTaxDetail
|
||||
|
||||
|
||||
def execute(filters=None):
|
||||
return VATAuditReport(filters).run()
|
||||
@@ -125,12 +127,13 @@ class VATAuditReport:
|
||||
item_wise_tax_detail = json.loads(item_wise_tax_detail)
|
||||
else:
|
||||
continue
|
||||
for item_code, taxes in item_wise_tax_detail.items():
|
||||
for item_code, tax_data in item_wise_tax_detail.items():
|
||||
tax_data = ItemWiseTaxDetail(**tax_data)
|
||||
is_zero_rated = self.invoice_items.get(parent).get(item_code).get("is_zero_rated")
|
||||
# to skip items with non-zero tax rate in multiple rows
|
||||
if taxes[0] == 0 and not is_zero_rated:
|
||||
if tax_data.tax_rate == 0 and not is_zero_rated:
|
||||
continue
|
||||
tax_rate = self.get_item_amount_map(parent, item_code, taxes)
|
||||
tax_rate = self.get_item_amount_map(parent, item_code, tax_data)
|
||||
|
||||
if tax_rate is not None:
|
||||
rate_based_dict = self.items_based_on_tax_rate.setdefault(parent, {}).setdefault(
|
||||
@@ -141,10 +144,12 @@ class VATAuditReport:
|
||||
except ValueError:
|
||||
continue
|
||||
|
||||
def get_item_amount_map(self, parent, item_code, taxes):
|
||||
# TODO: now that tax_data holds net_amount, this method seems almost obsolete and can be removactored,
|
||||
# gross_amount can be calculated on the file as a list comprehension
|
||||
def get_item_amount_map(self, parent, item_code, tax_data):
|
||||
net_amount = self.invoice_items.get(parent).get(item_code).get("net_amount")
|
||||
tax_rate = taxes[0]
|
||||
tax_amount = taxes[1]
|
||||
tax_rate = tax_data.tax_rate
|
||||
tax_amount = tax_data.tax_amount
|
||||
gross_amount = net_amount + tax_amount
|
||||
|
||||
self.item_tax_rate.setdefault(parent, {}).setdefault(
|
||||
|
||||
Reference in New Issue
Block a user