def add_bom_level(doc, qty, bom):
# Get the BOM doc
#frappe.msgprint("Getting BOM for" + bom)
bom_doc = frappe.get_doc("BOM",bom)
#Add the operations from this BOM to the list
new_operation = get_bom_operation(bom, qty)
new_operation.idx = len(doc.operations)+1
doc.operations.append(new_operation)
#Go through each item in the BOM to decide if it is a Purchased or Manufactured item
for myItem in bom_doc.items:
item_quantity = qty * myItem.qty
item_doc = frappe.get_doc("Item",myItem.item_code)
if myItem.bom_no and item_doc.default_material_request_type == "Manufacture":
# This is a manufactured item and we should add it to the BOM Operations then scan it's children
add_bom_level(doc,item_quantity, myItem.bom_no)
else:
# Consider it a purchased item, and just set the basics (Item Code, Qty, Supplier, Currency, Price List)
#frappe.msgprint("Getting BOM for" + bom)
new_purchased = get_purchase_item(myItem.item_code, item_quantity)
new_purchased.idx = len(doc.items)+1
bisect.insort_left(doc.items,new_purchased)
评论列表
文章目录