Skip to content

Commit

Permalink
fix: batch no not copying from SO to DN for Packed Items
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure committed Sep 13, 2024
1 parent f3b91d4 commit 69b2742
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
53 changes: 53 additions & 0 deletions erpnext/stock/doctype/delivery_note/test_delivery_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 6 additions & 0 deletions erpnext/stock/doctype/packed_item/packed_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 69b2742

Please sign in to comment.