Skip to content

Commit

Permalink
fix: TDS/TCS amount included in other charges. (#947)
Browse files Browse the repository at this point in the history
  • Loading branch information
ljain112 authored Aug 10, 2023
1 parent 70a14d8 commit 763635b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 61 deletions.
41 changes: 41 additions & 0 deletions india_compliance/gst_india/overrides/test_transaction_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,47 @@ def test_set_transaction_details(self):
},
)

def test_set_transaction_details_with_other_charges(self):
doc = create_sales_invoice(do_not_submit=True)
_append_taxes(doc, ("CGST", "SGST"))

tds = {
"charge_type": "On Previous Row Total",
"row_id": "2",
"account_head": "TDS Payable - _TIRC",
"description": "TDS ON SALES",
"rate": "1",
"cost_center": "Main - _TIRC",
}

doc.append("taxes", tds)
doc.save()

gst_transaction_data = GSTTransactionData(doc)
gst_transaction_data.set_transaction_details()

self.assertDictEqual(
gst_transaction_data.transaction_details,
{
"company_name": "_Test Indian Registered Company",
"party_name": "_Test Registered Customer",
"date": format_date(frappe.utils.today(), "dd/mm/yyyy"),
"total": 100.0,
"rounding_adjustment": -0.18,
"grand_total": 119.0,
"grand_total_in_foreign_currency": "",
"discount_amount": 0,
"company_gstin": "24AAQCA8719H1ZC",
"name": doc.name,
"other_charges": 1.18,
"total_cgst_amount": 9.0,
"total_sgst_amount": 9.0,
"total_igst_amount": 0,
"total_cess_amount": 0,
"total_cess_non_advol_amount": 0,
},
)

def test_set_transporter_details(self):
"""Dict Assertion for transporter details"""
doc = create_sales_invoice(vehicle_no="GJ07DL9009", do_not_submit=True)
Expand Down
78 changes: 17 additions & 61 deletions india_compliance/gst_india/utils/transaction_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
get_validated_country_code,
validate_pincode,
)
from india_compliance.income_tax_india.overrides.tax_withholding_category import (
get_tax_withholding_accounts,
)

REGEX_MAP = {
1: re.compile(r"[^A-Za-z0-9]"),
Expand Down Expand Up @@ -58,7 +55,16 @@ def __init__(self, doc):
}

def set_transaction_details(self):
tds_amount = self.get_tds_amount()
rounding_adjustment = self.rounded(self.doc.base_rounding_adjustment)
if self.doc.is_return:
rounding_adjustment = -rounding_adjustment

grand_total_fieldname = (
"base_grand_total"
if self.doc.disable_rounded_total
else "base_rounded_total"
)

self.transaction_details.update(
{
"company_name": self.sanitize_value(self.doc.company),
Expand All @@ -72,9 +78,13 @@ def set_transaction_details(self):
"total": abs(
self.rounded(sum(row.taxable_value for row in self.doc.items))
),
"rounding_adjustment": self.get_adjusted_rounding(tds_amount),
"grand_total": self.get_adjusted_grand_total(tds_amount),
"grand_total_in_foreign_currency": self.get_adjusted_total_in_foreign_currency(),
"rounding_adjustment": rounding_adjustment,
"grand_total": abs(self.rounded(self.doc.get(grand_total_fieldname))),
"grand_total_in_foreign_currency": (
abs(self.rounded(self.doc.grand_total))
if self.doc.currency != "INR"
else ""
),
"discount_amount": (
abs(self.rounded(self.doc.base_discount_amount))
if self.doc.get("is_cash_or_non_trade_discount")
Expand All @@ -88,60 +98,6 @@ def set_transaction_details(self):
self.update_transaction_details()
self.update_transaction_tax_details()

def get_tds_amount(self, currency="INR"):
tds_accounts = get_tax_withholding_accounts(self.doc.company)
amount_field = (
"base_tax_amount_after_discount_amount"
if currency == "INR"
else "tax_amount_after_discount_amount"
)
tds_amount = 0

if not tds_accounts:
return tds_amount

for row in self.doc.taxes:
if row.account_head in tds_accounts:
tds_amount += row.get(amount_field)

return tds_amount

def get_adjusted_rounding(self, tds_amount):
"""Adjust rounding for TDS Roundoff and Returns"""

if self.doc.disable_rounded_total:
return 0.0

tds_rounding_adjustment = self.rounded(tds_amount, 0) - tds_amount
rounding_adjustment = self.rounded(
self.doc.base_rounding_adjustment - tds_rounding_adjustment
)

if self.doc.is_return:
rounding_adjustment = -rounding_adjustment

return rounding_adjustment

def get_adjusted_grand_total(self, tds_amount):
grand_total_fieldname = "base_grand_total"

if not self.doc.disable_rounded_total:
grand_total_fieldname = "base_rounded_total"
tds_amount = self.rounded(tds_amount, 0)

return abs(self.rounded(self.doc.get(grand_total_fieldname) - tds_amount))

def get_adjusted_total_in_foreign_currency(self):
grand_total_in_foreign_currency = ""
if self.doc.currency != "INR":
grand_total_in_foreign_currency = abs(
self.rounded(
self.doc.grand_total - self.get_tds_amount(self.doc.currency)
)
)

return grand_total_in_foreign_currency

def update_transaction_details(self):
# to be overrridden
pass
Expand Down

0 comments on commit 763635b

Please sign in to comment.