From 4dbcef3d676bb1ac290bccc2632fc2d837e36625 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Thu, 4 Sep 2025 07:18:03 +0530 Subject: [PATCH] chore: fix test case (cherry picked from commit ac8637d5a0a2c7312be1e368166d5b55e182f445) (cherry picked from commit 6bdf11f5c90d5842b2760bd635350d9d37f0258c) --- erpnext/stock/deprecated_serial_batch.py | 2 +- .../test_serial_and_batch_bundle.py | 105 ++++++++++-------- 2 files changed, 58 insertions(+), 49 deletions(-) diff --git a/erpnext/stock/deprecated_serial_batch.py b/erpnext/stock/deprecated_serial_batch.py index 19e77b3e068..d3eb178d778 100644 --- a/erpnext/stock/deprecated_serial_batch.py +++ b/erpnext/stock/deprecated_serial_batch.py @@ -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() diff --git a/erpnext/stock/doctype/serial_and_batch_bundle/test_serial_and_batch_bundle.py b/erpnext/stock/doctype/serial_and_batch_bundle/test_serial_and_batch_bundle.py index 5fdc3d56ebd..4ae2b3ce4b5 100644 --- a/erpnext/stock/doctype/serial_and_batch_bundle/test_serial_and_batch_bundle.py +++ b/erpnext/stock/doctype/serial_and_batch_bundle/test_serial_and_batch_bundle.py @@ -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