Skip to content

Commit

Permalink
feat: added script to create warehouse for smith users
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammed Sinan K T committed Oct 21, 2023
1 parent a1909a5 commit f81c19d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
35 changes: 35 additions & 0 deletions aumms/aumms/doc_events/user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import frappe
from frappe.utils import has_common, get_fullname


def create_smith_warehouse(doc, method = None):
"""
method to create personal warehouse for a smith user
args:
doc (class object): object of User
"""
# 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 has_common(user_roles, required_roles) or doc.name == 'Administrator':
return

# generating the warehouse name
user_fullname = get_fullname(doc.name)
new_warehouse = frappe.new_doc("Warehouse")
req_warehouse_name = f"{user_fullname} - Smith"

# checking if the warehouse already exist
warehouse = frappe.db.exists("Warehouse", {"email_id": doc.name, 'parent_warehouse':'All smith Warehouse - EG'})
if warehouse:
warehouse_doc = frappe.get_doc("Warehouse", warehouse)
# renaming the warehouse if the user's full name was changed
if not warehouse_doc.warehouse_name == req_warehouse_name:
warehouse_doc.warehouse_name = req_warehouse_name
warehouse_doc.save()
else:
# 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()
3 changes: 3 additions & 0 deletions aumms/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@
},
'Payment Entry':{
'on_submit': 'aumms.aumms.doc_events.payment_entry.payment_entry_on_submit'
},
'User':{
'on_update': 'aumms.aumms.doc_events.user.create_smith_warehouse'
}
}

Expand Down

0 comments on commit f81c19d

Please sign in to comment.