|
7 | 7 | get_round_off_applicable_accounts as fetch_round_off_accounts, |
8 | 8 | ) |
9 | 9 |
|
10 | | -from india_compliance.gst_india.constants import GST_TAX_TYPES |
11 | 10 | from india_compliance.gst_india.overrides.transaction import ( |
12 | 11 | ItemGSTDetails, |
13 | 12 | ItemGSTTreatment, |
@@ -59,89 +58,28 @@ def set_temp_item_wise_tax_detail_object(self): |
59 | 58 | ) |
60 | 59 | ) |
61 | 60 |
|
62 | | - def get_item_name_wise_tax_details(self): |
| 61 | + def build_item_wise_tax_detail_from_data(self): |
63 | 62 | """ |
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() |
81 | 65 | """ |
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 = [] |
92 | 67 |
|
93 | 68 | for row in self.doc.taxes: |
94 | | - if not self.is_gst_tax_row(row): |
| 69 | + if not row.gst_tax_type: |
95 | 70 | continue |
96 | 71 |
|
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 | + ) |
145 | 83 |
|
146 | 84 |
|
147 | 85 | def update_gst_details(doc, method=None): |
|
0 commit comments