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 91951834bf9..67f946eb7c8 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 @@ -1149,7 +1149,18 @@ def make_batch_nos(item_code, batch_nos): continue batch_nos_details.append( - (batch_no, batch_no, now(), now(), user, user, item.item_code, item.item_name, item.description) + ( + batch_no, + batch_no, + now(), + now(), + user, + user, + item.item_code, + item.item_name, + item.description, + 1, + ) ) fields = [ @@ -1162,6 +1173,7 @@ def make_batch_nos(item_code, batch_nos): "item", "item_name", "description", + "use_batchwise_valuation", ] frappe.db.bulk_insert("Batch", fields=fields, values=set(batch_nos_details)) diff --git a/erpnext/stock/doctype/serial_and_batch_bundle/test_serial_and_batch_bundle.py b/erpnext/stock/doctype/serial_and_batch_bundle/test_serial_and_batch_bundle.py index 5f75b40411c..c313917bd4c 100644 --- a/erpnext/stock/doctype/serial_and_batch_bundle/test_serial_and_batch_bundle.py +++ b/erpnext/stock/doctype/serial_and_batch_bundle/test_serial_and_batch_bundle.py @@ -498,6 +498,8 @@ class TestSerialandBatchBundle(FrappeTestCase): make_batch_nos(item_code, batch_nos) self.assertTrue(frappe.db.exists("Batch", batch_id)) + use_batchwise_valuation = frappe.db.get_value("Batch", batch_id, "use_batchwise_valuation") + self.assertEqual(use_batchwise_valuation, 1) batch_id = "TEST-BATTCCH-VAL-00001" batch_nos = [{"batch_no": batch_id, "qty": 1}] diff --git a/erpnext/stock/serial_batch_bundle.py b/erpnext/stock/serial_batch_bundle.py index 72945e9abc3..573d7280ca1 100644 --- a/erpnext/stock/serial_batch_bundle.py +++ b/erpnext/stock/serial_batch_bundle.py @@ -553,7 +553,7 @@ class BatchNoValuation(DeprecatedBatchNoValuation): self.set_stock_value_difference() def get_batch_no_ledgers(self) -> list[dict]: - if not self.batchwise_valuation_batches: + if not self.batches: return [] parent = frappe.qb.DocType("Serial and Batch Bundle") @@ -575,7 +575,7 @@ class BatchNoValuation(DeprecatedBatchNoValuation): Sum(child.qty).as_("qty"), ) .where( - (child.batch_no.isin(self.batchwise_valuation_batches)) + (child.batch_no.isin(self.batches)) & (parent.warehouse == self.sle.warehouse) & (parent.item_code == self.sle.item_code) & (parent.docstatus == 1)