Set user permissions for new departments based on company

This commit is contained in:
Nabin Hait 2018-06-29 14:36:28 +05:30
parent c114ceb67d
commit 6e86fb2540
3 changed files with 52 additions and 1 deletions

View File

@ -143,6 +143,38 @@
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "disabled",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Disabled",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
@ -447,7 +479,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2018-06-13 15:50:04.611365",
"modified": "2018-06-29 14:24:32.774721",
"modified_by": "Administrator",
"module": "HR",
"name": "Department",

View File

@ -551,3 +551,5 @@ erpnext.patches.v11_0.update_total_qty_field
erpnext.patches.v11_0.update_sales_partner_type
erpnext.patches.v11_0.rename_asset_adjustment_doctype
execute:frappe.db.sql("update `tabDesktop Icon` set type = 'module' where module_name = 'Restaurant'")
erpnext.patches.v11_0.set_salary_component_properties
erpnext.patches.v11_0.set_user_permissions_for_department

View File

@ -0,0 +1,17 @@
import frappe
def execute():
user_permissions = frappe.db.sql("""select name, for_value from `tabUser Permission`
where allow='Department'""", as_dict=1)
for d in user_permissions:
user_permission = frappe.get_doc("User Permission", d.name)
for new_dept in frappe.db.sql("""select name from tabDepartment
where ifnull(company, '') != '' and department_name=%s""", d.for_value):
try:
new_user_permission = frappe.copy_doc(user_permission)
new_user_permission.for_value = new_dept[0]
new_user_permission.save()
except frappe.DuplicateEntryError:
pass
frappe.db.sql("update tabDepartment set disabled=1 where ifnull(company, '') = ''")