chore: fix test case

(cherry picked from commit ac8637d5a0)
(cherry picked from commit 6bdf11f5c9)
This commit is contained in:
rohitwaghchaure
2025-09-04 07:18:03 +05:30
committed by Mergify
parent 9c14aa2d01
commit 4dbcef3d67
2 changed files with 58 additions and 49 deletions

View File

@@ -198,7 +198,7 @@ class DeprecatedBatchNoValuation:
@deprecated
def set_balance_value_for_non_batchwise_valuation_batches(self):
self.last_sle = self.get_last_sle_for_non_batch()
if self.last_sle and self.last_sle.stock_value:
if self.last_sle and self.last_sle.stock_queue:
self.stock_queue = json.loads(self.last_sle.stock_queue or "[]") or []
self.set_balance_value_from_sl_entries()

View File

@@ -203,7 +203,10 @@ class TestSerialandBatchBundle(FrappeTestCase):
batch_item_code,
{
"has_batch_no": 1,
"batch_number_series": "TEST-OLD-BAT-VAL-.#####",
"create_new_batch": 1,
"is_stock_item": 1,
"valuation_method": "FIFO",
},
)
@@ -256,57 +259,63 @@ class TestSerialandBatchBundle(FrappeTestCase):
doc.submit()
doc.reload()
bundle_doc = make_serial_batch_bundle(
{
"item_code": batch_item_code,
"warehouse": "_Test Warehouse - _TC",
"voucher_type": "Stock Entry",
"posting_date": today(),
"posting_time": nowtime(),
"qty": -10,
"batches": frappe._dict({batch_id: 10}),
"type_of_transaction": "Outward",
"do_not_submit": True,
}
)
bundle_doc.reload()
for row in bundle_doc.entries:
self.assertEqual(flt(row.stock_value_difference, 2), -1666.67)
bundle_doc.flags.ignore_permissions = True
bundle_doc.flags.ignore_mandatory = True
bundle_doc.flags.ignore_links = True
bundle_doc.flags.ignore_validate = True
bundle_doc.submit()
bundle_doc = make_serial_batch_bundle(
{
"item_code": batch_item_code,
"warehouse": "_Test Warehouse - _TC",
"voucher_type": "Stock Entry",
"posting_date": today(),
"posting_time": nowtime(),
"qty": -20,
"batches": frappe._dict({batch_id: 20}),
"type_of_transaction": "Outward",
"do_not_submit": True,
}
)
bundle_doc.reload()
for row in bundle_doc.entries:
self.assertEqual(flt(row.stock_value_difference, 2), -3333.33)
bundle_doc.flags.ignore_permissions = True
bundle_doc.flags.ignore_mandatory = True
bundle_doc.flags.ignore_links = True
bundle_doc.flags.ignore_validate = True
bundle_doc.submit()
frappe.flags.ignore_serial_batch_bundle_validation = False
frappe.flags.use_serial_and_batch_fields = False
se = make_stock_entry(
item_code=batch_item_code,
source="_Test Warehouse - _TC",
qty=10,
use_serial_batch_fields=True,
batch_no=batch_id,
)
sle = frappe.db.get_value(
"Stock Ledger Entry",
{"item_code": batch_item_code, "is_cancelled": 0, "voucher_no": se.name},
["stock_value_difference", "stock_queue"],
as_dict=True,
)
self.assertEqual(flt(sle.stock_value_difference), 1000.00 * -1)
self.assertEqual(json.loads(sle.stock_queue), [[20, 200]])
se = make_stock_entry(
item_code=batch_item_code,
target="_Test Warehouse - _TC",
qty=10,
rate=100,
use_serial_batch_fields=True,
)
sle = frappe.db.get_value(
"Stock Ledger Entry",
{"item_code": batch_item_code, "is_cancelled": 0, "voucher_no": se.name},
["stock_value_difference", "stock_queue"],
as_dict=True,
)
self.assertEqual(flt(sle.stock_value_difference), 1000.00)
self.assertEqual(json.loads(sle.stock_queue), [[20, 200]])
se = make_stock_entry(
item_code=batch_item_code,
source="_Test Warehouse - _TC",
qty=30,
use_serial_batch_fields=False,
)
sle = frappe.db.get_value(
"Stock Ledger Entry",
{"item_code": batch_item_code, "is_cancelled": 0, "voucher_no": se.name},
["stock_value_difference", "stock_queue", "stock_value"],
as_dict=True,
)
self.assertEqual(flt(sle.stock_value_difference), 5000.00 * -1)
self.assertFalse(json.loads(sle.stock_queue or "[]"))
self.assertEqual(flt(sle.stock_value), 0.0)
def test_old_serial_no_valuation(self):
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt