添加功能

This commit is contained in:
李鹏宇
2025-11-22 18:19:49 +08:00
parent f25772ecf7
commit 444b5f2d0b
5 changed files with 101 additions and 49 deletions
+9
View File
@@ -51,6 +51,7 @@ class SoongWorkflow(models.Model):
is_enable = fields.Boolean(string="是否启用", compute="compute_is_enable", store=True)
is_enable_return_button = fields.Boolean(string="是否启用收回", default=True)
is_enable_transmitted_button = fields.Boolean(string="是否启用转交", default=True)
is_ease = fields.Boolean(string="是否简化流程")
approvals_group_id = fields.Many2one('soong.approval.group', string="审批分组")
department_role_ids = fields.Many2many('hr.department', string="授权部门范围", store=True)
user_role_ids = fields.Many2many('soong.user.role', 'soong_workflow_user_role_rel', 'workflow_id', 'user_role_id', string="授权范围", store=True)
@@ -59,6 +60,14 @@ class SoongWorkflow(models.Model):
employee_ids = fields.Many2many('hr.employee', string="人员")
role_ids = fields.Many2many('soong.user.role', 'soong_workflow_role_rel', 'workflow_id', 'user_role_id', string="角色")
@api.onchange('is_ease')
def _onchange_is_ease(self):
target_value = not self.is_ease
for node in self.node_ids:
transfer_buttons = [btn for btn in node.button_ids if btn.name == '转交']
for button in transfer_buttons:
button.has_comment = target_value
def _search_is_user_department_role(self, operator, value):
id_list = []
if self.env.user.has_group("soong_workflow.group_soong_workflow_user"):
+37 -37
View File
@@ -116,43 +116,43 @@ class SoongWorkflowMixin(models.AbstractModel):
soong_record_ids = fields.One2many(comodel_name="soong.workflow.line", inverse_name="res_id", string=" ",)
project_ids = fields.One2many(comodel_name="project.project.line", inverse_name="res_id", string=" ",)
@api.model_create_multi
def create(self, vals_list):
res = super().create(vals_list)
target_role = self.env['soong.user.role'].search(
[('name', '=', '考勤校对'), ('company_id', '=', res.env.user.employee_id.company_id.id)],
limit=1
)
target_role_id = target_role.id if target_role else None
for record in res:
button_ids = record.sudo().workflow_id.node_ids.button_ids.search(
[('workflow_id', '=', record.workflow_id.id)])
# 获取当前用户的主角色和辅助角色ID列表
employee = record.env.user.employee_id
current_user_role_ids = []
if employee.user_role_id:
current_user_role_ids.append(employee.user_role_id.id)
if employee.user_role_ids:
current_user_role_ids.extend(employee.user_role_ids.ids)
if target_role_id in current_user_role_ids:
continue
for button_id in button_ids:
if button_id.node_id.is_end:
continue
allowed_departments = button_id.node_id.department_id
if allowed_departments and employee.department_id.id not in allowed_departments.ids:
continue
allowed_role_ids = []
if button_id.users_role_id:
allowed_role_ids.append(button_id.users_role_id.id)
elif button_id.users_role_group_ids:
allowed_role_ids.extend(button_id.users_role_group_ids.user_role_ids.ids)
else:
continue
if current_user_role_ids and any(role_id in allowed_role_ids for role_id in current_user_role_ids):
record.state = button_id.node_id.node_name
return res
# @api.model_create_multi
# def create(self, vals_list):
# res = super().create(vals_list)
# target_role = self.env['soong.user.role'].search(
# [('name', '=', '考勤校对'), ('company_id', '=', res.env.user.employee_id.company_id.id)],
# limit=1
# )
# target_role_id = target_role.id if target_role else None
#
# for record in res:
# button_ids = record.sudo().workflow_id.node_ids.button_ids.search(
# [('workflow_id', '=', record.workflow_id.id)])
# # 获取当前用户的主角色和辅助角色ID列表
# employee = record.env.user.employee_id
# current_user_role_ids = []
# if employee.user_role_id:
# current_user_role_ids.append(employee.user_role_id.id)
# if employee.user_role_ids:
# current_user_role_ids.extend(employee.user_role_ids.ids)
# if target_role_id in current_user_role_ids:
# continue
# for button_id in button_ids:
# if button_id.node_id.is_end:
# continue
# allowed_departments = button_id.node_id.department_id
# if allowed_departments and employee.department_id.id not in allowed_departments.ids:
# continue
# allowed_role_ids = []
# if button_id.users_role_id:
# allowed_role_ids.append(button_id.users_role_id.id)
# elif button_id.users_role_group_ids:
# allowed_role_ids.extend(button_id.users_role_group_ids.user_role_ids.ids)
# else:
# continue
# if current_user_role_ids and any(role_id in allowed_role_ids for role_id in current_user_role_ids):
# record.state = button_id.node_id.node_name
# return res
def _create_update_logs(self, btn_rec):
log_obj = self.env["soong.workflow.log"]
+21 -1
View File
@@ -403,7 +403,7 @@ class SoongWorkflowNodeButton(models.Model):
related="node_id.workflow_id",
ondelete="cascade",
)
invisible_expression_model = fields.Char(related="workflow_id.model_id.model")
invisible_expression_model = fields.Char(related="workflow_id.model_id.model", store=True)
is_automatic = fields.Boolean('按当前申请人自动匹配-本部门')
is_automatic_company = fields.Boolean('本公司', default=True)
is_automatic_group = fields.Boolean('本集团')
@@ -415,6 +415,8 @@ class SoongWorkflowNodeButton(models.Model):
is_dep = fields.Boolean('部门')
role_id = fields.Many2one(comodel_name="soong.user.role.group", string="角色")
specify_field_id = fields.Many2one(comodel_name="ir.model.fields", string="指定字段")
def update_user_id(self):
button_ids = self.env["soong.workflow.node.button"].browse(
self._context.get('active_ids', self._context.get('active_id')))
@@ -428,6 +430,7 @@ class SoongWorkflowNodeButton(models.Model):
self.is_automatic_group = False
self.is_logged_by = False
self.is_logged_company = False
self.specify_field_id = None
self.is_dep = False
self.is_logged_group = False
@@ -438,6 +441,7 @@ class SoongWorkflowNodeButton(models.Model):
self.is_automatic_group = False
self.is_logged_by = False
self.is_dep = False
self.specify_field_id = None
self.is_logged_company = False
self.is_logged_group = False
@@ -448,6 +452,7 @@ class SoongWorkflowNodeButton(models.Model):
self.is_automatic_company = False
self.is_logged_by = False
self.is_dep = False
self.specify_field_id = None
self.is_logged_company = False
self.is_logged_group = False
@@ -457,6 +462,7 @@ class SoongWorkflowNodeButton(models.Model):
self.is_automatic = False
self.is_automatic_company = False
self.is_automatic_group = False
self.specify_field_id = None
self.is_dep = False
self.is_logged_company = False
self.is_logged_group = False
@@ -469,6 +475,7 @@ class SoongWorkflowNodeButton(models.Model):
self.is_automatic_group = False
self.is_logged_by = False
self.is_dep = False
self.specify_field_id = None
self.is_logged_group = False
@api.onchange('is_logged_group')
@@ -479,8 +486,20 @@ class SoongWorkflowNodeButton(models.Model):
self.is_automatic_group = False
self.is_logged_by = False
self.is_dep = False
self.specify_field_id = None
self.is_logged_company = False
@api.onchange('specify_field_id')
def _onchange_specify_field_id(self):
if self.specify_field_id:
self.is_automatic = False
self.is_automatic_company = False
self.is_automatic_group = False
self.is_logged_by = False
self.is_dep = False
self.is_logged_company = False
self.is_logged_group = False
@api.onchange('is_dep')
def _onchange_is_dep(self):
if self.is_dep:
@@ -488,6 +507,7 @@ class SoongWorkflowNodeButton(models.Model):
self.is_automatic_company = False
self.is_automatic_group = False
self.is_logged_by = False
self.specify_field_id = None
self.is_logged_company = False
self.is_logged_group = False
@@ -195,7 +195,9 @@
</group>
<group string="按指定部门匹配">
<field name="is_dep"/>
<field name="role_id" invisible="not is_dep" required="1"/>
<field name="role_id" invisible="not is_dep"/>
<separator string="按指定字段匹配"/>
<field name="specify_field_id" domain="[('ttype', '=', 'many2one'), ('model', '=', invisible_expression_model)]"/>
</group>
</group>
<notebook>
@@ -33,7 +33,7 @@ class SoongWorkflowCommentWizard(models.TransientModel):
return_link_id = fields.Many2one('trans.link', string='退回节点')
invalid_link_ids = fields.Many2many(
'trans.link',
string='无审批人节点',
string='审批人节点,跳过节点',
compute='_compute_invalid_link_ids',
help='没有找到符合条件审批人的节点'
)
@@ -137,15 +137,29 @@ class SoongWorkflowCommentWizard(models.TransientModel):
ctx_links = self.env.context.get('all_workflow_links', [])
all_links = self.env['trans.link'].browse(ctx_links) if isinstance(ctx_links, (list, tuple)) else ctx_links
record_id = self.env[record.res_model].browse(record.res_id) if record.res_model and record.res_id else None
current_link = record.trans_link_id
if current_link and all_links:
sorted_all_links = all_links.sorted('sequence')
for idx, link in enumerate(sorted_all_links):
if link.id == current_link.id and link.sequence == current_link.sequence:
approvers = self._get_approvers_for_link(link, record_id)
if not approvers:
invalid_links |= link
for link in all_links:
if not link or isinstance(link, int):
continue
# 使用封装方法
approvers = self._get_approvers_for_link(link, record_id)
if not approvers:
invalid_links |= link
if record_id.log_ids2:
log_records = record_id.log_ids2
else:
log_records = record_id.log_ids
approved_users = log_records.filtered(lambda log: log.node_btn_name != '1' and log.done_by).mapped('done_by.employee_ids')
approved_employee_ids = approved_users.ids
employee_ids = approvers.ids
if len(approvers) > 1:
is_all_included = all(emp_id in approved_employee_ids for emp_id in employee_ids)
if is_all_included:
if idx + 1 < len(sorted_all_links):
self.trans_link_id = sorted_all_links[idx + 1]
invalid_links |= current_link
break
record.invalid_link_ids = invalid_links
@@ -208,6 +222,7 @@ class SoongWorkflowCommentWizard(models.TransientModel):
is_logged_company = button.is_logged_company
is_logged_group = button.is_logged_group
is_dep = button.is_dep
is_field = button.specify_field_id
if button.reviewer_id:
employee = self.env['hr.employee'].search([
@@ -225,7 +240,7 @@ class SoongWorkflowCommentWizard(models.TransientModel):
current_user = self.env.user
applicant = None
# 尝试获取申请人的用户对象
# 获取申请人的用户对象
for field_name in ['user_id', 'users_id']:
if hasattr(record_id, field_name):
applicant = getattr(record_id, field_name)
@@ -275,6 +290,12 @@ class SoongWorkflowCommentWizard(models.TransientModel):
if parent_company:
group_company_ids = self.env['res.company'].search([('id', 'child_of', parent_company.id)]).ids
company_domain = [('company_id', 'in', group_company_ids)]
elif is_field:
field_name = button.specify_field_id.name
# 目前只会有入职
field_value = record_id[field_name]
department_domain = ['|', ('department_id', '=', field_value.id),
('department_ids', 'in', field_value.id)]
if link_users_id:
role_domain = ['|', ('user_role_id', '=', link_users_id.id), ('user_role_ids', 'in', link_users_id.id)]