fix: valuation issue for batch (backport #41425) (#41430)

fix: valuation issue for batch (#41425)

(cherry picked from commit 065163146c)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
mergify[bot]
2024-05-13 16:24:59 +05:30
committed by GitHub
parent b6f82a656f
commit f55a131dea
3 changed files with 17 additions and 3 deletions

View File

@@ -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))

View File

@@ -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}]

View File

@@ -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)