Skip to content

Commit

Permalink
Merge pull request #169 from efeone/03122023s001
Browse files Browse the repository at this point in the history
fix: smith warehouse will be created only after setup, warehouse name to be fetched instead of being hardcoded
  • Loading branch information
muhammadmp authored Nov 3, 2023
2 parents a320d56 + 8ede40f commit d75206f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 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'))
2 changes: 1 addition & 1 deletion aumms/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d75206f

Please sign in to comment.