From af9fa049c749c9f72f0b21a5960111cb6ec57c12 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Mon, 21 Feb 2022 12:28:19 +0530 Subject: [PATCH] fix: batchwise valuation can only be used by FIFO/LIFO --- erpnext/stock/doctype/batch/batch.py | 24 ++------------- .../test_stock_ledger_entry.py | 30 ------------------- 2 files changed, 2 insertions(+), 52 deletions(-) diff --git a/erpnext/stock/doctype/batch/batch.py b/erpnext/stock/doctype/batch/batch.py index b5e56ad301..93e8d41367 100644 --- a/erpnext/stock/doctype/batch/batch.py +++ b/erpnext/stock/doctype/batch/batch.py @@ -6,7 +6,6 @@ import frappe from frappe import _ from frappe.model.document import Document from frappe.model.naming import make_autoname, revert_series_if_last -from frappe.query_builder.functions import Sum from frappe.utils import cint, flt, get_link_to_form from frappe.utils.data import add_days from frappe.utils.jinja import render_template @@ -347,26 +346,7 @@ def get_pos_reserved_batch_qty(filters): def can_use_batchwise_valuation(item_code: str) -> bool: """ Check if item can use batchwise valuation. - Note: Item with existing moving average batches can't use batchwise valuation - until they are exhausted. - """ + Note: Moving average valuation method can not use batch_wise_valuation.""" from erpnext.stock.stock_ledger import get_valuation_method - batch = frappe.qb.DocType("Batch") - if get_valuation_method(item_code) != "Moving Average": - return True - - batch_qty = ( - frappe.qb - .from_(batch) - .select(Sum(batch.batch_qty)) - .where( - (batch.use_batchwise_valuation == 0) - & (batch.item == item_code) - ) - ).run() - - if batch_qty and batch_qty[0][0]: - return False - - return True + return get_valuation_method(item_code) != "Moving Average" 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 c65ed2888e..0864ece995 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 @@ -665,36 +665,6 @@ class TestStockLedgerEntry(ERPNextTestCase): {"actual_qty": -10, "stock_value_difference": -10*40, "stock_queue": []}, ])) - def test_mixed_valuation_batches_moving_average(self): - item_code, warehouses, batches = setup_item_valuation_test(use_batchwise_valuation=0, valuation_method="Moving Average") - warehouse = warehouses[0] - - make_stock_entry(item_code=item_code, target=warehouse, batch_no=batches[0], - qty=10, rate=10) - make_stock_entry(item_code=item_code, target=warehouse, batch_no=batches[1], - qty=10, rate=20) - make_stock_entry(item_code=item_code, target=warehouse, batch_no=batches[0], - qty=5, rate=15) - - new1 = make_stock_entry(item_code=item_code, target=warehouse, qty=10, rate=40) - batches.append(new1.items[0].batch_no) - new2 = make_stock_entry(item_code=item_code, target=warehouse, qty=10, rate=42) - batches.append(new2.items[0].batch_no) - - # consume old batch as per FIFO - make_stock_entry(item_code=item_code, source=warehouse, qty=15, batch_no=batches[0]) - # consume new batch as per batch - make_stock_entry(item_code=item_code, source=warehouse, qty=10, batch_no=batches[-1]) - # finish all old batches - make_stock_entry(item_code=item_code, source=warehouse, qty=10, batch_no=batches[1]) - - # finish all new batches - consume_new1 = make_stock_entry(item_code=item_code, source=warehouse, qty=10, batch_no=batches[-2]) - self.assertSLEs(consume_new1, ([ - {"stock_value": 0}, - ])) - - def create_repack_entry(**args): args = frappe._dict(args) repack = frappe.new_doc("Stock Entry")