diff --git a/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py b/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py index 1536a237de..0cb872c4b8 100644 --- a/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py +++ b/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py @@ -240,14 +240,15 @@ def get_deducted_tax(taxable_vouchers, fiscal_year, tax_details): def get_tds_amount(ldc, parties, inv, tax_details, fiscal_year_details, tax_deducted, vouchers): tds_amount = 0 invoice_filters = { - 'name': ('in', vouchers), - 'docstatus': 1 + 'name': ('in', vouchers), + 'docstatus': 1, + 'apply_tds': 1 } field = 'sum(net_total)' - if not cint(tax_details.consider_party_ledger_amount): - invoice_filters.update({'apply_tds': 1}) + if cint(tax_details.consider_party_ledger_amount): + invoice_filters.pop('apply_tds', None) field = 'sum(grand_total)' supp_credit_amt = frappe.db.get_value('Purchase Invoice', invoice_filters, field) or 0.0 diff --git a/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py b/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py index 1c687e5cb1..0f921db678 100644 --- a/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py +++ b/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py @@ -145,6 +145,36 @@ class TestTaxWithholdingCategory(unittest.TestCase): for d in invoices: d.cancel() + def test_tds_calculation_on_net_total(self): + frappe.db.set_value("Supplier", "Test TDS Supplier4", "tax_withholding_category", "Cumulative Threshold TDS") + invoices = [] + + pi = create_purchase_invoice(supplier = "Test TDS Supplier4", rate = 20000, do_not_save=True) + pi.append('taxes', { + "category": "Total", + "charge_type": "Actual", + "account_head": '_Test Account VAT - _TC', + "cost_center": 'Main - _TC', + "tax_amount": 1000, + "description": "Test", + "add_deduct_tax": "Add" + + }) + pi.save() + pi.submit() + invoices.append(pi) + + # Second Invoice will apply TDS checked + pi1 = create_purchase_invoice(supplier = "Test TDS Supplier4", rate = 20000) + pi1.submit() + invoices.append(pi1) + + self.assertEqual(pi1.taxes[0].tax_amount, 4000) + + #delete invoices to avoid clashing + for d in invoices: + d.cancel() + def cancel_invoices(): purchase_invoices = frappe.get_all("Purchase Invoice", { 'supplier': ['in', ['Test TDS Supplier', 'Test TDS Supplier1', 'Test TDS Supplier2']], @@ -220,7 +250,7 @@ def create_sales_invoice(**args): def create_records(): # create a new suppliers - for name in ['Test TDS Supplier', 'Test TDS Supplier1', 'Test TDS Supplier2', 'Test TDS Supplier3']: + for name in ['Test TDS Supplier', 'Test TDS Supplier1', 'Test TDS Supplier2', 'Test TDS Supplier3', 'Test TDS Supplier4']: if frappe.db.exists('Supplier', name): continue