Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use item gst details for tax amounts in transaction data #2487

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 16 additions & 66 deletions india_compliance/gst_india/utils/transaction_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
E_INVOICE_MASTER_CODES_URL,
GST_TAX_RATES,
GST_TAX_TYPES,
SUBCONTRACTING_DOCTYPES,
)
from india_compliance.gst_india.constants.e_waybill import (
TRANSPORT_MODES,
Expand Down Expand Up @@ -322,7 +321,13 @@ def group_same_items(self):
item = grouped_items.setdefault(
row.item_code,
frappe._dict(
{**row.as_dict(), "idx": 0, "qty": 0.00, "taxable_value": 0.00}
{
**row.as_dict(),
"idx": 0,
"qty": 0.00,
"taxable_value": 0.00,
**{f"{tax}_amount": 0.00 for tax in GST_TAX_TYPES},
}
),
)

Expand All @@ -332,6 +337,8 @@ def group_same_items(self):

item.qty += row.qty
item.taxable_value += row.taxable_value
for tax in GST_TAX_TYPES:
item[f"{tax}_amount"] += row.get(f"{tax}_amount", 0)

return list(grouped_items.values())

Expand All @@ -346,11 +353,13 @@ def update_item_details(self, item_details, item):
pass

def update_item_tax_details(self, item_details, item):
if self.doc.doctype in SUBCONTRACTING_DOCTYPES:
self.update_item_tax_details_using_item_gst_details(item_details, item)

else:
self.update_item_tax_details_using_taxes(item_details, item)
for tax in GST_TAX_TYPES:
item_details.update(
{
f"{tax}_amount": abs(self.rounded(item.get(f"{tax}_amount"))),
f"{tax}_rate": abs(self.rounded(item.get(f"{tax}_rate"))),
}
)

tax_rate = sum(
self.rounded(item_details.get(f"{tax}_rate", 0), 3)
Expand All @@ -374,65 +383,6 @@ def update_item_tax_details(self, item_details, item):
}
)

def update_item_tax_details_using_taxes(self, item_details, item):
for tax in GST_TAX_TYPES:
item_details.update({f"{tax}_amount": 0, f"{tax}_rate": 0})

for row in self.doc.taxes:
if (
not row.tax_amount
or self.is_purchase_rcm
or row.gst_tax_type not in GST_TAX_TYPES
):
continue

tax = row.gst_tax_type
tax_rate = self.rounded(
frappe.parse_json(row.item_wise_tax_detail).get(
item.item_code or item.item_name
)[0],
3,
)

# considers senarios where same item is there multiple times
tax_amount = self.get_progressive_item_tax_amount(
(
tax_rate * item.qty
if row.charge_type == "On Item Quantity"
else tax_rate * item.taxable_value / 100
),
tax,
)

item_details.update(
{
f"{tax}_rate": tax_rate,
f"{tax}_amount": tax_amount,
}
)

def update_item_tax_details_using_item_gst_details(self, item_details, item):
for tax in GST_TAX_TYPES:
item_details.update(
{
f"{tax}_amount": item.get(f"{tax}_amount"),
f"{tax}_rate": item.get(f"{tax}_rate"),
}
)

def get_progressive_item_tax_amount(self, amount, tax_type):
Copy link
Member

@vorasmit vorasmit Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be still needed. Can be implemented at Item GST Details.

"""
Helper function to calculate progressive tax amount for an item to remove
rounding errors.
"""
error_field = f"{tax_type}_rounding_error"
error_amount = self.rounding_errors[error_field]

response = self.rounded(amount + error_amount)
self.rounding_errors[error_field] = amount + error_amount - response

return abs(response)

def get_address_details(self, address_name, validate_gstin=False):
address = frappe.get_cached_value(
"Address",
Expand Down