diff --git a/erpnext/setup/utils.py b/erpnext/setup/utils.py index 93dad165de..086235e1cb 100644 --- a/erpnext/setup/utils.py +++ b/erpnext/setup/utils.py @@ -50,6 +50,7 @@ def before_tests(): frappe.db.sql("delete from `tabItem Price`") frappe.db.set_value("Stock Settings", None, "auto_insert_price_list_rate_if_missing", 0) + enable_all_roles_and_domains() frappe.db.commit() @@ -94,3 +95,29 @@ def get_exchange_rate(from_currency, to_currency, transaction_date=None): except: frappe.msgprint(_("Unable to find exchange rate for {0} to {1} for key date {2}. Please create a Currency Exchange record manually").format(from_currency, to_currency, transaction_date)) return 0.0 + +def enable_all_roles_and_domains(): + """ enable all roles and domain for testing """ + roles = frappe.get_list("Role", filters={"disabled": 1}) + for role in roles: + _role = frappe.get_doc("Role", role.get("name")) + _role.disabled = 0 + _role.flags.ignore_mandatory = True + _role.flags.ignore_permissions = True + _role.save() + + # add all roles to users + user = frappe.get_doc("User", "test@erpnext.com") + user.add_roles(*[role.get("name") for role in roles]) + + domains = frappe.get_list("Domain") + if not domains: + return + + domain_settings = frappe.get_doc("Domain Settings", "Domain Settings") + domain_settings.set("active_domains", []) + for domain in domains: + row = domain_settings.append("active_domains", {}) + row.domain=domain.get("name") + + domain_settings.save()