38 lines
1.8 KiB
Python
38 lines
1.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
from odoo import api, fields, models, _
|
|
|
|
|
|
class YuthonUserRole(models.Model):
|
|
_name = 'soong.user.role'
|
|
_order = 'number asc'
|
|
|
|
name = fields.Char(string="角色名称")
|
|
number = fields.Char(string="序号", store=True)
|
|
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', '天河粮储'), ('thtjbb', '天河投资本部')], string="所属公司", compute='compute_company')
|
|
|
|
@api.depends('department_id')
|
|
def compute_company(self):
|
|
company_mapping = {'天河投资集团': 'thtz', '天河物管': 'thwg',
|
|
'天河粮储': 'thlc',
|
|
'天河投资本部': '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' |