From 1001b75a24564ba139bc3d6ab2a9873b419bb320 Mon Sep 17 00:00:00 2001 From: Tyler Matteson Date: Sun, 3 Jul 2022 17:00:45 -0400 Subject: [PATCH] feat: allow normal cusomtization workflow with multiple installed apps --- check_run/customize.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 check_run/customize.py diff --git a/check_run/customize.py b/check_run/customize.py new file mode 100644 index 00000000..b9f172dd --- /dev/null +++ b/check_run/customize.py @@ -0,0 +1,33 @@ +import json +from pathlib import Path + +import frappe +from frappe.custom.doctype.custom_field.custom_field import create_custom_fields +from frappe.custom.doctype.property_setter.property_setter import make_property_setter + +def load_customizations(): + customizations_directory = Path().cwd().parent / 'apps' / 'check_run' / 'check_run' / 'check_run' / 'custom' + files = list(customizations_directory.glob('**/*.json')) + for file in files: + customizations = json.loads(Path(file).read_text()) + for field in customizations.get('custom_fields'): + existing_field = frappe.get_value('Custom Field', field.get('name')) + custom_field = frappe.get_doc("Custom Field", field.get('name')) if existing_field else frappe.new_doc('Custom Field') + field.pop('modified') + {custom_field.set(key, value) for key, value in field.items()} + custom_field.flags.ignore_permissions = True + custom_field.flags.ignore_version = True + custom_field.save() + for prop in customizations.get('property_setters'): + property_setter = frappe.get_doc({ + "name": prop.get('name'), + "doctype": "Property Setter", + "doctype_or_field": prop.get('doctype_or_field'), + "doc_type": prop.get('doc_type'), + "field_name": prop.get('field_name'), + "property": prop.get('property'), + "value": prop.get('value'), + "property_type": prop.get('property_type') + }) + property_setter.flags.ignore_permissions = True + property_setter.insert()