From effe13925e50798b8c10010f6f7106ec0ff7d779 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 14 Nov 2017 13:36:35 +0530 Subject: [PATCH] [hot] revert domain_settings patch --- frappe/core/doctype/domain/domain.py | 22 +++++++++++++++++++ frappe/patches.txt | 3 ++- frappe/patches/v9_1/revert_domain_settings.py | 10 +++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 frappe/patches/v9_1/revert_domain_settings.py diff --git a/frappe/core/doctype/domain/domain.py b/frappe/core/doctype/domain/domain.py index fed9f2360d..890ef87af6 100644 --- a/frappe/core/doctype/domain/domain.py +++ b/frappe/core/doctype/domain/domain.py @@ -31,6 +31,28 @@ class Domain(Document): # custom on_setup method frappe.get_attr(self.data.on_setup)() + def remove_domain(self): + '''Unset domain settings''' + self.setup_data() + for role_name in self.data.restricted_roles: + if frappe.db.exists('Role', role_name): + role = frappe.get_doc('Role', role_name) + role.disabled = 1 + role.save() + + if self.data.custom_fields: + for doctype in self.data.custom_fields: + custom_fields = self.data.custom_fields[doctype] + + # custom_fields can be a list or dict + if isinstance(custom_fields, dict): + custom_fields = [custom_fields] + + for custom_field_detail in custom_fields: + custom_field = frappe.get_doc('Custom Field', + dict(dt=doctype, fieldname=custom_field_detail.get('fieldname'))) + custom_field.delete() + def setup_roles(self): '''Enable roles that are restricted to this domain''' diff --git a/frappe/patches.txt b/frappe/patches.txt index 6b5bcd8c7b..a127ab73ca 100644 --- a/frappe/patches.txt +++ b/frappe/patches.txt @@ -196,4 +196,5 @@ frappe.patches.v8_5.patch_event_colors frappe.patches.v8_10.delete_static_web_page_from_global_search frappe.patches.v8_x.add_bgn_xaf_xof_currencies frappe.patches.v9_1.add_sms_sender_name_as_parameters -frappe.patches.v9_1.resave_domain_settings \ No newline at end of file +frappe.patches.v9_1.resave_domain_settings +frappe.patches.v9_1.revert_domain_settings \ No newline at end of file diff --git a/frappe/patches/v9_1/revert_domain_settings.py b/frappe/patches/v9_1/revert_domain_settings.py new file mode 100644 index 0000000000..a2202986fd --- /dev/null +++ b/frappe/patches/v9_1/revert_domain_settings.py @@ -0,0 +1,10 @@ +import frappe + +def execute(): + domain_settings = frappe.get_doc('Domain Settings') + active_domains = [d.domain for d in domain_settings.active_domains] + + for domain_name in ('Education', 'Healthcare', 'Hospitality'): + if domain_name not in active_domains: + domain = frappe.get_doc('Domain', domain_name) + domain.remove_domain() \ No newline at end of file