2020-05-19 14:21:45 +00:00
|
|
|
import frappe
|
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2020-05-19 14:21:45 +00:00
|
|
|
def execute():
|
|
|
|
frappe.reload_doc("stock", "doctype", "material_request_item")
|
|
|
|
frappe.reload_doc("selling", "doctype", "sales_order_item")
|
|
|
|
|
|
|
|
for doctype in ["Sales Order", "Material Request"]:
|
2021-12-29 04:44:03 +00:00
|
|
|
condition = " and child_doc.stock_qty > child_doc.produced_qty and doc.per_delivered < 100"
|
2020-05-19 14:21:45 +00:00
|
|
|
if doctype == "Material Request":
|
|
|
|
condition = " and doc.per_ordered < 100 and doc.material_request_type = 'Manufacture'"
|
|
|
|
|
|
|
|
frappe.db.sql(""" UPDATE `tab{doc}` as doc, `tab{doc} Item` as child_doc, tabItem as item
|
|
|
|
SET
|
|
|
|
child_doc.bom_no = item.default_bom
|
|
|
|
WHERE
|
|
|
|
child_doc.item_code = item.name and child_doc.docstatus < 2
|
2021-12-29 04:44:03 +00:00
|
|
|
and child_doc.parent = doc.name
|
2020-05-19 14:21:45 +00:00
|
|
|
and item.default_bom is not null and item.default_bom != '' {cond}
|
|
|
|
""".format(doc = doctype, cond = condition))
|