From 99e72af089989f776dcd721a9b6706acd444c327 Mon Sep 17 00:00:00 2001 From: Zlash65 Date: Tue, 15 May 2018 12:59:27 +0530 Subject: [PATCH] skip abbr, reload doc, disable edit for root department node' --- erpnext/hr/doctype/department/department.js | 13 +++++++++++-- erpnext/hr/doctype/department/department.py | 7 +++++-- .../create_department_records_for_each_company.py | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/erpnext/hr/doctype/department/department.js b/erpnext/hr/doctype/department/department.js index 71cf2d2aa98..a945312a52b 100644 --- a/erpnext/hr/doctype/department/department.js +++ b/erpnext/hr/doctype/department/department.js @@ -2,7 +2,16 @@ // For license information, please see license.txt frappe.ui.form.on('Department', { - onload: function(frm) { - + refresh: function(frm) { + // read-only for root department + if(!frm.doc.parent_department) { + cur_frm.set_read_only(); + cur_frm.set_intro(__("This is a root customer group and cannot be edited.")); + } + }, + validate: function(frm) { + if(frm.doc.name=="All Departments") { + frappe.throw(__("You cannot edit root node.")); + } } }); diff --git a/erpnext/hr/doctype/department/department.py b/erpnext/hr/doctype/department/department.py index 19994ae5efb..6544390ee5b 100644 --- a/erpnext/hr/doctype/department/department.py +++ b/erpnext/hr/doctype/department/department.py @@ -11,8 +11,11 @@ class Department(NestedSet): nsm_parent_field = 'parent_department' def autoname(self): - abbr = frappe.db.get_value('Company', self.company, 'abbr') - self.name = '{0} - {1}'.format(self.department_name, abbr) + if not self.department_name=="All Departments": + abbr = frappe.db.get_value('Company', self.company, 'abbr') + self.name = '{0} - {1}'.format(self.department_name, abbr) + else: + self.name = self.department_name def update_nsm_model(self): frappe.utils.nestedset.update_nsm(self) diff --git a/erpnext/patches/v11_0/create_department_records_for_each_company.py b/erpnext/patches/v11_0/create_department_records_for_each_company.py index 4cfe960b550..6f869b00422 100644 --- a/erpnext/patches/v11_0/create_department_records_for_each_company.py +++ b/erpnext/patches/v11_0/create_department_records_for_each_company.py @@ -2,7 +2,7 @@ import frappe from frappe.utils.nestedset import rebuild_tree def execute(): - for doctype in ['department', 'leave_period', 'staffing_plan']: + for doctype in ['department', 'leave_period', 'staffing_plan', 'job_opening']: frappe.reload_doc("hr", "doctype", doctype) companies = frappe.db.get_all("Company", fields=["name", "abbr"])