Skip to content

Commit

Permalink
fix: warehouse name to be fetched instead of hardcoded
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammed Sinan K T committed Nov 3, 2023
1 parent 0fa7819 commit 8ede40f
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions aumms/aumms/doc_events/user.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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

Expand All @@ -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'))

0 comments on commit 8ede40f

Please sign in to comment.