From 614402cf6c8e55e1ed2b195b668af49093d3bb18 Mon Sep 17 00:00:00 2001 From: venkat102 Date: Thu, 30 Oct 2025 00:16:37 +0530 Subject: [PATCH 1/2] fix: set valuation rate for rejected serial/batch item --- .../serial_and_batch_bundle/serial_and_batch_bundle.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py index fcb6e35a7db..c8558e17474 100644 --- a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py +++ b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py @@ -669,8 +669,12 @@ class SerialandBatchBundle(Document): if batches and valuation_method == "FIFO": stock_queue = parse_json(prev_sle.stock_queue) + set_valuation_rate_for_rejected_materials = frappe.db.get_single_value( + "Buying Settings", "set_valuation_rate_for_rejected_materials" + ) + for d in self.entries: - if self.is_rejected: + if self.is_rejected and not set_valuation_rate_for_rejected_materials: rate = 0.0 elif (d.incoming_rate == rate) and not stock_queue and d.qty and d.stock_value_difference: continue From d002959d357dd1b13fafed1553213ab2252fcb69 Mon Sep 17 00:00:00 2001 From: venkat102 Date: Thu, 30 Oct 2025 00:18:23 +0530 Subject: [PATCH 2/2] test: add unit test for valuation rate on rejected serial/batch item --- .../purchase_receipt/test_purchase_receipt.py | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index fabebeba5b5..c94f8b712bc 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -4312,6 +4312,67 @@ class TestPurchaseReceipt(IntegrationTestCase): frappe.db.set_single_value("Buying Settings", "set_valuation_rate_for_rejected_materials", 0) + @IntegrationTestCase.change_settings( + "Buying Settings", + {"bill_for_rejected_quantity_in_purchase_invoice": 1, "set_valuation_rate_for_rejected_materials": 1}, + ) + def test_valuation_rate_for_rejected_materials_with_serial_no(self): + item = make_item( + "Test Serial Item with Rej Material Valuation", + {"is_stock_item": 1, "has_serial_no": 1, "serial_no_series": "SNU-TSIRMV-.#####"}, + ) + company = "_Test Company with perpetual inventory" + + warehouse = create_warehouse( + "_Test In-ward Warehouse", + company="_Test Company with perpetual inventory", + ) + + rej_warehouse = create_warehouse( + "_Test Warehouse - Rejected Material", + company="_Test Company with perpetual inventory", + ) + + pr = make_purchase_receipt( + item_code=item.name, + qty=10, + rate=100, + company=company, + warehouse=warehouse, + rejected_qty=5, + rejected_warehouse=rej_warehouse, + ) + + stock_received_but_not_billed_account = frappe.get_value( + "Company", + company, + "stock_received_but_not_billed", + ) + + rejected_item_cost = frappe.db.get_value( + "Stock Ledger Entry", + { + "voucher_type": "Purchase Receipt", + "voucher_no": pr.name, + "warehouse": rej_warehouse, + }, + "stock_value_difference", + ) + + self.assertEqual(rejected_item_cost, 500) + + srbnb_cost = frappe.db.get_value( + "GL Entry", + { + "voucher_type": "Purchase Receipt", + "voucher_no": pr.name, + "account": stock_received_but_not_billed_account, + }, + "credit", + ) + + self.assertEqual(srbnb_cost, 1500) + 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"