添加功能

This commit is contained in:
李鹏宇
2025-12-31 10:37:20 +08:00
parent f0c474add3
commit de951675f9
@@ -233,100 +233,100 @@ class OvertimeApprovals(models.Model):
def put_hr_employee(self):
for record in self:
employee_id = self.env['hr.employee'].search([('id', '=', record.users_id.employee_ids.id)])
meal_number = employee_id.meal_number
if self.meal == 'yes':
meal_number += 1
employee_id.write({'meal_number': meal_number})
for employee_id in record.employee_ids:
meal_number = employee_id.meal_number
if self.meal == 'yes':
meal_number += 1
employee_id.write({'meal_number': meal_number})
holiday_status_id = self.env['hr.leave.type'].search([('name', '=', '补休')])
allocation = self.env['hr.leave.allocation'].create({
'employee_id': employee_id.id,
'name': '补休',
'number_of_days': self.duration / 8,
'holiday_status_id': holiday_status_id.id,
'allocation_type': 'regular',
"number_of_days_display": self.duration / 8,
})
if allocation:
allocation.sudo().action_validate()
# 创建日志
if self.start_time:
start_date = fields.Datetime.from_string(self.start_time).date()
vacation_date = start_date.replace(day=1)
reports_id = self.env['yuthon.vacation.reports'].search([
('employee_id', '=', self.users_id.employee_id.id),
('vacation_date', '=', vacation_date)
])
workflow_record_id = self.env['soong.workflow.record'].search([
('code', '=', self.code)
])
workday = 0.0
legal_day = 0.0
public_holidays = 0.0
holiday_status_id = self.env['hr.leave.type'].search([('name', '=', '补休')])
allocation = self.env['hr.leave.allocation'].create({
'employee_id': employee_id.id,
'name': '补休',
'number_of_days': self.duration / 8,
'holiday_status_id': holiday_status_id.id,
'allocation_type': 'regular',
"number_of_days_display": self.duration / 8,
})
if allocation:
allocation.sudo().action_validate()
# 创建日志
if self.start_time:
start_date = fields.Datetime.from_string(self.start_time).date()
vacation_date = start_date.replace(day=1)
reports_id = self.env['yuthon.vacation.reports'].search([
('employee_id', '=', employee_id.id),
('vacation_date', '=', vacation_date)
])
workflow_record_id = self.env['soong.workflow.record'].search([
('code', '=', self.code)
])
workday = 0.0
legal_day = 0.0
public_holidays = 0.0
if record.type_overtime == 'work':
workday = record.duration
elif record.type_overtime == 'weekend':
public_holidays = record.duration
elif record.type_overtime == 'holiday':
legal_day = record.duration
if record.type_overtime == 'work':
workday = record.duration
elif record.type_overtime == 'weekend':
public_holidays = record.duration
elif record.type_overtime == 'holiday':
legal_day = record.duration
overtime_data = {
'vacation_id': reports_id.id,
'update_type': 'add',
'meal_number': 1 if self.meal == 'yes' else 0,
'workflow_record_id': workflow_record_id.id if workflow_record_id else False,
'workday': workday,
'legal_day': legal_day,
'public_holidays': public_holidays,
'update_date': fields.Datetime.now(),
'text': '审批'
}
overtime_exist_domain = [
('vacation_id', '=', reports_id.id),
('update_type', '=', 'add'),
('workflow_record_id', '=', workflow_record_id.id if workflow_record_id else False),
('workday', '=', workday),
('legal_day', '=', legal_day),
('public_holidays', '=', public_holidays),
('text', '=', '审批')
]
existing_overtime = self.env['vacation.over.line'].search(
overtime_exist_domain,
limit=1
)
if not existing_overtime and reports_id:
reports_id.write({'overtime_ids': [(0, 0, overtime_data)]})
if self.meal == 'yes' and not existing_overtime:
meal_fee_value = (0, 0, {
overtime_data = {
'vacation_id': reports_id.id,
'update_type': 'add',
'workflow_record_id': workflow_record_id.id,
'meal_number': 1 if self.meal == 'yes' else 0,
'workflow_record_id': workflow_record_id.id if workflow_record_id else False,
'workday': workday,
'legal_day': legal_day,
'public_holidays': public_holidays,
'update_date': fields.Datetime.now(),
'update_lines': 1,
'text': '审批'
})
reports_id.write({'meal_fee_ids': [meal_fee_value]})
}
overtime_exist_domain = [
('vacation_id', '=', reports_id.id),
('update_type', '=', 'add'),
('workflow_record_id', '=', workflow_record_id.id if workflow_record_id else False),
('workday', '=', workday),
('legal_day', '=', legal_day),
('public_holidays', '=', public_holidays),
('text', '=', '审批')
]
existing_overtime = self.env['vacation.over.line'].search(
overtime_exist_domain,
limit=1
)
if not existing_overtime and reports_id:
reports_id.write({'overtime_ids': [(0, 0, overtime_data)]})
if self.meal == 'yes' and not existing_overtime:
meal_fee_value = (0, 0, {
'vacation_id': reports_id.id,
'update_type': 'add',
'workflow_record_id': workflow_record_id.id,
'update_date': fields.Datetime.now(),
'update_lines': 1,
'text': '审批'
})
reports_id.write({'meal_fee_ids': [meal_fee_value]})
reports_id.write({'overtime_ids': [(0, 0, overtime_data)]})
start_date = fields.Date.to_date(self.start_time)
end_date = fields.Date.to_date(self.end_time)
attendance_records = self.env['hr.attendance'].search([
('employee_id', '=', employee_id.id),
('current_data', '>=', start_date),
('current_data', '<=', end_date),
])
for attendance_record in attendance_records:
workflow_id = self.env['soong.workflow.record'].search([('code', '=', self.code)], limit=1)
if attendance_record:
attendance_record.write({'is_workflow': True,
'is_abnormal': False,
'is_no_card': False,
'is_late_card': False,
'is_early_card': False,
'workflow_id': workflow_id.id,
})
reports_id.write({'overtime_ids': [(0, 0, overtime_data)]})
start_date = fields.Date.to_date(self.start_time)
end_date = fields.Date.to_date(self.end_time)
attendance_records = self.env['hr.attendance'].search([
('employee_id', '=', employee_id.id),
('current_data', '>=', start_date),
('current_data', '<=', end_date),
])
for attendance_record in attendance_records:
workflow_id = self.env['soong.workflow.record'].search([('code', '=', self.code)], limit=1)
if attendance_record:
attendance_record.write({'is_workflow': True,
'is_abnormal': False,
'is_no_card': False,
'is_late_card': False,
'is_early_card': False,
'workflow_id': workflow_id.id,
})
@api.depends('users_id', 'duration', 'start_time', 'end_time')
def _compute_name(self):