From cba9c716f21ee88e608bbffc542c22c74f66fedf Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 21 May 2012 15:35:23 +0530 Subject: [PATCH] Remove all those parent items from packing details which are no longer present in main item table --- erpnext/selling/doctype/sales_common/sales_common.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/erpnext/selling/doctype/sales_common/sales_common.py b/erpnext/selling/doctype/sales_common/sales_common.py index 0a038b12fb..4817bdc473 100644 --- a/erpnext/selling/doctype/sales_common/sales_common.py +++ b/erpnext/selling/doctype/sales_common/sales_common.py @@ -432,6 +432,7 @@ class DocType(TransactionBase): # ------------------ def make_packing_list(self, obj, fname): self.packing_list_idx = 0 + parent_items = [] for d in getlist(obj.doclist, fname): warehouse = fname == "sales_order_details" and d.reserved_warehouse or d.warehouse if self.has_sales_bom(d.item_code): @@ -439,6 +440,16 @@ class DocType(TransactionBase): self.update_packing_list_item(obj, i['item_code'], flt(i['qty'])*flt(d.qty), warehouse, d) else: self.update_packing_list_item(obj, d.item_code, d.qty, warehouse, d) + if d.item_code not in parent_items: + parent_items.append(d.item_code) + + self.cleanup_packing_list(obj, parent_items) + + def cleanup_packing_list(self, obj, parent_items): + """Remove all those parent items which are no longer present in main item table""" + for d in getlist(obj.doclist, 'packing_details'): + if d.parent_item not in parent_items: + d.parent = '' # Get total in words