From 0fa78198109910d2a3e9e9f55b0dd646fc6f07b7 Mon Sep 17 00:00:00 2001 From: Muhammed Sinan K T Date: Fri, 3 Nov 2023 12:29:05 +0530 Subject: [PATCH 1/2] fix: capitalization in warehouse name --- aumms/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aumms/setup.py b/aumms/setup.py index a77b6d0f..d381ecdd 100644 --- a/aumms/setup.py +++ b/aumms/setup.py @@ -58,7 +58,7 @@ def create_all_smith_warehouse(): if not frappe.db.exists('Warehouse', {'warehouse_name': 'All Smith Warehouse'}): warehouse_doc = frappe.new_doc('Warehouse') warehouse_doc.company = default_company - warehouse_doc.warehouse_name = 'All smith Warehouse' + warehouse_doc.warehouse_name = 'All Smith Warehouse' warehouse_doc.parent_warehouse = warehouse warehouse_doc.is_group = 1 warehouse_doc.insert(ignore_permissions = True) From 8ede40fce8c5fe9a8aad33e03ae3299e8a53678b Mon Sep 17 00:00:00 2001 From: Muhammed Sinan K T Date: Fri, 3 Nov 2023 12:29:14 +0530 Subject: [PATCH 2/2] fix: warehouse name to be fetched instead of hardcoded --- aumms/aumms/doc_events/user.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) 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'))