Do not make packing list after submission

This commit is contained in:
Nabin Hait 2014-06-17 16:13:15 +05:30
parent 69641ddc36
commit b73d3f925d
2 changed files with 13 additions and 12 deletions

View File

@ -102,7 +102,6 @@ class SalesOrder(SellingController):
self.validate_warehouse() self.validate_warehouse()
from erpnext.stock.doctype.packed_item.packed_item import make_packing_list from erpnext.stock.doctype.packed_item.packed_item import make_packing_list
make_packing_list(self,'sales_order_details') make_packing_list(self,'sales_order_details')
self.validate_with_previous_doc() self.validate_with_previous_doc()

View File

@ -12,18 +12,18 @@ from frappe.model.document import Document
class PackedItem(Document): class PackedItem(Document):
pass pass
def get_sales_bom_items(item_code): def get_sales_bom_items(item_code):
return frappe.db.sql("""select t1.item_code, t1.qty, t1.uom return frappe.db.sql("""select t1.item_code, t1.qty, t1.uom
from `tabSales BOM Item` t1, `tabSales BOM` t2 from `tabSales BOM Item` t1, `tabSales BOM` t2
where t2.new_item_code=%s and t1.parent = t2.name""", item_code, as_dict=1) where t2.new_item_code=%s and t1.parent = t2.name""", item_code, as_dict=1)
def get_packing_item_details(item): 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] where name = %s""", item, as_dict = 1)[0]
def get_bin_qty(item, warehouse): 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) where item_code = %s and warehouse = %s""", (item, warehouse), as_dict = 1)
return det and det[0] or '' 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: if not pi.batch_no:
pi.batch_no = cstr(line.get("batch_no")) pi.batch_no = cstr(line.get("batch_no"))
pi.idx = packing_list_idx pi.idx = packing_list_idx
packing_list_idx += 1 packing_list_idx += 1
def make_packing_list(obj, item_table_fieldname): def make_packing_list(obj, item_table_fieldname):
"""make packing list for sales bom item""" """make packing list for sales bom item"""
if obj._action == "update_after_submit": return
packing_list_idx = 0 packing_list_idx = 0
parent_items = [] parent_items = []
for d in obj.get(item_table_fieldname): 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 and d.warehouse or d.warehouse
if frappe.db.get_value("Sales BOM", {"new_item_code": d.item_code}): if frappe.db.get_value("Sales BOM", {"new_item_code": d.item_code}):
for i in get_sales_bom_items(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) warehouse, d, packing_list_idx)
if [d.item_code, d.name] not in parent_items: if [d.item_code, d.name] not in parent_items:
parent_items.append([d.item_code, d.name]) parent_items.append([d.item_code, d.name])
cleanup_packing_list(obj, parent_items) cleanup_packing_list(obj, parent_items)
def 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""" """Remove all those child items which are no longer present in main item table"""
delete_list = [] delete_list = []
@ -86,10 +89,9 @@ def cleanup_packing_list(obj, parent_items):
if not delete_list: if not delete_list:
return obj return obj
packing_details = obj.get("packing_details") packing_details = obj.get("packing_details")
obj.set("packing_details", []) obj.set("packing_details", [])
for d in packing_details: for d in packing_details:
if d not in delete_list: if d not in delete_list:
obj.append("packing_details", d) obj.append("packing_details", d)