diff --git a/frappe/modules/utils.py b/frappe/modules/utils.py index 0703a064d3..ab914eff96 100644 --- a/frappe/modules/utils.py +++ b/frappe/modules/utils.py @@ -83,12 +83,10 @@ def sync_customizations(app=None): for app_name in apps: for module_name in frappe.local.app_modules.get(app_name) or []: folder = frappe.get_app_path(app_name, module_name, 'custom') - if os.path.exists(folder): for fname in os.listdir(folder): with open(os.path.join(folder, fname), 'r') as f: data = json.loads(f.read()) - if data.get('sync_on_migrate'): sync_customizations_for_doctype(data, folder) @@ -105,14 +103,31 @@ def sync_customizations_for_doctype(data, folder): # sync single doctype exculding the child doctype def sync_single_doctype(doc_type): - frappe.db.sql('delete from `tab{0}` where `{1}` =%s'.format( - custom_doctype, doctype_fieldname), doc_type) - for d in data[key]: - if d.get(doctype_fieldname) == doc_type: - d['doctype'] = custom_doctype - doc = frappe.get_doc(d) + def _insert(data): + if data.get(doctype_fieldname) == doc_type: + data['doctype'] = custom_doctype + doc = frappe.get_doc(data) doc.db_insert() + if custom_doctype != 'Custom Field': + frappe.db.sql('delete from `tab{0}` where `{1}` =%s'.format( + custom_doctype, doctype_fieldname), doc_type) + + for d in data[key]: + _insert(data, key) + + else: + for d in data[key]: + field = frappe.db.get_value("Custom Field", {"dt": doc_type, "fieldname": d["fieldname"]}) + if not field: + d["owner"] = "Administrator" + _insert(d) + else: + custom_field = frappe.get_doc("Custom Field", field) + custom_field.flags.ignore_validate = True + custom_field.update(d) + custom_field.db_update() + for doc_type in doctypes: # only sync the parent doctype and child doctype if there isn't any other child table json file if doc_type == doctype or not os.path.exists(os.path.join(folder, frappe.scrub(doc_type)+".json")):