Skip to content

Commit

Permalink
feat: Created doctype Smith
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadmp authored and G-eethu committed Oct 24, 2023
2 parents a1909a5 + f81c19d commit 46f3c91
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 41 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()
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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) {

// }
});
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand All @@ -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": [
Expand Down
Original file line number Diff line number Diff line change
@@ -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
class Smith(Document):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
from frappe.tests.utils import FrappeTestCase


class TestSmithDetails(FrappeTestCase):
class TestSmith(FrappeTestCase):
pass
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 46f3c91

Please sign in to comment.