diff --git a/aumms/aumms/doc_events/user.py b/aumms/aumms/doc_events/user.py new file mode 100644 index 00000000..df12f064 --- /dev/null +++ b/aumms/aumms/doc_events/user.py @@ -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() diff --git a/aumms/aumms/doctype/smith_details/__init__.py b/aumms/aumms/doctype/smith/__init__.py similarity index 100% rename from aumms/aumms/doctype/smith_details/__init__.py rename to aumms/aumms/doctype/smith/__init__.py diff --git a/aumms/aumms/doctype/smith_details/smith_details.js b/aumms/aumms/doctype/smith/smith.js similarity index 61% rename from aumms/aumms/doctype/smith_details/smith_details.js rename to aumms/aumms/doctype/smith/smith.js index 539e786f..96aa1bb3 100644 --- a/aumms/aumms/doctype/smith_details/smith_details.js +++ b/aumms/aumms/doctype/smith/smith.js @@ -1,6 +1,8 @@ // Copyright (c) 2023, efeone and contributors // For license information, please see license.txt -frappe.ui.form.on('Smith Details', { +frappe.ui.form.on('Smith', { + // refresh: function(frm) { + // } }); diff --git a/aumms/aumms/doctype/smith_details/smith_details.json b/aumms/aumms/doctype/smith/smith.json similarity index 95% rename from aumms/aumms/doctype/smith_details/smith_details.json rename to aumms/aumms/doctype/smith/smith.json index 0d322dfa..973994bb 100644 --- a/aumms/aumms/doctype/smith_details/smith_details.json +++ b/aumms/aumms/doctype/smith/smith.json @@ -2,7 +2,7 @@ "actions": [], "allow_rename": 1, "autoname": "format:S{######}", - "creation": "2023-10-18 10:02:01.800347", + "creation": "2023-10-24 09:54:51.116100", "default_view": "List", "doctype": "DocType", "editable_grid": 1, @@ -28,22 +28,37 @@ "options": "\nInternal\nExternal" }, { - "fieldname": "department", + "depends_on": "eval:doc.smith_type == 'Internal'", + "fieldname": "employee", "fieldtype": "Link", - "label": "Department", - "options": "Department" + "label": "Employee", + "options": "Employee" }, { - "fieldname": "hourly_rate", + "depends_on": "eval:doc.smith_type == 'External'", + "fieldname": "supplier", + "fieldtype": "Link", + "label": "Supplier", + "options": "Supplier" + }, + { + "depends_on": "eval:doc.smith_type == 'External'", + "fetch_from": "supplier.supplier_name", + "fieldname": "supplier_name", "fieldtype": "Data", - "label": "Hourly Rate" + "label": "Supplier Name" }, { - "fetch_from": "department.head_of_department", - "fieldname": "head_of_smith", - "fieldtype": "Link", - "label": "Head of smith", - "options": "Employee" + "depends_on": "eval:doc.smith_type =='Internal'", + "fetch_from": "employee.employee_name", + "fieldname": "employee_name", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Employee Name" + }, + { + "fieldname": "column_break_mhz6m", + "fieldtype": "Column Break" }, { "fieldname": "warehouse", @@ -52,49 +67,34 @@ "options": "Warehouse" }, { - "depends_on": "eval:doc.smith_type == 'External'", - "fieldname": "supplier", + "fieldname": "department", "fieldtype": "Link", - "label": "Supplier", - "options": "Supplier" + "label": "Department", + "options": "Department" }, { - "depends_on": "eval:doc.smith_type == 'Internal'", - "fieldname": "employee", + "fetch_from": "department.head_of_department", + "fieldname": "head_of_smith", "fieldtype": "Link", - "label": "Employee", + "label": "Head of smith", "options": "Employee" }, - { - "fieldname": "column_break_mhz6m", - "fieldtype": "Column Break" - }, { "fieldname": "section_break_9mmii", "fieldtype": "Section Break" }, { - "depends_on": "eval:doc.smith_type == 'External'", - "fetch_from": "supplier.supplier_name", - "fieldname": "supplier_name", - "fieldtype": "Data", - "label": "Supplier Name" - }, - { - "depends_on": "eval:doc.smith_type =='Internal'", - "fetch_from": "employee.employee_name", - "fieldname": "employee_name", + "fieldname": "hourly_rate", "fieldtype": "Data", - "in_list_view": 1, - "label": "Employee Name" + "label": "Hourly Rate" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-10-20 16:01:00.222753", + "modified": "2023-10-24 09:54:51.116100", "modified_by": "Administrator", "module": "AuMMS", - "name": "Smith Details", + "name": "Smith", "naming_rule": "Expression", "owner": "Administrator", "permissions": [ diff --git a/aumms/aumms/doctype/smith_details/smith_details.py b/aumms/aumms/doctype/smith/smith.py similarity index 75% rename from aumms/aumms/doctype/smith_details/smith_details.py rename to aumms/aumms/doctype/smith/smith.py index 0d86a073..5ead3ab7 100644 --- a/aumms/aumms/doctype/smith_details/smith_details.py +++ b/aumms/aumms/doctype/smith/smith.py @@ -1,8 +1,8 @@ # Copyright (c) 2023, efeone and contributors # For license information, please see license.txt +# import frappe from frappe.model.document import Document - -class SmithDetails(Document): - pass \ No newline at end of file +class Smith(Document): + pass diff --git a/aumms/aumms/doctype/smith_details/test_smith_details.py b/aumms/aumms/doctype/smith/test_smith.py similarity index 77% rename from aumms/aumms/doctype/smith_details/test_smith_details.py rename to aumms/aumms/doctype/smith/test_smith.py index 8579315c..7e4577c0 100644 --- a/aumms/aumms/doctype/smith_details/test_smith_details.py +++ b/aumms/aumms/doctype/smith/test_smith.py @@ -5,5 +5,5 @@ from frappe.tests.utils import FrappeTestCase -class TestSmithDetails(FrappeTestCase): +class TestSmith(FrappeTestCase): pass diff --git a/aumms/hooks.py b/aumms/hooks.py index 46828b55..a90c494d 100644 --- a/aumms/hooks.py +++ b/aumms/hooks.py @@ -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' } }