diff --git a/aumms/aumms/doc_events/user.py b/aumms/aumms/doc_events/user.py index df12f064..d59597a9 100644 --- a/aumms/aumms/doc_events/user.py +++ b/aumms/aumms/doc_events/user.py @@ -1,5 +1,7 @@ import frappe from frappe.utils import has_common, get_fullname +from frappe import _ +from aumms.setup import is_setup_completed, create_all_smith_warehouse def create_smith_warehouse(doc, method = None): @@ -11,6 +13,10 @@ def create_smith_warehouse(doc, method = None): # checking if the user has Smith roles or if the user is administrator user_roles = frappe.get_roles(doc.name) required_roles = ["Smith", "Head of Smith"] + + if not is_setup_completed(): + return + if not has_common(user_roles, required_roles) or doc.name == 'Administrator': return @@ -31,5 +37,15 @@ def create_smith_warehouse(doc, method = None): # creating a new warehouse new_warehouse.warehouse_name = req_warehouse_name new_warehouse.email_id = doc.name - new_warehouse.parent_warehouse = 'All smith Warehouse - EG' - new_warehouse.save() + parent_warehouse_name = frappe.db.exists("Warehouse", {'name':['like','%all Smith%'], 'is_group':1}) + + #creating the all smith warehouse if it doesn't exist in the system + if not parent_warehouse_name: + create_all_smith_warehouse() + parent_warehouse_name = frappe.db.exists("Warehouse", {'name':['like','%all Smith%'], 'is_group':1}) + + if parent_warehouse_name: + new_warehouse.parent_warehouse = parent_warehouse_name + new_warehouse.save() + else: + frappe.throw(_('All Smith Warehouse not found, Please contact System Manager'))