外出过滤
This commit is contained in:
@@ -57,21 +57,8 @@ class GoApprovals(models.Model):
|
||||
for rec in self:
|
||||
if not rec.start_date or not rec.end_date or not rec.employee_ids:
|
||||
continue
|
||||
# 获取当前记录关联的 workflow record,判断自身状态
|
||||
# 草稿状态(start)或已回收的不参与冲突判断
|
||||
self_workflow = self.env['soong.workflow.record'].search([
|
||||
('res_model', '=', 'go.approval'),
|
||||
('res_id', '=', rec.id),
|
||||
('reclaim_state', '=', False),
|
||||
], limit=1)
|
||||
# 自身是草稿且尚未进入审批,不做校验(保存草稿时不拦截)
|
||||
# 只有转交(审批中/结束)时才校验
|
||||
if self_workflow and self_workflow.approve_state == 'start':
|
||||
continue
|
||||
|
||||
for employee in rec.employee_ids:
|
||||
# 查找同一员工其他外出申请中时间段有交叉的记录
|
||||
# 通过 workflow record 过滤:只算审批中(pending)或结束(end)的
|
||||
candidate_ids = self.env['go.approval'].search([
|
||||
('id', '!=', rec.id),
|
||||
('employee_ids', 'in', employee.id),
|
||||
@@ -80,7 +67,7 @@ class GoApprovals(models.Model):
|
||||
]).ids
|
||||
if not candidate_ids:
|
||||
continue
|
||||
# 过滤掉草稿和已回收的
|
||||
# 只有审批中(pending)或已结束(end)的才算冲突,草稿和已回收的不算
|
||||
valid_workflow = self.env['soong.workflow.record'].search([
|
||||
('res_model', '=', 'go.approval'),
|
||||
('res_id', 'in', candidate_ids),
|
||||
@@ -95,6 +82,35 @@ class GoApprovals(models.Model):
|
||||
def _get_default_name_title(self):
|
||||
return self._description if self._description else self._name
|
||||
|
||||
def btn_exec_action(self):
|
||||
"""重写转交方法,在转交时校验时间段冲突"""
|
||||
cx = self.env.context.copy() or {}
|
||||
btn_key = cx.get('btn_key', '')
|
||||
# 只在转交时做校验
|
||||
btn_rec = self.env['soong.workflow.node.button'].search([('btn_key', '=', btn_key)], limit=1)
|
||||
if btn_rec and btn_rec.name == '转交':
|
||||
if self.start_date and self.end_date and self.employee_ids:
|
||||
for employee in self.employee_ids:
|
||||
candidate_ids = self.env['go.approval'].search([
|
||||
('id', '!=', self.id),
|
||||
('employee_ids', 'in', employee.id),
|
||||
('start_date', '<=', self.end_date),
|
||||
('end_date', '>=', self.start_date),
|
||||
]).ids
|
||||
if candidate_ids:
|
||||
valid_workflow = self.env['soong.workflow.record'].search([
|
||||
('res_model', '=', 'go.approval'),
|
||||
('res_id', 'in', candidate_ids),
|
||||
('reclaim_state', '=', False),
|
||||
('approve_state', 'in', ['pending', 'end']),
|
||||
])
|
||||
if valid_workflow:
|
||||
raise ValidationError(
|
||||
f"员工【{employee.name}】在 {self.start_date} 至 {self.end_date} 期间已有外出申请(审批中或已结束),相同时间段内不能重复创建。"
|
||||
)
|
||||
return super().btn_exec_action()
|
||||
|
||||
|
||||
name_title = fields.Char(default=_get_default_name_title)
|
||||
self_users_ids = fields.Many2many('res.users', string="当前经办人", default=lambda self: [(6, 0, [self.env.user.id])])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user