From f55a131dea68986c3f3a29336fc5748184d6e054 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 13 May 2024 16:24:59 +0530 Subject: [PATCH] fix: valuation issue for batch (backport #41425) (#41430) fix: valuation issue for batch (#41425) (cherry picked from commit 065163146c6137e235c1da1409537d12563a140f) Co-authored-by: rohitwaghchaure --- .../serial_and_batch_bundle.py | 14 +++++++++++++- .../test_serial_and_batch_bundle.py | 2 ++ erpnext/stock/serial_batch_bundle.py | 4 ++-- 3 files changed, 17 insertions(+), 3 deletions(-) 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)