From a4198128646fe25e85c347cee5a26a4e6c12430e Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Tue, 12 Mar 2024 14:18:39 +0530 Subject: [PATCH] fix: negative stock error for the batch (#40389) --- .../doctype/sales_order/test_sales_order.py | 40 +++++++++++++++++++ erpnext/stock/serial_batch_bundle.py | 1 + 2 files changed, 41 insertions(+) diff --git a/erpnext/selling/doctype/sales_order/test_sales_order.py b/erpnext/selling/doctype/sales_order/test_sales_order.py index b5189b8f06f..9fcda0d9a0f 100644 --- a/erpnext/selling/doctype/sales_order/test_sales_order.py +++ b/erpnext/selling/doctype/sales_order/test_sales_order.py @@ -2101,6 +2101,46 @@ class TestSalesOrder(FrappeTestCase): self.assertFalse(row.warehouse == rejected_warehouse) self.assertTrue(row.warehouse == warehouse) + def test_pick_list_for_batch(self): + from erpnext.stock.doctype.pick_list.pick_list import create_delivery_note + + batch_item = make_item( + "_Test Batch Item for Pick LIST", + properties={ + "has_batch_no": 1, + "create_new_batch": 1, + "batch_number_series": "BATCH-SDDTBIFRM-.#####", + }, + ).name + + warehouse = "_Test Warehouse - _TC" + se = make_stock_entry(item_code=batch_item, qty=10, target=warehouse, use_serial_batch_fields=1) + so = make_sales_order(item_code=batch_item, qty=10, warehouse=warehouse) + pick_list = create_pick_list(so.name) + + pick_list.save() + batch_no = frappe.get_all( + "Serial and Batch Entry", + filters={"parent": se.items[0].serial_and_batch_bundle}, + fields=["batch_no"], + )[0].batch_no + + for row in pick_list.locations: + self.assertEqual(row.qty, 10.0) + self.assertTrue(row.warehouse == warehouse) + self.assertTrue(row.batch_no == batch_no) + + pick_list.submit() + + dn = create_delivery_note(pick_list.name) + for row in dn.items: + self.assertEqual(row.qty, 10.0) + self.assertTrue(row.warehouse == warehouse) + self.assertTrue(row.batch_no == batch_no) + + dn.submit() + dn.reload() + def automatically_fetch_payment_terms(enable=1): accounts_settings = frappe.get_doc("Accounts Settings") diff --git a/erpnext/stock/serial_batch_bundle.py b/erpnext/stock/serial_batch_bundle.py index 12df0fabedb..4e87fa022d8 100644 --- a/erpnext/stock/serial_batch_bundle.py +++ b/erpnext/stock/serial_batch_bundle.py @@ -599,6 +599,7 @@ class BatchNoValuation(DeprecatedBatchNoValuation): elif self.sle.voucher_no: query = query.where(parent.voucher_no != self.sle.voucher_no) + query = query.where(parent.voucher_type != "Pick List") if timestamp_condition: query = query.where(timestamp_condition)