From 214815eb626d6e4e4cc93f6f36c97a63a8f95aa9 Mon Sep 17 00:00:00 2001 From: sahil28297 <37302950+sahil28297@users.noreply.github.com> Date: Mon, 12 Aug 2019 11:49:21 +0530 Subject: [PATCH] fix(patch): force reload child docs (#18672) --- .../v12_0/update_pricing_rule_fields.py | 94 +++++++++---------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/erpnext/patches/v12_0/update_pricing_rule_fields.py b/erpnext/patches/v12_0/update_pricing_rule_fields.py index 8f8349e9b5..985613a973 100644 --- a/erpnext/patches/v12_0/update_pricing_rule_fields.py +++ b/erpnext/patches/v12_0/update_pricing_rule_fields.py @@ -5,67 +5,67 @@ from __future__ import unicode_literals import frappe parentfield = { - 'item_code': 'items', - 'item_group': 'item_groups', - 'brand': 'brands' + 'item_code': 'items', + 'item_group': 'item_groups', + 'brand': 'brands' } def execute(): - if not frappe.get_all('Pricing Rule', limit=1): - return + if not frappe.get_all('Pricing Rule', limit=1): + return - frappe.reload_doc('accounts', 'doctype', 'pricing_rule_detail') - doctypes = {'Supplier Quotation': 'buying', 'Purchase Order': 'buying', 'Purchase Invoice': 'accounts', - 'Purchase Receipt': 'stock', 'Quotation': 'selling', 'Sales Order': 'selling', - 'Sales Invoice': 'accounts', 'Delivery Note': 'stock'} + frappe.reload_doc('accounts', 'doctype', 'pricing_rule_detail') + doctypes = {'Supplier Quotation': 'buying', 'Purchase Order': 'buying', 'Purchase Invoice': 'accounts', + 'Purchase Receipt': 'stock', 'Quotation': 'selling', 'Sales Order': 'selling', + 'Sales Invoice': 'accounts', 'Delivery Note': 'stock'} - for doctype, module in doctypes.items(): - frappe.reload_doc(module, 'doctype', frappe.scrub(doctype)) + for doctype, module in doctypes.items(): + frappe.reload_doc(module, 'doctype', frappe.scrub(doctype)) - child_doc = frappe.scrub(doctype) + '_item' - frappe.reload_doc(module, 'doctype', child_doc) + child_doc = frappe.scrub(doctype) + '_item' + frappe.reload_doc(module, 'doctype', child_doc, force=True) - child_doctype = doctype + ' Item' + child_doctype = doctype + ' Item' - frappe.db.sql(""" UPDATE `tab{child_doctype}` SET pricing_rules = pricing_rule - WHERE docstatus < 2 and pricing_rule is not null and pricing_rule != '' - """.format(child_doctype= child_doctype)) + frappe.db.sql(""" UPDATE `tab{child_doctype}` SET pricing_rules = pricing_rule + WHERE docstatus < 2 and pricing_rule is not null and pricing_rule != '' + """.format(child_doctype= child_doctype)) - data = frappe.db.sql(""" SELECT pricing_rule, name, parent, - parenttype, creation, modified, docstatus, modified_by, owner, name - FROM `tab{child_doc}` where docstatus < 2 and pricing_rule is not null - and pricing_rule != ''""".format(child_doc=child_doctype), as_dict=1) + data = frappe.db.sql(""" SELECT pricing_rule, name, parent, + parenttype, creation, modified, docstatus, modified_by, owner, name + FROM `tab{child_doc}` where docstatus < 2 and pricing_rule is not null + and pricing_rule != ''""".format(child_doc=child_doctype), as_dict=1) - values = [] - for d in data: - values.append((d.pricing_rule, d.name, d.parent, 'pricing_rules', d.parenttype, - d.creation, d.modified, d.docstatus, d.modified_by, d.owner, frappe.generate_hash("", 10))) + values = [] + for d in data: + values.append((d.pricing_rule, d.name, d.parent, 'pricing_rules', d.parenttype, + d.creation, d.modified, d.docstatus, d.modified_by, d.owner, frappe.generate_hash("", 10))) - if values: - frappe.db.sql(""" INSERT INTO - `tabPricing Rule Detail` (`pricing_rule`, `child_docname`, `parent`, `parentfield`, `parenttype`, - `creation`, `modified`, `docstatus`, `modified_by`, `owner`, `name`) - VALUES {values} """.format(values=', '.join(['%s'] * len(values))), tuple(values)) + if values: + frappe.db.sql(""" INSERT INTO + `tabPricing Rule Detail` (`pricing_rule`, `child_docname`, `parent`, `parentfield`, `parenttype`, + `creation`, `modified`, `docstatus`, `modified_by`, `owner`, `name`) + VALUES {values} """.format(values=', '.join(['%s'] * len(values))), tuple(values)) - frappe.reload_doc('accounts', 'doctype', 'pricing_rule') + frappe.reload_doc('accounts', 'doctype', 'pricing_rule') - for doctype, apply_on in {'Pricing Rule Item Code': 'Item Code', - 'Pricing Rule Item Group': 'Item Group', 'Pricing Rule Brand': 'Brand'}.items(): - frappe.reload_doc('accounts', 'doctype', frappe.scrub(doctype)) + for doctype, apply_on in {'Pricing Rule Item Code': 'Item Code', + 'Pricing Rule Item Group': 'Item Group', 'Pricing Rule Brand': 'Brand'}.items(): + frappe.reload_doc('accounts', 'doctype', frappe.scrub(doctype)) - field = frappe.scrub(apply_on) - data = frappe.get_all('Pricing Rule', fields=[field, "name", "creation", "modified", - "owner", "modified_by"], filters= {'apply_on': apply_on}) + field = frappe.scrub(apply_on) + data = frappe.get_all('Pricing Rule', fields=[field, "name", "creation", "modified", + "owner", "modified_by"], filters= {'apply_on': apply_on}) - values = [] - for d in data: - values.append((d.get(field), d.name, parentfield.get(field), 'Pricing Rule', - d.creation, d.modified, d.owner, d.modified_by, frappe.generate_hash("", 10))) + values = [] + for d in data: + values.append((d.get(field), d.name, parentfield.get(field), 'Pricing Rule', + d.creation, d.modified, d.owner, d.modified_by, frappe.generate_hash("", 10))) - if values: - frappe.db.sql(""" INSERT INTO - `tab{doctype}` ({field}, parent, parentfield, parenttype, creation, modified, - owner, modified_by, name) - VALUES {values} """.format(doctype=doctype, - field=field, values=', '.join(['%s'] * len(values))), tuple(values)) \ No newline at end of file + if values: + frappe.db.sql(""" INSERT INTO + `tab{doctype}` ({field}, parent, parentfield, parenttype, creation, modified, + owner, modified_by, name) + VALUES {values} """.format(doctype=doctype, + field=field, values=', '.join(['%s'] * len(values))), tuple(values))