From cf5e8ce87846ae4557087dc465ee78332f6e97df Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Wed, 13 May 2026 14:27:52 +0530 Subject: [PATCH] =?UTF-8?q?Revert=20"fix:=20debit=20credit=20not=20equal?= =?UTF-8?q?=20in=20purchase=20transactions=20for=20mult=E2=80=A6=20(#54906?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Revert "fix: debit credit not equal in purchase transactions for multi currency" This reverts commit 75bcea57f4d7600334eec941fd15aa8b17dd6279. * Revert "test: add test case" This reverts commit 1d30a202c329183af7d1523fb49b1f8be2bbc761. * Revert "fix: include rejected qty in tax (purchase receipt)" This reverts commit 8c9a88abbedf6babcfa1d1fea84335768af4067e. --- erpnext/controllers/buying_controller.py | 12 +------- erpnext/controllers/taxes_and_totals.py | 21 ++------------ .../purchase_receipt/purchase_receipt.py | 9 +----- .../purchase_receipt/test_purchase_receipt.py | 29 +------------------ 4 files changed, 5 insertions(+), 66 deletions(-) diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index 4f5efd7de7d..e5847c449a9 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -456,17 +456,7 @@ class BuyingController(SubcontractingController): get_conversion_factor(item.item_code, item.uom).get("conversion_factor") or 1.0 ) - net_rate = ( - flt( - (item.base_net_amount / item.received_qty) * item.qty, - item.precision("base_net_amount"), - ) - if item.received_qty - and frappe.get_single_value( - "Buying Settings", "bill_for_rejected_quantity_in_purchase_invoice" - ) - else item.base_net_amount - ) + net_rate = item.base_net_amount if item.sales_incoming_rate: # for internal transfer net_rate = item.qty * item.sales_incoming_rate diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 69b8234e6a3..d1afe78cfc3 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -169,10 +169,6 @@ class calculate_taxes_and_totals: return if not self.discount_amount_applied: - bill_for_rejected_quantity_in_purchase_invoice = frappe.get_single_value( - "Buying Settings", "bill_for_rejected_quantity_in_purchase_invoice" - ) - do_not_round_fields = ["valuation_rate", "incoming_rate"] for item in self.doc.items: @@ -236,13 +232,7 @@ class calculate_taxes_and_totals: elif not item.qty and self.doc.get("is_debit_note"): item.amount = flt(item.rate, item.precision("amount")) else: - qty = ( - (item.qty + item.rejected_qty) - if bill_for_rejected_quantity_in_purchase_invoice - and self.doc.doctype == "Purchase Receipt" - else item.qty - ) - item.amount = flt(item.rate * qty, item.precision("amount")) + item.amount = flt(item.rate * item.qty, item.precision("amount")) item.net_amount = item.amount @@ -402,16 +392,9 @@ class calculate_taxes_and_totals: self.doc.total ) = self.doc.base_total = self.doc.net_total = self.doc.base_net_total = 0.0 - bill_for_rejected_quantity_in_purchase_invoice = frappe.get_single_value( - "Buying Settings", "bill_for_rejected_quantity_in_purchase_invoice" - ) for item in self._items: self.doc.total += item.amount - self.doc.total_qty += ( - (item.qty + item.rejected_qty) - if bill_for_rejected_quantity_in_purchase_invoice and self.doc.doctype == "Purchase Receipt" - else item.qty - ) + self.doc.total_qty += item.qty self.doc.base_total += item.base_amount self.doc.net_total += item.net_amount self.doc.base_net_total += item.base_net_amount diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index e2361335fc0..335a77e3963 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -562,14 +562,7 @@ class PurchaseReceipt(BuyingController): else flt(item.net_amount, item.precision("net_amount")) ) - outgoing_amount = ( - flt((item.base_net_amount / item.received_qty) * item.qty, item.precision("base_net_amount")) - if item.received_qty - and frappe.get_single_value( - "Buying Settings", "bill_for_rejected_quantity_in_purchase_invoice" - ) - else item.base_net_amount - ) + outgoing_amount = item.base_net_amount if self.is_internal_transfer() and item.valuation_rate: outgoing_amount = abs(get_stock_value_difference(self.name, item.name, item.from_warehouse)) credit_amount = outgoing_amount diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index ec6d8634355..142378124b4 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -4606,7 +4606,7 @@ class TestPurchaseReceipt(ERPNextTestSuite): self.assertEqual(srbnb_cost, 1500) - def test_valuation_rate_for_rejected_materials_without_accepted_materials(self): + def test_valuation_rate_for_rejected_materials_withoout_accepted_materials(self): item = make_item("Test Item with Rej Material Valuation WO Accepted", {"is_stock_item": 1}) company = "_Test Company with perpetual inventory" @@ -5419,33 +5419,6 @@ class TestPurchaseReceipt(ERPNextTestSuite): self.assertEqual(row.warehouse, "_Test Warehouse 1 - _TC") self.assertEqual(row.incoming_rate, 100) - def test_bill_for_rejected_quantity_in_purchase_invoice(self): - item_code = make_item("Test Rejected Qty", {"is_stock_item": 1}).name - - with self.change_settings("Buying Settings", {"bill_for_rejected_quantity_in_purchase_invoice": 0}): - pr = make_purchase_receipt( - item_code=item_code, - qty=10, - rejected_qty=2, - rate=10, - warehouse="_Test Warehouse - _TC", - ) - - self.assertEqual(pr.total_qty, 10) - self.assertEqual(pr.total, 100) - - with self.change_settings("Buying Settings", {"bill_for_rejected_quantity_in_purchase_invoice": 1}): - pr = make_purchase_receipt( - item_code=item_code, - qty=10, - rejected_qty=2, - rate=10, - warehouse="_Test Warehouse - _TC", - ) - - self.assertEqual(pr.total_qty, 12) - self.assertEqual(pr.total, 120) - def test_different_exchange_rate_in_pr_and_pi(self): from erpnext.accounts.doctype.account.test_account import create_account