diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index 417173553af..dea868f13b3 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -4038,6 +4038,8 @@ class TestPurchaseReceipt(IntegrationTestCase): make_purchase_return, ) + frappe.flags.through_repost_item_valuation = False + sn_item_code = make_item( "Test Serial No for Validation", {"has_serial_no": 1, "serial_no_series": "SN-TSNFVAL-.#####"} ).name @@ -4069,6 +4071,8 @@ class TestPurchaseReceipt(IntegrationTestCase): make_purchase_return, ) + frappe.flags.through_repost_item_valuation = False + batch_item_code = make_item( "Test Batch No for Validation", {"has_batch_no": 1, "batch_number_series": "BT-TSNFVAL-.#####", "create_new_batch": 1}, 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 2ea12b2b27c..20c4b277a67 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 @@ -322,6 +322,15 @@ class SerialandBatchBundle(Document): else: valuation_rate = valuation_details["batches"].get(row.batch_no) + if frappe.flags.through_repost_item_valuation and not valuation_rate: + # if different serial nos / batches are returned + if row.serial_no: + serial_nos = sorted(list(valuation_details["serial_nos"].keys())) + valuation_rate = valuation_details["serial_nos"].get(serial_nos[cint(row.idx) - 1]) + else: + batches = sorted(list(valuation_details["batches"].keys())) + valuation_rate = valuation_details["batches"].get(batches[cint(row.idx) - 1]) + row.incoming_rate = flt(valuation_rate) row.stock_value_difference = flt(row.qty) * flt(row.incoming_rate) @@ -337,6 +346,9 @@ class SerialandBatchBundle(Document): self.set_incoming_rate_for_inward_transaction(row, save) def validate_returned_serial_batch_no(self, return_against, row, original_inv_details): + if frappe.flags.through_repost_item_valuation: + return + if row.serial_no and row.serial_no not in original_inv_details["serial_nos"]: self.throw_error_message( _(