fix: batchwise valuation can only be used by FIFO/LIFO
This commit is contained in:
parent
75fb561698
commit
af9fa049c7
@ -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"
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user