fix: allow to use batchwise valuation for moving average items
(cherry picked from commit 65ba79bb85)
This commit is contained in:
committed by
Mergify
parent
4163b18ec3
commit
e479975f54
@@ -160,10 +160,6 @@ class Batch(Document):
|
||||
from erpnext.stock.utils import get_valuation_method
|
||||
|
||||
if self.is_new():
|
||||
if get_valuation_method(self.item) == "Moving Average":
|
||||
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
|
||||
|
||||
@@ -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, 150)
|
||||
self.assertEqual(valuation_rate, 100.0)
|
||||
|
||||
doc = frappe.get_doc("Stock Settings")
|
||||
doc.do_not_use_batchwise_valuation = 1
|
||||
|
||||
@@ -1960,6 +1960,53 @@ class TestStockEntry(FrappeTestCase):
|
||||
self.assertEqual(se.items[0].amount, 300)
|
||||
self.assertEqual(se.items[0].basic_amount, 300)
|
||||
|
||||
def test_use_batch_wise_valuation_for_moving_average_item(self):
|
||||
item_code = "_Test Use Batch Wise MA Valuation Item"
|
||||
|
||||
make_item(
|
||||
item_code,
|
||||
{
|
||||
"is_stock_item": 1,
|
||||
"valuation_method": "Moving Average",
|
||||
"has_batch_no": 1,
|
||||
"create_new_batch": 1,
|
||||
"batch_naming_series": "Test-UBWVMAV-T-NNS.#####",
|
||||
},
|
||||
)
|
||||
|
||||
frappe.db.set_single_value("Stock Settings", "do_not_use_batchwise_valuation", 0)
|
||||
|
||||
batches = []
|
||||
se = make_stock_entry(
|
||||
item_code=item_code,
|
||||
qty=10,
|
||||
to_warehouse="_Test Warehouse - _TC",
|
||||
basic_rate=100,
|
||||
posting_date=add_days(nowdate(), -2),
|
||||
)
|
||||
|
||||
batches.append(get_batch_from_bundle(se.items[0].serial_and_batch_bundle))
|
||||
|
||||
se = make_stock_entry(
|
||||
item_code=item_code,
|
||||
qty=10,
|
||||
to_warehouse="_Test Warehouse - _TC",
|
||||
basic_rate=300,
|
||||
posting_date=add_days(nowdate(), -1),
|
||||
)
|
||||
|
||||
batches.append(get_batch_from_bundle(se.items[0].serial_and_batch_bundle))
|
||||
|
||||
se = make_stock_entry(
|
||||
item_code=item_code,
|
||||
qty=5,
|
||||
from_warehouse="_Test Warehouse - _TC",
|
||||
batch_no=batches[1],
|
||||
posting_date=nowdate(),
|
||||
)
|
||||
|
||||
self.assertEqual(se.items[0].basic_rate, 300)
|
||||
|
||||
|
||||
def make_serialized_item(**args):
|
||||
args = frappe._dict(args)
|
||||
|
||||
@@ -523,7 +523,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 = [100.0, 100.0, 100.0, 100.0]
|
||||
expected_incoming_rates = expected_abs_svd = [75.0, 125.0, 75.0, 125.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):
|
||||
|
||||
@@ -692,7 +692,9 @@ class BatchNoValuation(DeprecatedBatchNoValuation):
|
||||
self.batchwise_valuation_batches = []
|
||||
self.non_batchwise_valuation_batches = []
|
||||
|
||||
if get_valuation_method(self.sle.item_code) == "Moving Average":
|
||||
if get_valuation_method(self.sle.item_code) == "Moving Average" and frappe.db.get_single_value(
|
||||
"Stock Settings", "do_not_use_batchwise_valuation"
|
||||
):
|
||||
self.non_batchwise_valuation_batches = self.batches
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user