mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-11 11:08:44 +00:00
fix: allow to use batchwise valuation for moving average items
(cherry picked from commit65ba79bb85) (cherry picked from commite479975f54)
This commit is contained in:
committed by
Mergify
parent
1326ba5326
commit
dded682feb
@@ -160,10 +160,6 @@ class Batch(Document):
|
|||||||
from erpnext.stock.utils import get_valuation_method
|
from erpnext.stock.utils import get_valuation_method
|
||||||
|
|
||||||
if self.is_new():
|
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"):
|
if frappe.db.get_single_value("Stock Settings", "do_not_use_batchwise_valuation"):
|
||||||
self.use_batchwise_valuation = 0
|
self.use_batchwise_valuation = 0
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -3327,7 +3327,7 @@ class TestPurchaseReceipt(FrappeTestCase):
|
|||||||
bundle = dn.items[0].serial_and_batch_bundle
|
bundle = dn.items[0].serial_and_batch_bundle
|
||||||
|
|
||||||
valuation_rate = frappe.db.get_value("Serial and Batch Bundle", bundle, "avg_rate")
|
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 = frappe.get_doc("Stock Settings")
|
||||||
doc.do_not_use_batchwise_valuation = 1
|
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].amount, 300)
|
||||||
self.assertEqual(se.items[0].basic_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):
|
def make_serialized_item(**args):
|
||||||
args = frappe._dict(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)
|
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"])
|
sle_details = fetch_sle_details_for_doc_list(dns, ["stock_value_difference"])
|
||||||
svd_list = [-1 * d["stock_value_difference"] for d in sle_details]
|
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")
|
self.assertEqual(expected_abs_svd, svd_list, "Incorrect 'Stock Value Difference' values")
|
||||||
for dn, _incoming_rate in zip(dns, expected_incoming_rates, strict=False):
|
for dn, _incoming_rate in zip(dns, expected_incoming_rates, strict=False):
|
||||||
|
|||||||
@@ -692,7 +692,9 @@ class BatchNoValuation(DeprecatedBatchNoValuation):
|
|||||||
self.batchwise_valuation_batches = []
|
self.batchwise_valuation_batches = []
|
||||||
self.non_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
|
self.non_batchwise_valuation_batches = self.batches
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user