From d2b0f137ac4d21aa95475cf2595e0736c8f31b8d Mon Sep 17 00:00:00 2001 From: zhou <123@> Date: Sat, 12 Jul 2025 19:44:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yuthon_holiday/models/inherit_hr_leave.py | 41 +++++++++++++++++++ .../models/inherit_hr_leave_allocation.py | 12 +++--- .../models/yuthon_vacation_reports.py | 34 +++++++++++++-- .../views/yuthon_vacation_reports_views.xml | 41 ++++++++++++------- 4 files changed, 104 insertions(+), 24 deletions(-) diff --git a/yuthon_holiday/models/inherit_hr_leave.py b/yuthon_holiday/models/inherit_hr_leave.py index 052909ea3..4413e2edc 100644 --- a/yuthon_holiday/models/inherit_hr_leave.py +++ b/yuthon_holiday/models/inherit_hr_leave.py @@ -148,6 +148,47 @@ class HrLeave(models.Model): ('22', '22:00'), ('22.5', '22:30'), ('23', '23:00'), ('23.5', '23:30')], string='结束时间') + @api.model + def create(self, vals): + allocation = super(HrLeave, self).create(vals) + if allocation.holiday_status_id.name == '年假' and allocation.state == 'validate': + employee = allocation.employee_id + days = allocation.number_of_days * 8 + employee.write({ + 'user_year': employee.user_year + days + }) + reports_id = self.env['yuthon.vacation.reports'].search([ + ('employee_id', '=', employee.id) + ], limit=1) + # 创建假期明细记录 + 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', + }) + return allocation + + 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 + }) + return super(HrLeave, self).unlink() + @api.depends('request_hour_from') def _compute_request_hour_from_real(self): for record in self: diff --git a/yuthon_holiday/models/inherit_hr_leave_allocation.py b/yuthon_holiday/models/inherit_hr_leave_allocation.py index b15aab3fa..b73e31872 100644 --- a/yuthon_holiday/models/inherit_hr_leave_allocation.py +++ b/yuthon_holiday/models/inherit_hr_leave_allocation.py @@ -105,10 +105,8 @@ class HrLeaveAllocation(models.Model): @api.model def create(self, vals): - # 调用原始创建方法获取记录 allocation = super(HrLeaveAllocation, self).create(vals) - # 处理年假类型的分配 - if allocation.holiday_status_id.name == '年假': + if allocation.holiday_status_id.name == '年假' and allocation.state == 'validate': employee = allocation.employee_id days = allocation.number_of_hours_display employee.write({ @@ -118,11 +116,12 @@ class HrLeaveAllocation(models.Model): ('employee_id', '=', employee.id) ], limit=1) # 创建假期明细记录 - self.env['yuthon.vacation.line'].create({ + self.env['vacation.leave.line'].create({ 'vacation_id': reports_id.id, 'update_type': 'add', 'update_date': fields.Datetime.now(), 'update_lines': days, + 'allocation_type': 'allocation', 'text': allocation.name }) return allocation @@ -134,14 +133,15 @@ class HrLeaveAllocation(models.Model): 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['yuthon.vacation.line'].search([ + lines_to_delete = self.env['vacation.leave.line'].search([ ('vacation_id.employee_id', '=', employee.id), ('update_type', '=', 'add'), ('update_lines', '=', days), + ('allocation_type', '=', 'allocation'), ('text', '=', record.name) ]) if lines_to_delete: - lines_to_delete.unlink() + lines_to_delete.is_void = True employee.write({ 'quota_issued': employee.quota_issued - days }) diff --git a/yuthon_holiday/models/yuthon_vacation_reports.py b/yuthon_holiday/models/yuthon_vacation_reports.py index 5126a2aab..81725fea7 100644 --- a/yuthon_holiday/models/yuthon_vacation_reports.py +++ b/yuthon_holiday/models/yuthon_vacation_reports.py @@ -18,6 +18,22 @@ class YuthonVacationReports(models.Model): working_overtime = fields.Float(string='加班时', compute='_compute_working_overtime', store=True) meal_fee = fields.Integer(string="误餐次数", compute='_compute_meal_fee', store=True) + def vacation_delete(self): + vacation_ids = self.env["yuthon.vacation.reports"].browse( + self._context.get('active_ids', self._context.get('active_id'))) + for record in vacation_ids: + for leave in record.leave_ids: + leave.unlink() + for overtime in record.overtime_ids: + overtime.unlink() + for meal_fee in record.meal_fee_ids: + meal_fee.unlink() + record.write({ + 'leave': 0.0, + 'working_overtime': 0.0, + 'meal_fee': 0, + }) + @api.depends('leave_ids.update_lines', 'leave_ids.update_type') def _compute_leave(self): for record in self: @@ -132,10 +148,13 @@ class VacationLeaveLine(models.Model): _description = '年假明细' vacation_id = fields.Many2one('yuthon.vacation.reports', string='关联假期额度记录') + employee_id = fields.Many2one('hr.employee', string='员工') workflow_record_id = fields.Many2one('soong.workflow.record', string='流程') update_type= fields.Selection([('add', '增加'), ('reduce', '减少')], string='更新类型') update_date = fields.Date(string='更新时间') update_lines = fields.Float(string='更新额度') + is_void = fields.Boolean(string='是否作废') + allocation_type = fields.Selection([('vacation', '休假'), ('allocation', '分配')], string='分配类型') text = fields.Text(string='备注') @api.model @@ -148,9 +167,14 @@ class VacationLeaveLine(models.Model): """ sign = -1 if reverse else 1 employee = self.vacation_id.employee_id - employee.write({ - 'user_year': employee.user_year + self.update_lines * sign, - }) + if self.allocation_type == 'vacation': + employee.write({ + 'user_year': employee.user_year + self.update_lines * sign, + }) + else: + employee.write({ + 'quota_issued': employee.quota_issued + self.update_lines * sign, + }) def unlink(self): """删除记录时同步扣减员工加班时长""" @@ -162,6 +186,7 @@ class VacationOverline(models.Model): _description = '加班明细' vacation_id = fields.Many2one('yuthon.vacation.reports', string='关联假期额度记录') + employee_id = fields.Many2one('hr.employee', string='员工') workflow_record_id = fields.Many2one('soong.workflow.record', string='流程') update_type= fields.Selection([('add', '增加'), ('reduce', '减少')], string='更新类型') workday = fields.Float(string='工作日') @@ -169,6 +194,7 @@ class VacationOverline(models.Model): public_holidays = fields.Float(string='公休日') meal_number = fields.Integer(string='误餐次数') update_date = fields.Date(string='更新时间') + is_void = fields.Boolean(string='是否作废') text = fields.Text(string='备注') def _sync_to_employee(self, reverse=False): @@ -208,11 +234,13 @@ class VacationMealLine(models.Model): _description = '误餐明细' vacation_id = fields.Many2one('yuthon.vacation.reports', string='关联假期额度记录') + employee_id = fields.Many2one('hr.employee', string='员工') workflow_record_id = fields.Many2one('soong.workflow.record', string='流程') update_type= fields.Selection([('add', '增加'), ('reduce', '减少')], string='更新类型') update_date = fields.Date(string='更新时间') update_lines = fields.Float(string='更新额度') is_soon = fields.Boolean(string="流程修改") + is_void = fields.Boolean(string='是否作废', default=False) is_manual = fields.Boolean(string="手动修改") text = fields.Text(string='备注') diff --git a/yuthon_holiday/views/yuthon_vacation_reports_views.xml b/yuthon_holiday/views/yuthon_vacation_reports_views.xml index 1666d919e..73eb82485 100644 --- a/yuthon_holiday/views/yuthon_vacation_reports_views.xml +++ b/yuthon_holiday/views/yuthon_vacation_reports_views.xml @@ -21,43 +21,49 @@
+ - - + + + - - - + + + +