Merge pull request #57711 from frappe/pg-audit/purchase-register-add-deduct

fix(accounts): net Add and Deduct tax rows in Purchase Register
This commit is contained in:
Mihir Kandoi
2026-08-03 00:52:24 +05:30
committed by GitHub
parent 03183fc4d9
commit a30f3dde0f
2 changed files with 37 additions and 2 deletions

View File

@@ -553,8 +553,8 @@ def get_invoice_tax_map(invoice_list, invoice_expense_map, expense_accounts, inc
else:
invoice_expense_map[d.parent][d.account_head] = flt(d.tax_amount)
else:
invoice_tax_map.setdefault(d.parent, frappe._dict()).setdefault(d.account_head, [])
invoice_tax_map[d.parent][d.account_head] = flt(d.tax_amount)
invoice_tax_map.setdefault(d.parent, frappe._dict()).setdefault(d.account_head, 0.0)
invoice_tax_map[d.parent][d.account_head] += flt(d.tax_amount)
return invoice_expense_map, invoice_tax_map

View File

@@ -47,6 +47,41 @@ class TestPurchaseRegister(ERPNextTestSuite):
self.assertEqual(labels, sorted([lower, upper], key=str.casefold))
def test_add_and_deduct_rows_on_one_account_are_netted(self):
"""An account head carrying both an Add and a Deduct row must report their net.
The tax query groups by (parent, account_head, add_deduct_tax), so such an account comes
back as two rows. Only one of them survived into the report.
"""
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import (
make_purchase_invoice as make_pi,
)
company = "_Test Company"
tax_account = "_Test Account VAT - _TC"
pi = make_pi(company=company, do_not_save=True)
for add_deduct, amount in (("Add", 10), ("Deduct", 4)):
pi.append(
"taxes",
{
"charge_type": "Actual",
"account_head": tax_account,
"description": "VAT",
"category": "Total",
"add_deduct_tax": add_deduct,
"tax_amount": amount,
"cost_center": "Main - _TC",
},
)
pi.save()
pi.submit()
filters = frappe._dict(company=company, from_date=add_months(today(), -1), to_date=today())
row = next(r for r in execute(filters)[1] if r.get("voucher_no") == pi.name)
self.assertEqual(flt(row.get(frappe.scrub(tax_account))), 6.0)
def test_purchase_register_ignores_tax_rows_from_other_doctype(self):
filters = frappe._dict(company="_Test Company 6", from_date=add_months(today(), -1), to_date=today())