Set parent department if missing and not root itself

This commit is contained in:
Nabin Hait 2018-05-23 18:35:59 +05:30
parent 315dbd2ed1
commit d5cb4c10a1

View File

@ -3,6 +3,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe import _
from frappe.utils.nestedset import NestedSet from frappe.utils.nestedset import NestedSet
from erpnext.utilities.transaction_base import delete_events from erpnext.utilities.transaction_base import delete_events
from frappe.model.document import Document from frappe.model.document import Document
@ -11,15 +12,16 @@ class Department(NestedSet):
nsm_parent_field = 'parent_department' nsm_parent_field = 'parent_department'
def autoname(self): def autoname(self):
if not self.department_name=="All Departments": if not self.department_name==_("All Departments"):
abbr = frappe.db.get_value('Company', self.company, 'abbr') abbr = frappe.db.get_value('Company', self.company, 'abbr')
self.name = '{0} - {1}'.format(self.department_name, abbr) self.name = '{0} - {1}'.format(self.department_name, abbr)
else: else:
self.name = self.department_name self.name = self.department_name
def validate(self): def validate(self):
if not self.parent_department: if not self.parent_department and self.department_name != _("All Departments") \
self.parent_department = "All Departments" and frappe.db.exists("Department", _("All Departments")):
self.parent_department = _("All Departments")
def update_nsm_model(self): def update_nsm_model(self):
frappe.utils.nestedset.update_nsm(self) frappe.utils.nestedset.update_nsm(self)