@@ -10,6 +10,7 @@ from datetime import datetime, date, time, timedelta
|
||||
class SoongWorkflowCommentWizard(models.TransientModel):
|
||||
_name = "soong.workflow.comment.wizard"
|
||||
_description = "Soong Workflow Comment Wizard"
|
||||
_inherit = ['mail.thread.main.attachment', 'mail.activity.mixin']
|
||||
|
||||
name = fields.Char(string="name")
|
||||
res_model = fields.Char()
|
||||
@@ -43,7 +44,6 @@ class SoongWorkflowCommentWizard(models.TransientModel):
|
||||
'custom_id', 'employee_id',
|
||||
string="督办人员", store=True)
|
||||
is_automatic = fields.Boolean('是否自动匹配')
|
||||
|
||||
employee_ids1 = fields.Many2many(
|
||||
'hr.employee',
|
||||
'employee_ids1_rel',
|
||||
@@ -121,24 +121,68 @@ class SoongWorkflowCommentWizard(models.TransientModel):
|
||||
record_id = self.env[self.res_model].search([('id', '=', self.res_id)])
|
||||
for ret in self.trans_link_id:
|
||||
workflow_id = self.trans_link_id.node_button_id.workflow_id
|
||||
link_users_id = workflow_id.node_ids.search([('name', '=', self.trans_link_id.name), ('workflow_id', '=', workflow_id.id)]).button_ids[0].users_role_id
|
||||
link_users_group_ids = workflow_id.node_ids.search([('name', '=', self.trans_link_id.name), ('workflow_id', '=', workflow_id.id)]).button_ids[0].users_role_group_ids
|
||||
next_is_automatic = workflow_id.node_ids.search([('name', '=', self.trans_link_id.name), ('workflow_id', '=', workflow_id.id)]).button_ids[0].is_automatic
|
||||
node = workflow_id.node_ids.search(
|
||||
[('name', '=', self.trans_link_id.name), ('workflow_id', '=', workflow_id.id)])
|
||||
button = node.button_ids[0] if node.button_ids else False
|
||||
if not button:
|
||||
continue
|
||||
link_users_id = button.users_role_id
|
||||
link_users_group_ids = button.users_role_group_ids
|
||||
# 获取六个布尔字段的值(假设只有一个为True)
|
||||
is_automatic = button.is_automatic
|
||||
is_automatic_company = button.is_automatic_company
|
||||
is_automatic_group = button.is_automatic_group
|
||||
is_logged_by = button.is_logged_by
|
||||
is_logged_company = button.is_logged_company
|
||||
is_logged_group = button.is_logged_group
|
||||
employee_user_role_ids = employee_user_role_id = False
|
||||
# 构建部门筛选条件
|
||||
department_domain = []
|
||||
# 按当前申请人自动匹配
|
||||
if is_automatic: # 申请人-本部门
|
||||
department_domain = [('department_id', '=', record_id.department_id.id)]
|
||||
elif is_automatic_company: # 申请人-本公司
|
||||
company_departments = self.env['hr.department'].search(
|
||||
[('company_id', '=', record_id.company_id.id)]).ids
|
||||
department_domain = [('department_id', 'in', company_departments)]
|
||||
elif is_automatic_group: # 申请人-本集团
|
||||
parent_company = record_id.company_id.parent_id
|
||||
group_departments = self.env['hr.department'].search(
|
||||
[('company_id', 'child_of', parent_company.id)]).ids if parent_company else []
|
||||
department_domain = [('department_id', 'in', group_departments)]
|
||||
|
||||
# 按当前登录人自动匹配
|
||||
elif is_logged_by: # 登录人-本部门
|
||||
department_domain = [('department_id', '=', self.env.user.department_id.id)]
|
||||
elif is_logged_company: # 登录人-本公司
|
||||
company_departments = self.env['hr.department'].search(
|
||||
[('company_id', '=', self.env.user.company_id.id)]).ids
|
||||
department_domain = [('department_id', 'in', company_departments)]
|
||||
elif is_logged_group: # 登录人-本集团
|
||||
parent_company = self.env.user.company_id.parent_id
|
||||
group_departments = self.env['hr.department'].search(
|
||||
[('company_id', 'child_of', parent_company.id)]).ids if parent_company else []
|
||||
department_domain = [('department_id', 'in', group_departments)]
|
||||
# 处理角色筛选条件
|
||||
if link_users_id:
|
||||
employee_user_role_ids = self.env['hr.employee'].sudo().search(['|', ('user_role_id', '=', link_users_id.id), ('user_role_ids', 'in', link_users_id.id), ('company_id', '=', self.env.user.company_id.id)]) # 自动匹配
|
||||
employee_user_role_id = self.env['hr.employee'].sudo().search(['|', ('user_role_id', '=', link_users_id.id), ('user_role_ids', 'in', link_users_id.id),
|
||||
'|', ('department_id', '=', record_id.department_id.id), ('department_ids', 'in', record_id.department_id.id), ('company_id', '=', self.env.user.company_id.id)]) # 不自动匹配
|
||||
role_domain = ['|', ('user_role_id', '=', link_users_id.id), ('user_role_ids', 'in', link_users_id.id)]
|
||||
company_domain = [('company_id', '=', self.env.user.company_id.id)]
|
||||
# 自动匹配:结合角色和部门筛选
|
||||
domain = role_domain + company_domain + department_domain
|
||||
employee_user_role_ids = self.env['hr.employee'].sudo().search(domain)
|
||||
|
||||
elif link_users_group_ids:
|
||||
# 不自动匹配
|
||||
employee_user_role_ids = self.env['hr.employee'].sudo().search(['|', ('user_role_id', 'in', link_users_group_ids.user_role_ids.ids), ('user_role_ids', 'in', link_users_group_ids.user_role_ids.ids)])
|
||||
role_domain = ['|', ('user_role_id', 'in', link_users_group_ids.user_role_ids.ids),
|
||||
('user_role_ids', 'in', link_users_group_ids.user_role_ids.ids)]
|
||||
company_domain = [('company_id', '=', self.env.user.company_id.id)]
|
||||
# 自动匹配
|
||||
employee_user_role_id = self.env['hr.employee'].sudo().search([('id', 'in', employee_user_role_ids.ids),
|
||||
'|', ('department_id', '=', record_id.department_id.id),
|
||||
('department_ids', 'in', record_id.department_id.id),
|
||||
('company_id', '=', self.env.user.company_id.id)]) # 自动匹配
|
||||
self.employee_trans_domain_ids = employee_user_role_ids if not next_is_automatic else employee_user_role_id
|
||||
self.employee_ids1 = employee_user_role_ids if not next_is_automatic else employee_user_role_id
|
||||
domain = role_domain + company_domain + department_domain
|
||||
employee_user_role_ids = self.env['hr.employee'].sudo().search(domain)
|
||||
|
||||
# 设置结果
|
||||
self.employee_trans_domain_ids = employee_user_role_ids
|
||||
self.employee_ids1 = employee_user_role_ids
|
||||
# 特殊处理:分发按钮
|
||||
if '分发' in ret.name:
|
||||
self.employee_ids1 = record_id.users_id.employee_id
|
||||
|
||||
@@ -148,7 +192,7 @@ class SoongWorkflowCommentWizard(models.TransientModel):
|
||||
record_id = self.env[self.res_model].search([('id', '=', self.res_id)])
|
||||
for employee in self.employee_ids:
|
||||
action_id = self.env['ir.actions.act_window'].search([('res_model', '=', self.res_model)])[0]
|
||||
url = f'https://oa.thtzjt.com/web?wecom_fields={employee.user_id.wecom_fields}&oauth_uid={employee.wecom_userid}#id={record_id.id}&cids=2&action={action_id.id}&model={record_id._name}&view_type=form'
|
||||
url = f'https://oa.thtzjt.com/web?login={employee.user_id.login}&oauth_uid={employee.wecom_userid}#id={record_id.id}&cids=2&action={action_id.id}&model={record_id._name}&view_type=form'
|
||||
self.sudo().env["wecom.apps"].sync_send_message_textcard(category='oa',
|
||||
user_id=employee.wecom_userid,
|
||||
title=record_id._description,
|
||||
|
||||
Reference in New Issue
Block a user