From f72d14b1ca9824100b84ab635561fdeb00cead08 Mon Sep 17 00:00:00 2001 From: venkat102 Date: Thu, 30 Oct 2025 00:16:37 +0530 Subject: [PATCH 1/3] fix: set valuation rate for rejected serial/batch item (cherry picked from commit 614402cf6c8e55e1ed2b195b668af49093d3bb18) --- .../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 0655cd2cfd7..1992b5dc49f 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 @@ -667,8 +667,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 397bc96b40d1cfd1758aa52e7ac0315eca857b8c Mon Sep 17 00:00:00 2001 From: venkat102 Date: Thu, 30 Oct 2025 00:18:23 +0530 Subject: [PATCH 2/3] test: add unit test for valuation rate on rejected serial/batch item (cherry picked from commit d002959d357dd1b13fafed1553213ab2252fcb69) --- .../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 c0a6c4d0f4a..1443b72c839 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -4287,6 +4287,67 @@ class TestPurchaseReceipt(FrappeTestCase): 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" From b019d2f45ec4ace099f92e341bdfce14c7ff1220 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Thu, 30 Oct 2025 09:06:37 +0530 Subject: [PATCH 3/3] chore: fix linters issue --- erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index 1443b72c839..383421f3c67 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -4287,7 +4287,7 @@ class TestPurchaseReceipt(FrappeTestCase): frappe.db.set_single_value("Buying Settings", "set_valuation_rate_for_rejected_materials", 0) - @IntegrationTestCase.change_settings( + @change_settings( "Buying Settings", {"bill_for_rejected_quantity_in_purchase_invoice": 1, "set_valuation_rate_for_rejected_materials": 1}, )