Merge pull request #39349 from GursheenK/JVs-in-withholding-report
fix: TDS accounts GLE query for withholding category report
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 4a80dd0..852cf15 100644
--- a/erpnext/accounts/report/tax_withholding_details/tax_withholding_details.py
+++ b/erpnext/accounts/report/tax_withholding_details/tax_withholding_details.py
@@ -354,9 +354,6 @@
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) | (
@@ -368,7 +365,14 @@
(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
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 b3f6737..af55ba6 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 @@
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.utils import get_fiscal_year
-class TestTdsPayableMonthly(AccountsTestMixin, FrappeTestCase):
+class TestTaxWithholdingDetails(AccountsTestMixin, FrappeTestCase):
def setUp(self):
self.create_company()
self.clear_old_entries()
@@ -27,11 +26,15 @@
def test_tax_withholding_for_customers(self):
si = create_sales_invoice(rate=1000)
pe = create_tcs_payment_entry()
+ 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 = [
+ # 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.52, 1000.52],
]
@@ -41,12 +44,15 @@
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()
@@ -109,3 +115,32 @@
)
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()