fix: correct item valuation when "Deduct" is used in Purchase Invoice and Receipt.

(cherry picked from commit e68f149d3a)
This commit is contained in:
ljain112
2026-03-13 11:53:08 +05:30
committed by Mergify
parent 8c35a939cb
commit c6fe5be95a
2 changed files with 65 additions and 2 deletions

View File

@@ -503,11 +503,15 @@ class BuyingController(SubcontractingController):
if d.category not in ["Valuation", "Valuation and Total"]:
continue
amount = flt(d.base_tax_amount_after_discount_amount) * (
-1 if d.get("add_deduct_tax") == "Deduct" else 1
)
if d.charge_type == "On Net Total":
total_valuation_amount += flt(d.base_tax_amount_after_discount_amount)
total_valuation_amount += amount
tax_accounts.append(d.account_head)
else:
total_actual_tax_amount += flt(d.base_tax_amount_after_discount_amount)
total_actual_tax_amount += amount
return tax_accounts, total_valuation_amount, total_actual_tax_amount

View File

@@ -1240,6 +1240,65 @@ class TestPurchaseReceipt(ERPNextTestSuite):
pr.cancel()
def test_item_valuation_with_deduct_valuation_and_total_tax(self):
pr = make_purchase_receipt(
company="_Test Company with perpetual inventory",
warehouse="Stores - TCP1",
supplier_warehouse="Work In Progress - TCP1",
qty=5,
rate=100,
do_not_save=1,
)
pr.append(
"taxes",
{
"charge_type": "Actual",
"add_deduct_tax": "Deduct",
"account_head": "_Test Account Shipping Charges - TCP1",
"category": "Valuation and Total",
"cost_center": "Main - TCP1",
"description": "Valuation Discount",
"tax_amount": 20,
},
)
pr.insert()
self.assertAlmostEqual(pr.items[0].item_tax_amount, -20.0, places=2)
self.assertAlmostEqual(pr.items[0].valuation_rate, 96.0, places=2)
pr.delete()
pr = make_purchase_receipt(
company="_Test Company with perpetual inventory",
warehouse="Stores - TCP1",
supplier_warehouse="Work In Progress - TCP1",
qty=5,
rate=100,
do_not_save=1,
)
pr.append(
"taxes",
{
"charge_type": "On Net Total",
"add_deduct_tax": "Deduct",
"account_head": "_Test Account Shipping Charges - TCP1",
"category": "Valuation and Total",
"cost_center": "Main - TCP1",
"description": "Valuation Discount",
"rate": 10,
},
)
pr.insert()
self.assertAlmostEqual(pr.items[0].item_tax_amount, -50.0, places=2)
self.assertAlmostEqual(pr.items[0].valuation_rate, 90.0, places=2)
pr.delete()
def test_po_to_pi_and_po_to_pr_worflow_full(self):
"""Test following behaviour:
- Create PO