fix: check if tds deducted based on Purchase Taxes and Charges (#45161)
(cherry picked from commit 37a5767be5)
This commit is contained in:
@@ -302,6 +302,10 @@ def get_tax_amount(party_type, parties, inv, tax_details, posting_date, pan_no=N
|
||||
tax_amount = 0
|
||||
|
||||
if party_type == "Supplier":
|
||||
# if tds account is changed.
|
||||
if not tax_deducted:
|
||||
tax_deducted = is_tax_deducted_on_the_basis_of_inv(vouchers)
|
||||
|
||||
ldc = get_lower_deduction_certificate(inv.company, posting_date, tax_details, pan_no)
|
||||
if tax_deducted:
|
||||
net_total = inv.tax_withholding_net_total
|
||||
@@ -336,6 +340,18 @@ def get_tax_amount(party_type, parties, inv, tax_details, posting_date, pan_no=N
|
||||
return tax_amount, tax_deducted, tax_deducted_on_advances, voucher_wise_amount
|
||||
|
||||
|
||||
def is_tax_deducted_on_the_basis_of_inv(vouchers):
|
||||
return frappe.db.exists(
|
||||
"Purchase Taxes and Charges",
|
||||
{
|
||||
"parent": ["in", vouchers],
|
||||
"is_tax_withholding_account": 1,
|
||||
"parenttype": "Purchase Invoice",
|
||||
"base_tax_amount_after_discount_amount": [">", 0],
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def get_invoice_vouchers(parties, tax_details, company, party_type="Supplier"):
|
||||
doctype = "Purchase Invoice" if party_type == "Supplier" else "Sales Invoice"
|
||||
field = (
|
||||
|
||||
@@ -61,6 +61,49 @@ class TestTaxWithholdingCategory(FrappeTestCase):
|
||||
for d in reversed(invoices):
|
||||
d.cancel()
|
||||
|
||||
def test_tds_with_account_changed(self):
|
||||
frappe.db.set_value(
|
||||
"Supplier", "Test TDS Supplier", "tax_withholding_category", "Multi Account TDS Category"
|
||||
)
|
||||
invoices = []
|
||||
|
||||
# create invoices for lower than single threshold tax rate
|
||||
for _ in range(2):
|
||||
pi = create_purchase_invoice(supplier="Test TDS Supplier")
|
||||
pi.submit()
|
||||
invoices.append(pi)
|
||||
|
||||
# create another invoice whose total when added to previously created invoice,
|
||||
# surpasses cumulative threshhold
|
||||
pi = create_purchase_invoice(supplier="Test TDS Supplier")
|
||||
pi.submit()
|
||||
|
||||
# assert equal tax deduction on total invoice amount until now
|
||||
self.assertEqual(pi.taxes_and_charges_deducted, 3000)
|
||||
self.assertEqual(pi.grand_total, 7000)
|
||||
invoices.append(pi)
|
||||
|
||||
# account changed
|
||||
|
||||
frappe.db.set_value(
|
||||
"Tax Withholding Account",
|
||||
{"parent": "Multi Account TDS Category"},
|
||||
"account",
|
||||
"_Test Account VAT - _TC",
|
||||
)
|
||||
|
||||
# TDS should be on invoice only even though account is changed
|
||||
pi = create_purchase_invoice(supplier="Test TDS Supplier", rate=5000)
|
||||
pi.submit()
|
||||
|
||||
# assert equal tax deduction on total invoice amount until now
|
||||
self.assertEqual(pi.taxes_and_charges_deducted, 500)
|
||||
invoices.append(pi)
|
||||
|
||||
# delete invoices to avoid clashing
|
||||
for d in reversed(invoices):
|
||||
d.cancel()
|
||||
|
||||
def test_single_threshold_tds(self):
|
||||
invoices = []
|
||||
frappe.db.set_value(
|
||||
@@ -1061,6 +1104,16 @@ def create_tax_withholding_category_records():
|
||||
consider_party_ledger_amount=1,
|
||||
)
|
||||
|
||||
create_tax_withholding_category(
|
||||
category_name="Multi Account TDS Category",
|
||||
rate=10,
|
||||
from_date=from_date,
|
||||
to_date=to_date,
|
||||
account="TDS - _TC",
|
||||
single_threshold=0,
|
||||
cumulative_threshold=30000,
|
||||
)
|
||||
|
||||
|
||||
def create_tax_withholding_category(
|
||||
category_name,
|
||||
|
||||
Reference in New Issue
Block a user