@@ -66,25 +66,31 @@ class OvertimeApprovals(models.Model):
|
||||
@api.constrains('start_time')
|
||||
def _check_start_time(self):
|
||||
for rec in self:
|
||||
workflow_records = self.env['soong.workflow.record'].search([
|
||||
('workflow_id.name', '=', '加班'),
|
||||
('create_uid', '=', self.users_id.id),
|
||||
('reclaim_state', '=', False),
|
||||
])
|
||||
if not workflow_records:
|
||||
if not rec.employee_ids or not rec.start_time:
|
||||
continue
|
||||
for wf_rec in workflow_records:
|
||||
if wf_rec.res_model == rec._name and wf_rec.res_id == rec.id:
|
||||
current_date = (rec.start_time + timedelta(hours=8)).date()
|
||||
for employee in rec.employee_ids:
|
||||
if not employee.user_id:
|
||||
continue
|
||||
|
||||
target_model = self.env[wf_rec.res_model]
|
||||
target_record = target_model.browse(wf_rec.res_id)
|
||||
|
||||
if not target_record.exists() or not target_record.start_time:
|
||||
continue
|
||||
if (target_record.start_time + timedelta(hours=8)).date() == (
|
||||
rec.start_time + timedelta(hours=8)).date():
|
||||
raise UserError('当天已有加班审批,请重新选择开始时间')
|
||||
workflow_records = self.env['soong.workflow.record'].search([
|
||||
('workflow_id.name', '=', '加班'),
|
||||
('create_uid', '=', employee.user_id.id),
|
||||
('reclaim_state', '=', False),
|
||||
])
|
||||
for wf_rec in workflow_records:
|
||||
# 跳过自己这条记录
|
||||
if wf_rec.res_model == rec._name and wf_rec.res_id == rec.id:
|
||||
continue
|
||||
target_model = self.env[wf_rec.res_model]
|
||||
target_record = target_model.browse(wf_rec.res_id)
|
||||
if not target_record.exists() or not target_record.start_time:
|
||||
continue
|
||||
exist_date = (target_record.start_time + timedelta(hours=8)).date()
|
||||
if exist_date == current_date:
|
||||
raise UserError('员工【%s】在【%s】已有加班记录,不可重复提交!' % (
|
||||
employee.name,
|
||||
current_date
|
||||
))
|
||||
for employee in rec.employee_ids:
|
||||
holiday_status_id = self.env['hr.leave.type'].search([('name', '=', '补休')])
|
||||
start_year = rec.start_time.date().year
|
||||
@@ -175,13 +181,20 @@ class OvertimeApprovals(models.Model):
|
||||
corrected_end_time = max_allowed_end_time - timedelta(hours=8)
|
||||
rec.end_time = corrected_end_time
|
||||
|
||||
@api.depends('users_id', 'duration', 'start_time')
|
||||
@api.depends('employee_ids', 'duration', 'start_time')
|
||||
def _compute_overtime_hours(self):
|
||||
for rec in self:
|
||||
rec.overtime_hours = 0.0
|
||||
if not rec.users_id or not rec.start_time:
|
||||
if not rec.employee_ids or len(rec.employee_ids) != 1:
|
||||
continue
|
||||
now = rec.start_time # 获取当前时间(datetime类型)
|
||||
employee = rec.employee_ids[0]
|
||||
if not employee.user_id:
|
||||
continue
|
||||
|
||||
if not rec.start_time:
|
||||
continue
|
||||
|
||||
now = rec.start_time
|
||||
first_datetime = datetime(now.year, now.month, 1, 0, 0, 0)
|
||||
if now.month == 12:
|
||||
next_month_datetime = datetime(now.year + 1, 1, 1, 0, 0, 0)
|
||||
@@ -190,20 +203,20 @@ class OvertimeApprovals(models.Model):
|
||||
last_datetime = next_month_datetime - timedelta(seconds=1)
|
||||
workflow_records = self.env['soong.workflow.record'].search([
|
||||
('workflow_id.name', '=', '加班'),
|
||||
('create_uid', '=', rec.users_id.id),
|
||||
('create_uid', '=', employee.user_id.id),
|
||||
('approve_state', 'in', ['pending', 'end']),
|
||||
('reclaim_state', '!=', True),
|
||||
])
|
||||
overtime_name_list = []
|
||||
total_overtime = 0.0
|
||||
for workflow in workflow_records:
|
||||
related_model = self.env[workflow.res_model].browse(workflow.res_id)
|
||||
if not related_model.exists():
|
||||
continue
|
||||
start_time = related_model.start_time
|
||||
if first_datetime <= start_time <= last_datetime:
|
||||
if related_model.duration:
|
||||
total_overtime += related_model.duration
|
||||
overtime_name_list.append(related_model.name)
|
||||
rec.overtime_hours = total_overtime
|
||||
rec.overtime_hours = total_overtime
|
||||
|
||||
@api.constrains('users_id')
|
||||
def _check_overtime_hours(self):
|
||||
|
||||
@@ -113,7 +113,7 @@
|
||||
<group col="2">
|
||||
<group>
|
||||
<field name="is_thwg" invisible="1"/>
|
||||
<field name="overtime_hours" readonly="1" invisible="overtime_hours1"/>
|
||||
<field name="overtime_hours" readonly="1" invisible="overtime_hours1 or overtime_hours"/>
|
||||
<field name="overtime_hours1" invisible="not overtime_hours1" readonly="1"/>
|
||||
<field name="meal" required="1" invisible="is_thwg or is_lc"/>
|
||||
</group>
|
||||
|
||||
Reference in New Issue
Block a user