Files
gzth/soong_workflow/models/soong_user_role.py
T
2024-11-18 11:19:08 +08:00

56 lines
2.5 KiB
Python

# -*- coding: utf-8 -*-
from odoo import api, fields, models, _
class YuthonUserRole(models.Model):
_name = 'soong.user.role'
name = fields.Char(string="角色名称")
user_type = fields.Selection([("oa_admin", "OA管理员"),
("system_global_user", "系统全局角色"),
("departmental_role", "部门私有角色")], string="角色类型")
department_id = fields.Many2one('hr.department', string="所属机构部门")
create_time = fields.Datetime(string="创建时间", default=fields.Datetime.now)
end_time = fields.Datetime(string="结束时间")
yuthon_company = fields.Selection([('thtz', '天河投资集团'), ('thwg', '天河物管'),
('thlc', '天河粮储'), ('tctj', '天投城建'),
('thtjbb', '天河投资本部')], string="所属公司",compute='compute_company')
@api.depends('department_id')
def compute_company(self):
company_mapping = {'天河投资集团': 'thtz',
'天河物管': 'thwg',
'天河粮储': 'thlc',
'天投城建': 'tctj',
'天河投资本部':'thtjbb'}
for record in self:
visited_departments = set()
department = record.department_id
while department and department.id not in visited_departments:
visited_departments.add(department.id)
if department.name == '天河投资集团':
record.yuthon_company = 'thtz'
break
elif department.name in company_mapping:
record.yuthon_company = company_mapping[department.name]
break
department = department.parent_id
else:
record.yuthon_company = 'thtz'
@api.model
def _get_company_mapping(self):
return {
'thtz': '天河投资集团',
'thwg': '天河物管',
'thlc': '天河粮储',
'tctj': '天投城建',
'thtjbb': '天河投资本部',
}
@api.depends('name', 'yuthon_company')
def _compute_display_name(self):
company_mapping = self._get_company_mapping()
for record in self:
company_name = company_mapping.get(record.yuthon_company, record.yuthon_company)
record.display_name = f"{company_name}-{record.department_id.name}-{record.name}"