Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: batch /serial no not copying from SO to DN for Packed Items #43208

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 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,64 @@ 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()
dn.cancel()
so.reload()
so.cancel()

product_bundle.delete()


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
Loading