brotherton-erpnext/erpnext/patches/v11_0/make_quality_inspection_template.py
2022-03-28 18:52:46 +05:30

35 lines
1.1 KiB
Python

# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
import frappe
def execute():
frappe.reload_doc("stock", "doctype", "quality_inspection_template")
frappe.reload_doc("stock", "doctype", "item")
for data in frappe.get_all(
"Item Quality Inspection Parameter", fields=["distinct parent"], filters={"parenttype": "Item"}
):
qc_doc = frappe.new_doc("Quality Inspection Template")
qc_doc.quality_inspection_template_name = "QIT/%s" % data.parent
qc_doc.flags.ignore_mandatory = True
qc_doc.save(ignore_permissions=True)
frappe.db.set_value(
"Item", data.parent, "quality_inspection_template", qc_doc.name, update_modified=False
)
frappe.db.sql(
""" update `tabItem Quality Inspection Parameter`
set parentfield = 'item_quality_inspection_parameter', parenttype = 'Quality Inspection Template',
parent = %s where parenttype = 'Item' and parent = %s""",
(qc_doc.name, data.parent),
)
# update field in item variant settings
frappe.db.sql(
""" update `tabVariant Field` set field_name = 'quality_inspection_template'
where field_name = 'quality_parameters'"""
)