From c648090b5d18c58af658ec4fe88114741efa60c7 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Fri, 12 Jan 2024 18:33:06 +0530 Subject: [PATCH 1/4] fix: query for filter by party --- .../tax_withholding_details.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/report/tax_withholding_details/tax_withholding_details.py b/erpnext/accounts/report/tax_withholding_details/tax_withholding_details.py index d045d91f52..613d6f9fca 100644 --- a/erpnext/accounts/report/tax_withholding_details/tax_withholding_details.py +++ b/erpnext/accounts/report/tax_withholding_details/tax_withholding_details.py @@ -340,9 +340,6 @@ def get_tds_docs_query(filters, bank_accounts, tds_accounts): if filters.get("to_date"): query = query.where(gle.posting_date <= filters.get("to_date")) - if bank_accounts: - query = query.where(gle.against.notin(bank_accounts)) - if filters.get("party"): party = [filters.get("party")] jv_condition = gle.against.isin(party) | ( @@ -354,7 +351,14 @@ def get_tds_docs_query(filters, bank_accounts, tds_accounts): (gle.voucher_type == "Journal Entry") & ((gle.party_type == filters.get("party_type")) | (gle.party_type == "")) ) - query = query.where((gle.account.isin(tds_accounts) & jv_condition) | gle.party.isin(party)) + + query.where((gle.account.isin(tds_accounts) & jv_condition) | gle.party.isin(party)) + if bank_accounts: + query = query.where( + gle.against.notin(bank_accounts) & (gle.account.isin(tds_accounts) & jv_condition) + | gle.party.isin(party) + ) + return query From e9526b112d2610293411ada5a98ee847dd511306 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Sun, 21 Jan 2024 18:04:47 +0530 Subject: [PATCH 2/4] test: journals in withholding report --- .../test_tax_withholding_details.py | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/erpnext/accounts/report/tax_withholding_details/test_tax_withholding_details.py b/erpnext/accounts/report/tax_withholding_details/test_tax_withholding_details.py index b3f67378a9..88321e928c 100644 --- a/erpnext/accounts/report/tax_withholding_details/test_tax_withholding_details.py +++ b/erpnext/accounts/report/tax_withholding_details/test_tax_withholding_details.py @@ -5,9 +5,8 @@ import frappe from frappe.tests.utils import FrappeTestCase from frappe.utils import today -from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center +from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_entry -from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.doctype.tax_withholding_category.test_tax_withholding_category import ( create_tax_withholding_category, @@ -17,7 +16,7 @@ from erpnext.accounts.test.accounts_mixin import AccountsTestMixin from erpnext.accounts.utils import get_fiscal_year -class TestTdsPayableMonthly(AccountsTestMixin, FrappeTestCase): +class TestTaxWithholdingDetails(AccountsTestMixin, FrappeTestCase): def setUp(self): self.create_company() self.clear_old_entries() @@ -27,13 +26,25 @@ class TestTdsPayableMonthly(AccountsTestMixin, FrappeTestCase): def test_tax_withholding_for_customers(self): si = create_sales_invoice(rate=1000) pe = create_tcs_payment_entry() + jv = make_journal_entry( + "TCS - _TC", + "Debtors - _TC", + 1000, + "_Test Cost Center - _TC", + save=False, + ) + jv.accounts[1].party_type = "Customer" + jv.accounts[1].party = "_Test Customer" + jv.submit() + filters = frappe._dict( company="_Test Company", party_type="Customer", from_date=today(), to_date=today() ) result = execute(filters)[1] expected_values = [ + [jv.name, "TCS", 0.075, 1000, -1000, 1000], [pe.name, "TCS", 0.075, 2550, 0.53, 2550.53], - [si.name, "TCS", 0.075, 1000, 0.52, 1000.52], + [si.name, "TCS", 0.075, 1000, 0.525, 1000.525], ] self.check_expected_values(result, expected_values) @@ -41,12 +52,15 @@ class TestTdsPayableMonthly(AccountsTestMixin, FrappeTestCase): for i in range(len(result)): voucher = frappe._dict(result[i]) voucher_expected_values = expected_values[i] - self.assertEqual(voucher.ref_no, voucher_expected_values[0]) - self.assertEqual(voucher.section_code, voucher_expected_values[1]) - self.assertEqual(voucher.rate, voucher_expected_values[2]) - self.assertEqual(voucher.base_total, voucher_expected_values[3]) - self.assertAlmostEqual(voucher.tax_amount, voucher_expected_values[4]) - self.assertAlmostEqual(voucher.grand_total, voucher_expected_values[5]) + voucher_actual_values = ( + voucher.ref_no, + voucher.section_code, + voucher.rate, + voucher.base_total, + voucher.tax_amount, + voucher.grand_total, + ) + self.assertSequenceEqual(voucher_actual_values, voucher_expected_values) def tearDown(self): self.clear_old_entries() From ddecbeba756b741950f4233a3355b07add285880 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Tue, 30 Jan 2024 12:39:40 +0530 Subject: [PATCH 3/4] fix: test JV totals using back calculation logic --- .../test_tax_withholding_details.py | 43 ++++++++++++++----- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/erpnext/accounts/report/tax_withholding_details/test_tax_withholding_details.py b/erpnext/accounts/report/tax_withholding_details/test_tax_withholding_details.py index 88321e928c..6825b4dcf6 100644 --- a/erpnext/accounts/report/tax_withholding_details/test_tax_withholding_details.py +++ b/erpnext/accounts/report/tax_withholding_details/test_tax_withholding_details.py @@ -26,23 +26,15 @@ class TestTaxWithholdingDetails(AccountsTestMixin, FrappeTestCase): def test_tax_withholding_for_customers(self): si = create_sales_invoice(rate=1000) pe = create_tcs_payment_entry() - jv = make_journal_entry( - "TCS - _TC", - "Debtors - _TC", - 1000, - "_Test Cost Center - _TC", - save=False, - ) - jv.accounts[1].party_type = "Customer" - jv.accounts[1].party = "_Test Customer" - jv.submit() + jv = create_tcs_journal_entry() filters = frappe._dict( company="_Test Company", party_type="Customer", from_date=today(), to_date=today() ) result = execute(filters)[1] expected_values = [ - [jv.name, "TCS", 0.075, 1000, -1000, 1000], + # Check for JV totals using back calculation logic + [jv.name, "TCS", 0.075, -10000.0, -7.5, -10000.0], [pe.name, "TCS", 0.075, 2550, 0.53, 2550.53], [si.name, "TCS", 0.075, 1000, 0.525, 1000.525], ] @@ -123,3 +115,32 @@ def create_tcs_payment_entry(): ) payment_entry.submit() return payment_entry + + +def create_tcs_journal_entry(): + jv = frappe.new_doc("Journal Entry") + jv.posting_date = today() + jv.company = "_Test Company" + jv.set( + "accounts", + [ + { + "account": "Debtors - _TC", + "party_type": "Customer", + "party": "_Test Customer", + "credit_in_account_currency": 10000, + }, + { + "account": "Debtors - _TC", + "party_type": "Customer", + "party": "_Test Customer", + "debit_in_account_currency": 9992.5, + }, + { + "account": "TCS - _TC", + "debit_in_account_currency": 7.5, + }, + ], + ) + jv.insert() + return jv.submit() From 25c2b79864ba96b43388a235b34c5b55e2898a8a Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Mon, 5 Feb 2024 13:03:21 +0530 Subject: [PATCH 4/4] fix: precision for tds amount --- .../tax_withholding_details/test_tax_withholding_details.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/report/tax_withholding_details/test_tax_withholding_details.py b/erpnext/accounts/report/tax_withholding_details/test_tax_withholding_details.py index 6825b4dcf6..af55ba6639 100644 --- a/erpnext/accounts/report/tax_withholding_details/test_tax_withholding_details.py +++ b/erpnext/accounts/report/tax_withholding_details/test_tax_withholding_details.py @@ -36,7 +36,7 @@ class TestTaxWithholdingDetails(AccountsTestMixin, FrappeTestCase): # Check for JV totals using back calculation logic [jv.name, "TCS", 0.075, -10000.0, -7.5, -10000.0], [pe.name, "TCS", 0.075, 2550, 0.53, 2550.53], - [si.name, "TCS", 0.075, 1000, 0.525, 1000.525], + [si.name, "TCS", 0.075, 1000, 0.52, 1000.52], ] self.check_expected_values(result, expected_values)