From 69b2742666f48459f72d3d4e244770cf935814ff Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 13 Sep 2024 13:21:16 +0530 Subject: [PATCH] fix: batch no not copying from SO to DN for Packed Items --- .../delivery_note/test_delivery_note.py | 53 +++++++++++++++++++ .../stock/doctype/packed_item/packed_item.py | 6 +++ 2 files changed, 59 insertions(+) diff --git a/erpnext/stock/doctype/delivery_note/test_delivery_note.py b/erpnext/stock/doctype/delivery_note/test_delivery_note.py index 73b77f67536f..d80531b820cd 100644 --- a/erpnext/stock/doctype/delivery_note/test_delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/test_delivery_note.py @@ -2066,6 +2066,59 @@ def test_warranty_expiry_date_for_serial_item(self): self.assertEqual(sn.status, "Delivered") self.assertEqual(sn.warranty_period, 100) + def test_packed_items_batch_serial_nos(self): + service_item = make_item("Test Service Item 123", {"is_stock_item": 0}) + serial_item = make_item( + "Test Serial Item 123", + {"is_stock_item": 1, "has_serial_no": 1, "serial_no_series": "SN24-TSI123.#####"}, + ) + + batch_item = make_item( + "Test Batch Item 123", + { + "is_stock_item": 1, + "has_batch_no": 1, + "batch_number_series": "BN24-TBI123.#####", + "create_new_batch": 1, + }, + ) + + product_bundle = make_product_bundle( + parent=service_item.name, items=[serial_item.name, batch_item.name], qty=1 + ) + + item_details = frappe._dict() + for row in product_bundle.items: + se = make_stock_entry( + item_code=row.item_code, + target="_Test Warehouse - _TC", + qty=1, + basic_rate=100, + ) + + if row.item_code == serial_item.name: + item_details[row.item_code] = get_serial_nos_from_bundle(se.items[0].serial_and_batch_bundle) + else: + item_details[row.item_code] = get_batch_from_bundle(se.items[0].serial_and_batch_bundle) + + so = make_sales_order(item_code=service_item.name, qty=1, do_not_submit=True) + for row in so.packed_items: + row.use_serial_batch_fields = 1 + + if row.item_code == serial_item.name: + row.serial_no = item_details[serial_item.name][0] + else: + row.batch_no = item_details[batch_item.name] + + so.submit() + dn = create_dn_against_so(so.name, 1, do_not_submit=True) + dn.save() + + for row in dn.packed_items: + self.assertTrue(row.serial_no or row.batch_no) + + dn.submit() + def create_delivery_note(**args): dn = frappe.new_doc("Delivery Note") diff --git a/erpnext/stock/doctype/packed_item/packed_item.py b/erpnext/stock/doctype/packed_item/packed_item.py index 081d9c59ddfc..a386615c47ca 100644 --- a/erpnext/stock/doctype/packed_item/packed_item.py +++ b/erpnext/stock/doctype/packed_item/packed_item.py @@ -112,6 +112,9 @@ def get_indexed_packed_items_table(doc): indexed_table = {} for packed_item in doc.get("packed_items"): key = (packed_item.parent_item, packed_item.item_code, packed_item.parent_detail_docname) + if doc.is_new(): + key = (packed_item.parent_item, packed_item.item_code) + indexed_table[key] = packed_item return indexed_table @@ -173,6 +176,9 @@ def add_packed_item_row(doc, packing_item, main_item_row, packed_items_table, re # check if row already exists in packed items table key = (main_item_row.item_code, packing_item.item_code, main_item_row.name) + if doc.is_new(): + key = (main_item_row.item_code, packing_item.item_code) + if packed_items_table.get(key): pi_row, exists = packed_items_table.get(key), True