Skip to content

Commit 06376cd

Browse files
committed
fix: implement item-wise tax detail building in CustomItemGSTDetails
1 parent d64737e commit 06376cd

2 files changed

Lines changed: 21 additions & 78 deletions

File tree

india_compliance/gst_india/overrides/transaction.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,7 @@ def get(self, docs, doctype, company):
11411141
if not doc.get("items") or not doc.get("taxes"):
11421142
continue
11431143

1144+
self.build_item_wise_tax_detail_from_data()
11441145
self.get_item_name_wise_tax_details()
11451146

11461147
for item in doc.get("items"):
@@ -1400,6 +1401,10 @@ def set_temp_item_wise_tax_detail_object(self):
14001401
# for custom tax controller
14011402
pass
14021403

1404+
def build_item_wise_tax_detail_from_data(self):
1405+
# for custom tax controller
1406+
pass
1407+
14031408
@staticmethod
14041409
def tax_amount_field():
14051410
return "base_tax_amount_after_discount_amount"

india_compliance/gst_india/utils/taxes_controller.py

Lines changed: 16 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
get_round_off_applicable_accounts as fetch_round_off_accounts,
88
)
99

10-
from india_compliance.gst_india.constants import GST_TAX_TYPES
1110
from india_compliance.gst_india.overrides.transaction import (
1211
ItemGSTDetails,
1312
ItemGSTTreatment,
@@ -59,89 +58,28 @@ def set_temp_item_wise_tax_detail_object(self):
5958
)
6059
)
6160

62-
def get_item_name_wise_tax_details(self):
61+
def build_item_wise_tax_detail_from_data(self):
6362
"""
64-
Item Tax Details complied
65-
Example:
66-
{
67-
"Item Code 1": {
68-
"count": 2,
69-
"cgst_rate": 9,
70-
"cgst_amount": 18,
71-
"sgst_rate": 9,
72-
"sgst_amount": 18,
73-
...
74-
},
75-
...
76-
}
77-
78-
Possible Exceptions Handled:
79-
- There could be more than one row for same account
80-
- Item count added to handle rounding errors
63+
Build item_wise_tax_details structure from JSON for patch/get operations.
64+
This mimics the child table structure expected by base class get_item_name_wise_tax_details()
8165
"""
82-
83-
tax_details = frappe._dict()
84-
85-
for row in self.doc.get("items"):
86-
key = row.name
87-
88-
if key not in tax_details:
89-
tax_details[key] = self.item_defaults.copy()
90-
91-
tax_details[key]["count"] += 1
66+
self.doc.item_wise_tax_details = []
9267

9368
for row in self.doc.taxes:
94-
if not self.is_gst_tax_row(row):
69+
if not row.gst_tax_type:
9570
continue
9671

97-
tax = row.gst_tax_type
98-
tax_rate_field = f"{tax}_rate"
99-
tax_amount_field = f"{tax}_amount"
100-
101-
old = json.loads(row.get(self.tax_details_field(), "{}"))
102-
103-
tax_difference = row.tax_amount
104-
last_item_with_tax = None
105-
106-
# update item taxes
107-
for item_name in old:
108-
if item_name not in tax_details:
109-
# Do not compute if Item is not present in Item table
110-
# There can be difference in Item Table and Item Wise Tax Details
111-
continue
112-
113-
item_taxes = tax_details[item_name]
114-
tax_rate = old[item_name].get("tax_rate")
115-
tax_amount = old[item_name].get("tax_amount")
116-
117-
tax_difference -= tax_amount
118-
119-
# cases when charge type == "Actual"
120-
if tax_amount and not tax_rate:
121-
continue
122-
123-
item_taxes[tax_rate_field] = tax_rate
124-
item_taxes[tax_amount_field] += tax_amount
125-
126-
# update tax difference only for taxable items
127-
if tax_amount:
128-
last_item_with_tax = item_taxes
129-
130-
# Floating point errors
131-
tax_difference = flt(tax_difference, 5)
132-
133-
# Handle rounding errors
134-
if tax_difference and last_item_with_tax:
135-
last_item_with_tax[tax_amount_field] += tax_difference
136-
137-
self.item_tax_details = tax_details
138-
139-
def is_gst_tax_row(self, row):
140-
return (
141-
row.gst_tax_type
142-
and row.gst_tax_type in GST_TAX_TYPES
143-
and row.get(self.tax_details_field())
144-
)
72+
item_wise_tax_rates = self.get_tax_details(row)
73+
for item_name, rate in item_wise_tax_rates.items():
74+
self.doc.item_wise_tax_details.append(
75+
frappe._dict(
76+
{
77+
"item_row": item_name,
78+
"tax_row": row.name,
79+
"rate": rate,
80+
}
81+
)
82+
)
14583

14684

14785
def update_gst_details(doc, method=None):

0 commit comments

Comments
 (0)