添加功能

This commit is contained in:
zhou
2025-06-09 14:20:55 +08:00
parent 5b2060f13a
commit cdfd0443e9
2 changed files with 22 additions and 20 deletions
+21 -19
View File
@@ -74,7 +74,7 @@ class YuthonWillTask(models.Model):
remarks = fields.Text(string='备注')
creation_time = fields.Date(string='创建时间', default=fields.Date.today())
employee_ids = fields.Many2many('hr.employee', 'will_task_employee_rel', 'custom_id', 'employee_id',
string='人员', store=True, index=True)
string='人员', store=True, index=True, search='_search_part_of_company')
employee_ids2 = fields.Many2many('hr.employee', 'will_task_employee_rel2', 'custom_id', 'employee_id',
string='司机', store=True, index=True)
users_ids = fields.Many2many('res.users', string='用户', store=True, index=True, default=lambda self: self.env.user)
@@ -88,24 +88,26 @@ class YuthonWillTask(models.Model):
@api.onchange('is_this_company')
def _onchange_is_this_company(self):
pass
# """当是否为本公司字段变化时,更新员工列表和domain"""
# if self.is_this_company:
# # 获取当前用户所属的公司列表
# company_ids = self.env.companies.ids
# # 过滤已选员工,只保留属于当前公司的员工
# self.employee_ids = self.employee_ids.filtered(
# lambda emp: emp.company_id.id in company_ids
# )
# # 返回domain,限制可选员工为当前公司的员工
# return {
# 'domain': {
# 'employee_ids': [('company_id', 'in', company_ids)]
# }
# }
# else:
# # 当不限制为本公司时,清空domain,允许选择所有员工
# return {'domain': {'employee_ids': []}}
for record in self:
if record.is_this_company:
# 返回本公司员工的domain
return {'domain': {'employee_ids': [('company_id', '=', self.env.company.id)]}}
else:
# 返回所有员工的domain
return {'domain': {'employee_ids': []}}
def _search_part_of_company(self, operator, value):
if operator not in ('=', '!=') or not isinstance(value, bool):
raise UserError(('Operation not supported'))
company_ids = self.env.companies.ids # 获取公司ID列表
# 处理反向操作符
if not value:
operator = '!=' if operator == '=' else '='
# 使用company_id in company_ids的结构
if operator == '=':
return [('company_id', 'in', company_ids)]
else: # operator == '!='
return [('company_id', 'not in', company_ids)]
@api.onchange('employee_ids', 'user_id')
def _onchange_employee_ids(self):
@@ -84,7 +84,7 @@
<group>
<field name="user_id"/>
<field name="task_state" invisible="1"/>
<field name="employee_ids" widget="many2many_tags" options="{'no_create': True}"/>
<field name="employee_ids" widget="many2many_tags" options="{'no_create': True}" domain="[('company_id', '=', company_id)] if is_this_company else []"/>
<field name="user_role_ids" widget="many2many_tags" invisible="1"/>
<field name="users_ids" widget="many2many_tags" invisible="1"/>
</group>