diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index 2b60dcd214..1b66c65dac 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -102,7 +102,6 @@ class SalesOrder(SellingController): self.validate_warehouse() from erpnext.stock.doctype.packed_item.packed_item import make_packing_list - make_packing_list(self,'sales_order_details') self.validate_with_previous_doc() diff --git a/erpnext/stock/doctype/packed_item/packed_item.py b/erpnext/stock/doctype/packed_item/packed_item.py index cf208ee87d..44c1a00cc9 100644 --- a/erpnext/stock/doctype/packed_item/packed_item.py +++ b/erpnext/stock/doctype/packed_item/packed_item.py @@ -12,18 +12,18 @@ from frappe.model.document import Document class PackedItem(Document): pass - + def get_sales_bom_items(item_code): - return frappe.db.sql("""select t1.item_code, t1.qty, t1.uom - from `tabSales BOM Item` t1, `tabSales BOM` t2 + return frappe.db.sql("""select t1.item_code, t1.qty, t1.uom + from `tabSales BOM Item` t1, `tabSales BOM` t2 where t2.new_item_code=%s and t1.parent = t2.name""", item_code, as_dict=1) def get_packing_item_details(item): - return frappe.db.sql("""select item_name, description, stock_uom from `tabItem` + return frappe.db.sql("""select item_name, description, stock_uom from `tabItem` where name = %s""", item, as_dict = 1)[0] def get_bin_qty(item, warehouse): - det = frappe.db.sql("""select actual_qty, projected_qty from `tabBin` + det = frappe.db.sql("""select actual_qty, projected_qty from `tabBin` where item_code = %s and warehouse = %s""", (item, warehouse), as_dict = 1) return det and det[0] or '' @@ -55,12 +55,15 @@ def update_packing_list_item(obj, packing_item_code, qty, warehouse, line, packi if not pi.batch_no: pi.batch_no = cstr(line.get("batch_no")) pi.idx = packing_list_idx - + packing_list_idx += 1 def make_packing_list(obj, item_table_fieldname): """make packing list for sales bom item""" + + if obj._action == "update_after_submit": return + packing_list_idx = 0 parent_items = [] for d in obj.get(item_table_fieldname): @@ -68,14 +71,14 @@ def make_packing_list(obj, item_table_fieldname): and d.warehouse or d.warehouse if frappe.db.get_value("Sales BOM", {"new_item_code": d.item_code}): for i in get_sales_bom_items(d.item_code): - update_packing_list_item(obj, i['item_code'], flt(i['qty'])*flt(d.qty), + update_packing_list_item(obj, i['item_code'], flt(i['qty'])*flt(d.qty), warehouse, d, packing_list_idx) if [d.item_code, d.name] not in parent_items: parent_items.append([d.item_code, d.name]) - + cleanup_packing_list(obj, parent_items) - + def cleanup_packing_list(obj, parent_items): """Remove all those child items which are no longer present in main item table""" delete_list = [] @@ -86,10 +89,9 @@ def cleanup_packing_list(obj, parent_items): if not delete_list: return obj - + packing_details = obj.get("packing_details") obj.set("packing_details", []) for d in packing_details: if d not in delete_list: obj.append("packing_details", d) - \ No newline at end of file