20 lines
729 B
Python
20 lines
729 B
Python
# -*- coding: utf-8 -*-
|
|
from odoo import api, models
|
|
|
|
|
|
class HrDepartment(models.Model):
|
|
_inherit = 'hr.department'
|
|
|
|
@api.depends('name', 'parent_id.name')
|
|
@api.depends_context('show_parent_department')
|
|
def _compute_display_name(self):
|
|
"""当上下文中 show_parent_department=True 时,显示 '直接上级 / 当前部门',只取一级"""
|
|
if self.env.context.get('show_parent_department'):
|
|
for record in self:
|
|
if record.parent_id:
|
|
record.display_name = '%s / %s' % (record.parent_id.name, record.name)
|
|
else:
|
|
record.display_name = record.name
|
|
return
|
|
return super()._compute_display_name()
|