diff --git a/erpnext/stock/deprecated_serial_batch.py b/erpnext/stock/deprecated_serial_batch.py index f946f459c07..359027ec6be 100644 --- a/erpnext/stock/deprecated_serial_batch.py +++ b/erpnext/stock/deprecated_serial_batch.py @@ -228,7 +228,6 @@ class DeprecatedBatchNoValuation: (sle.item_code == self.sle.item_code) & (sle.warehouse == self.sle.warehouse) & (sle.batch_no.isnotnull()) - & (batch.use_batchwise_valuation == 0) & (sle.is_cancelled == 0) & (sle.batch_no.isin(self.non_batchwise_valuation_batches)) ) @@ -278,7 +277,6 @@ class DeprecatedBatchNoValuation: (sle.item_code == self.sle.item_code) & (sle.warehouse == self.sle.warehouse) & (sle.batch_no.isnotnull()) - & (batch.use_batchwise_valuation == 0) & (sle.is_cancelled == 0) ) .where(timestamp_condition) @@ -318,7 +316,6 @@ class DeprecatedBatchNoValuation: (sabb.item_code == self.sle.item_code) & (sabb.warehouse == self.sle.warehouse) & (sabb_entry.batch_no.isnotnull()) - & (batch.use_batchwise_valuation == 0) & (sabb.is_cancelled == 0) & (sabb.docstatus == 1) ) @@ -378,7 +375,6 @@ class DeprecatedBatchNoValuation: (bundle.item_code == self.sle.item_code) & (bundle.warehouse == self.sle.warehouse) & (bundle_child.batch_no.isnotnull()) - & (batch.use_batchwise_valuation == 0) & (bundle.is_cancelled == 0) & (bundle.docstatus == 1) & (bundle.type_of_transaction.isin(["Inward", "Outward"])) diff --git a/erpnext/stock/doctype/batch/batch.py b/erpnext/stock/doctype/batch/batch.py index ae77672b730..4aeb165c7b5 100644 --- a/erpnext/stock/doctype/batch/batch.py +++ b/erpnext/stock/doctype/batch/batch.py @@ -157,7 +157,13 @@ class Batch(Document): frappe.throw(_("The selected item cannot have Batch")) def set_batchwise_valuation(self): + from erpnext.stock.utils import get_valuation_method + if self.is_new(): + if get_valuation_method(self.item) != "FIFO": + self.use_batchwise_valuation = 0 + return + if frappe.db.get_single_value("Stock Settings", "do_not_use_batchwise_valuation"): self.use_batchwise_valuation = 0 return diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index 9cf9f4d4958..4f22d83244e 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -3327,7 +3327,7 @@ class TestPurchaseReceipt(FrappeTestCase): bundle = dn.items[0].serial_and_batch_bundle valuation_rate = frappe.db.get_value("Serial and Batch Bundle", bundle, "avg_rate") - self.assertEqual(valuation_rate, 100) + self.assertEqual(valuation_rate, 150) doc = frappe.get_doc("Stock Settings") doc.do_not_use_batchwise_valuation = 1 diff --git a/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py b/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py index 42e402e0005..c0171b7a710 100644 --- a/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py +++ b/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py @@ -484,7 +484,7 @@ class TestStockLedgerEntry(FrappeTestCase, StockTestMixin): dns = create_delivery_note_entries_for_batchwise_item_valuation_test(dn_entry_list) sle_details = fetch_sle_details_for_doc_list(dns, ["stock_value_difference"]) svd_list = [-1 * d["stock_value_difference"] for d in sle_details] - expected_incoming_rates = expected_abs_svd = [75.0, 125.0, 75.0, 125.0] + expected_incoming_rates = expected_abs_svd = [100.0, 100.0, 100.0, 100.0] self.assertEqual(expected_abs_svd, svd_list, "Incorrect 'Stock Value Difference' values") for dn, _incoming_rate in zip(dns, expected_incoming_rates, strict=False): diff --git a/erpnext/stock/serial_batch_bundle.py b/erpnext/stock/serial_batch_bundle.py index c88df01665f..8e64b4e856f 100644 --- a/erpnext/stock/serial_batch_bundle.py +++ b/erpnext/stock/serial_batch_bundle.py @@ -683,6 +683,8 @@ class BatchNoValuation(DeprecatedBatchNoValuation): return query.run(as_dict=True) def prepare_batches(self): + from erpnext.stock.utils import get_valuation_method + self.batches = self.batch_nos if isinstance(self.batch_nos, dict): self.batches = list(self.batch_nos.keys()) @@ -690,6 +692,10 @@ class BatchNoValuation(DeprecatedBatchNoValuation): self.batchwise_valuation_batches = [] self.non_batchwise_valuation_batches = [] + if get_valuation_method(self.sle.item_code) == "Moving Average": + self.non_batchwise_valuation_batches = self.batches + return + batches = frappe.get_all( "Batch", filters={"name": ("in", self.batches), "use_batchwise_valuation": 1}, fields=["name"] )