|
|
|
@@ -14,7 +14,7 @@ class OvertimeApprovals(models.Model):
|
|
|
|
|
name = fields.Char(string="标题", compute='_compute_name')
|
|
|
|
|
code = fields.Char(string="编号", default=lambda self: self.env['ir.sequence'].next_by_code('overtime_approval'))
|
|
|
|
|
users_id = fields.Many2one('res.users', string="申请人", default=lambda self: self.env.user.id)
|
|
|
|
|
overtime_approval_ids = fields.One2many('overtime.user.line', 'overtime_approval_id', string="加班审批行")
|
|
|
|
|
# overtime_approval_ids = fields.One2many('overtime.user.line', 'overtime_approval_id', string="加班审批行")
|
|
|
|
|
reason_application = fields.Char(string="事由")
|
|
|
|
|
department_id = fields.Many2one(related='users_id.employee_id.department_id', string="部门")
|
|
|
|
|
is_issues = fields.Boolean(string='是否上会')
|
|
|
|
@@ -138,51 +138,6 @@ class OvertimeApprovals(models.Model):
|
|
|
|
|
|
|
|
|
|
class OvertimeUserLine(models.Model):
|
|
|
|
|
_name = 'overtime.user.line'
|
|
|
|
|
_rec_name = 'overtime_approval_id'
|
|
|
|
|
_description = "加班明细行"
|
|
|
|
|
|
|
|
|
|
overtime_approval_id = fields.Many2one('overtime.approval', string="加班单号")
|
|
|
|
|
users_id = fields.Many2one('res.users', string="加班人员")
|
|
|
|
|
department_id = fields.Many2one('hr.department', string="部门")
|
|
|
|
|
overtime_hours = fields.Float(string="本月加班时长")
|
|
|
|
|
start_time = fields.Datetime(string="开始时间")
|
|
|
|
|
end_time = fields.Datetime(string="结束时间")
|
|
|
|
|
hours = fields.Float(string="加班时长", compute="_compute_hours")
|
|
|
|
|
type_overtime = fields.Selection([('work', '工作日加班'), ('weekend', '周末加班'), ('holiday', '节假日加班')],
|
|
|
|
|
string="加班类型", compute="_compute_overtime_type")
|
|
|
|
|
|
|
|
|
|
@api.depends('start_time', 'end_time')
|
|
|
|
|
def _compute_hours(self):
|
|
|
|
|
for record in self:
|
|
|
|
|
if record.start_time and record.end_time:
|
|
|
|
|
delta = record.end_time - record.start_time
|
|
|
|
|
record.hours = delta.total_seconds() / 3600
|
|
|
|
|
else:
|
|
|
|
|
record.hours = 0
|
|
|
|
|
|
|
|
|
|
@api.depends('start_time', 'end_time')
|
|
|
|
|
def _compute_overtime_type(self):
|
|
|
|
|
for record in self:
|
|
|
|
|
if record.start_time and record.end_time:
|
|
|
|
|
if record.start_time > record.end_time:
|
|
|
|
|
raise UserError("开始时间不能晚于结束时间")
|
|
|
|
|
start_date = fields.Datetime.from_string(record.start_time)
|
|
|
|
|
end_date = fields.Datetime.from_string(record.end_time)
|
|
|
|
|
public_holidays = self.env['resource.calendar.leaves'].search([])
|
|
|
|
|
for holiday in public_holidays:
|
|
|
|
|
holiday_start = fields.Datetime.from_string(holiday.date_from)
|
|
|
|
|
holiday_end = fields.Datetime.from_string(holiday.date_to)
|
|
|
|
|
if start_date <= holiday_end and end_date >= holiday_start:
|
|
|
|
|
record.type_overtime = 'holiday'
|
|
|
|
|
break
|
|
|
|
|
else:
|
|
|
|
|
if start_date.weekday() < 5 and end_date.weekday() < 5: # Not Saturday or Sunday
|
|
|
|
|
record.type_overtime = 'work'
|
|
|
|
|
elif start_date.weekday() >= 5 or end_date.weekday() >= 5: # Saturday or Sunday
|
|
|
|
|
record.type_overtime = 'weekend'
|
|
|
|
|
else:
|
|
|
|
|
record.type_overtime = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# def is_holiday(self, date):
|
|
|
|
|
# holiday_obj = self.env['resource.calendar.leaves']
|
|
|
|
|