-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added script to create warehouse for smith users
- Loading branch information
Muhammed Sinan K T
committed
Oct 21, 2023
1 parent
a1909a5
commit f81c19d
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters