feat: ESS User
This commit is contained in:
parent
ca412d37c8
commit
03635fb0c4
@ -771,3 +771,4 @@ erpnext.patches.v12_0.add_gst_category_in_delivery_note
|
|||||||
erpnext.patches.v12_0.purchase_receipt_status
|
erpnext.patches.v12_0.purchase_receipt_status
|
||||||
erpnext.patches.v13_0.fix_non_unique_represents_company
|
erpnext.patches.v13_0.fix_non_unique_represents_company
|
||||||
erpnext.patches.v12_0.add_document_type_field_for_italy_einvoicing
|
erpnext.patches.v12_0.add_document_type_field_for_italy_einvoicing
|
||||||
|
erpnext.patches.v13_0.make_non_standard_user_type #12-03-2020
|
||||||
|
8
erpnext/patches/v13_0/make_non_standard_user_type.py
Normal file
8
erpnext/patches/v13_0/make_non_standard_user_type.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Copyright (c) 2019, Frappe and Contributors
|
||||||
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from erpnext.setup.install import add_non_standard_user_types
|
||||||
|
|
||||||
|
def execute():
|
||||||
|
add_non_standard_user_types()
|
@ -8,9 +8,11 @@ from erpnext.accounts.doctype.cash_flow_mapper.default_cash_flow_mapper import D
|
|||||||
from .default_success_action import get_default_success_action
|
from .default_success_action import get_default_success_action
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils import cint
|
from frappe.utils import cint
|
||||||
|
from frappe.installer import update_site_config
|
||||||
from frappe.desk.page.setup_wizard.setup_wizard import add_all_roles_to
|
from frappe.desk.page.setup_wizard.setup_wizard import add_all_roles_to
|
||||||
from frappe.custom.doctype.custom_field.custom_field import create_custom_field
|
from frappe.custom.doctype.custom_field.custom_field import create_custom_field
|
||||||
from erpnext.setup.default_energy_point_rules import get_default_energy_point_rules
|
from erpnext.setup.default_energy_point_rules import get_default_energy_point_rules
|
||||||
|
from six import iteritems
|
||||||
|
|
||||||
default_mail_footer = """<div style="padding: 7px; text-align: right; color: #888"><small>Sent via
|
default_mail_footer = """<div style="padding: 7px; text-align: right; color: #888"><small>Sent via
|
||||||
<a style="color: #888" href="http://erpnext.org">ERPNext</a></div>"""
|
<a style="color: #888" href="http://erpnext.org">ERPNext</a></div>"""
|
||||||
@ -29,6 +31,7 @@ def after_install():
|
|||||||
add_company_to_session_defaults()
|
add_company_to_session_defaults()
|
||||||
add_standard_navbar_items()
|
add_standard_navbar_items()
|
||||||
add_app_name()
|
add_app_name()
|
||||||
|
add_non_standard_user_types()
|
||||||
frappe.db.commit()
|
frappe.db.commit()
|
||||||
|
|
||||||
|
|
||||||
@ -164,3 +167,69 @@ def add_standard_navbar_items():
|
|||||||
|
|
||||||
def add_app_name():
|
def add_app_name():
|
||||||
frappe.db.set_value('System Settings', None, 'app_name', 'ERPNext')
|
frappe.db.set_value('System Settings', None, 'app_name', 'ERPNext')
|
||||||
|
|
||||||
|
def add_non_standard_user_types():
|
||||||
|
user_types = get_user_types_data()
|
||||||
|
|
||||||
|
user_type_limit = {}
|
||||||
|
for user_type, data in iteritems(user_types):
|
||||||
|
user_type_limit.setdefault(frappe.scrub(user_type), 10)
|
||||||
|
|
||||||
|
update_site_config('user_type_doctype_limit', user_type_limit)
|
||||||
|
|
||||||
|
for user_type, data in iteritems(user_types):
|
||||||
|
create_custom_role(data)
|
||||||
|
create_user_type(user_type, data)
|
||||||
|
|
||||||
|
def get_user_types_data():
|
||||||
|
return {
|
||||||
|
'ESS User': {
|
||||||
|
'role': 'ESS User',
|
||||||
|
'apply_user_permission_on': 'Employee',
|
||||||
|
'user_id_field': 'user_id',
|
||||||
|
'doctypes': {
|
||||||
|
'Salary Slip': ['read'],
|
||||||
|
'Employee': ['read', 'write'],
|
||||||
|
'Timesheet': ['read', 'write', 'create'],
|
||||||
|
'Expense Claim': ['read', 'write', 'create'],
|
||||||
|
'Leave Application': ['read', 'write', 'create'],
|
||||||
|
'Attendance Request': ['read', 'write', 'create'],
|
||||||
|
'Compensatory Leave Request': ['read', 'write', 'create'],
|
||||||
|
'Employee Tax Exemption Declaration': ['read', 'write', 'create'],
|
||||||
|
'Employee Tax Exemption Proof Submission': ['read', 'write', 'create'],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def create_custom_role(data):
|
||||||
|
if data.get('role') and not frappe.db.exists('Role', data.get('role')):
|
||||||
|
frappe.get_doc({
|
||||||
|
'doctype': 'Role',
|
||||||
|
'role_name': data.get('role'),
|
||||||
|
'desk_access': 1,
|
||||||
|
'is_custom': 1
|
||||||
|
}).insert(ignore_permissions=True)
|
||||||
|
|
||||||
|
def create_user_type(user_type, data):
|
||||||
|
if frappe.db.exists('User Type', user_type):
|
||||||
|
doc = frappe.get_cached_doc('User Type', user_type)
|
||||||
|
doc.user_doctypes = []
|
||||||
|
else:
|
||||||
|
doc = frappe.new_doc('User Type')
|
||||||
|
doc.update({
|
||||||
|
'name': user_type,
|
||||||
|
'role': data.get('role'),
|
||||||
|
'user_id_field': data.get('user_id_field'),
|
||||||
|
'apply_user_permission_on': data.get('apply_user_permission_on')
|
||||||
|
})
|
||||||
|
|
||||||
|
create_role_permissions_for_doctype(doc, data)
|
||||||
|
doc.save(ignore_permissions=True)
|
||||||
|
|
||||||
|
def create_role_permissions_for_doctype(doc, data):
|
||||||
|
for doctype, perms in iteritems(data.get('doctypes')):
|
||||||
|
args = {'document_type': doctype}
|
||||||
|
for perm in perms:
|
||||||
|
args[perm] = 1
|
||||||
|
|
||||||
|
doc.append('user_doctypes', args)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user