brotherton-erpnext/erpnext/patches/v12_0/update_bom_in_so_mr.py
Chillar Anand 915b34391c
chore: Clean up imports (#27302)
* chore: Added isort to pre-commit config

* chore: Sort imports with isort

* chore: Clean up imports with pycln

* chore: Sort imports with isort

* chore: Fix import issues

* chore: Clean up sider issues

* chore: Remove import errors from flake8 ignore list

* chore: Clean up lint issues
2021-09-02 16:44:59 +05:30

22 lines
774 B
Python

from __future__ import unicode_literals
import frappe
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"]:
condition = " and child_doc.stock_qty > child_doc.produced_qty"
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
and item.default_bom is not null and item.default_bom != '' {cond}
""".format(doc = doctype, cond = condition))