@@ -185,98 +185,6 @@ class HrLeave(models.Model):
|
||||
for leave in leave_ids:
|
||||
leave.state = 'draft'
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
allocation = super(HrLeave, self).create(vals)
|
||||
if allocation.state != 'validate':
|
||||
return allocation
|
||||
employees = self.env['hr.employee'].browse(allocation.employee_id.id)
|
||||
# 根据假期类型执行不同逻辑
|
||||
if allocation.holiday_status_id.name == '年假':
|
||||
self._process_annual_leave(allocation, employees)
|
||||
elif allocation.holiday_status_id.name == '补休':
|
||||
self._process_compensatory_leave(allocation, employees)
|
||||
return allocation
|
||||
|
||||
def _process_annual_leave(self, allocation, employees):
|
||||
"""处理年假逻辑"""
|
||||
days = allocation.number_of_days * 8
|
||||
for employee in employees:
|
||||
# 更新员工年假余额
|
||||
employee.write({
|
||||
'user_year': employee.user_year + days
|
||||
})
|
||||
reports_id = self.env['yuthon.vacation.reports'].search([
|
||||
('employee_id', '=', employee.id)
|
||||
], limit=1)
|
||||
if not reports_id:
|
||||
reports_id = self.env['yuthon.vacation.reports'].create({
|
||||
'employee_id': employee.id,
|
||||
})
|
||||
self.env['vacation.leave.line'].create({
|
||||
'vacation_id': reports_id.id,
|
||||
'update_type': 'reduce',
|
||||
'update_date': fields.Datetime.now(),
|
||||
'update_lines': days,
|
||||
'text': '休假',
|
||||
'allocation_type': 'vacation',
|
||||
})
|
||||
|
||||
def _process_compensatory_leave(self, allocation, employees):
|
||||
"""处理补休逻辑"""
|
||||
for employee in employees:
|
||||
reports_id = self.env['yuthon.vacation.reports'].search([
|
||||
('employee_id', '=', employee.id)
|
||||
], limit=1)
|
||||
if not reports_id:
|
||||
reports_id = self.env['yuthon.vacation.reports'].create({
|
||||
'employee_id': employee.id,
|
||||
})
|
||||
self.env['vacation.over.line'].create({
|
||||
'vacation_id': reports_id.id,
|
||||
'employee_id': employee.id,
|
||||
'update_type': 'reduce',
|
||||
'workday': allocation.number_of_days * 8,
|
||||
'legal_day': 0,
|
||||
'public_holidays': 0,
|
||||
'meal_number': 0,
|
||||
'update_date': fields.Date.today(),
|
||||
'is_void': False,
|
||||
'text': f'补休',
|
||||
})
|
||||
|
||||
def unlink(self):
|
||||
for record in self:
|
||||
if record.employee_id and record.holiday_status_id.name == '年假':
|
||||
employee = record.employee_id
|
||||
days = record.number_of_hours_display
|
||||
lines_to_delete = self.env['vacation.leave.line'].search([
|
||||
('vacation_id.employee_id', '=', employee.id),
|
||||
('update_type', '=', 'reduce'),
|
||||
('update_lines', '=', days),
|
||||
('allocation_type', '=', 'vacation'),
|
||||
])
|
||||
if lines_to_delete:
|
||||
lines_to_delete.is_void = True
|
||||
employee.write({
|
||||
'user_year': employee.user_year - days
|
||||
})
|
||||
|
||||
elif record.employee_id and record.holiday_status_id.name == '补休':
|
||||
employee = record.employee_id
|
||||
days = record.number_of_hours_display
|
||||
over_lines_to_delete = self.env['vacation.over.line'].search([
|
||||
('employee_id', '=', employee.id),
|
||||
('workday', '=', days),
|
||||
('update_type', '=', 'reduce'),
|
||||
('text', 'ilike', f'%{record.name}%'), # 通过名称模糊匹配
|
||||
])
|
||||
|
||||
if over_lines_to_delete:
|
||||
over_lines_to_delete.write({'is_void': True})
|
||||
|
||||
return super(HrLeave, self).unlink()
|
||||
|
||||
@api.depends('request_hour_from')
|
||||
def _compute_request_hour_from_real(self):
|
||||
for record in self:
|
||||
@@ -508,6 +416,8 @@ class HolidaysRequestBatch(models.Model):
|
||||
|
||||
# 提交
|
||||
def action_submit(self):
|
||||
self.leave_ids.action_validate()
|
||||
self.hour_leave_ids.action_validate()
|
||||
"""提交请假申请,区分年假和其他假期处理"""
|
||||
self._process_specific_leaves('年假', is_annual_leave=True)
|
||||
other_leave_types = [
|
||||
|
||||
Reference in New Issue
Block a user