From d65cc9952255fdba85ec49e3a1a1ecdb6fa1593a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= <9664676+pengyuthon@user.noreply.gitee.com> Date: Fri, 30 Jan 2026 18:09:01 +0800 Subject: [PATCH 1/2] =?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 | 113 +++++++----------- .../models/yuthon_vacation_reports.py | 6 +- 2 files changed, 47 insertions(+), 72 deletions(-) diff --git a/yuthon_holiday/models/inherit_hr_leave.py b/yuthon_holiday/models/inherit_hr_leave.py index c4890c521..024c0ecbb 100644 --- a/yuthon_holiday/models/inherit_hr_leave.py +++ b/yuthon_holiday/models/inherit_hr_leave.py @@ -518,17 +518,10 @@ class HolidaysRequestBatch(models.Model): return date_ranges def _create_overtime_leave_line(self, period_start, leave_data, hours, period, leave_type_name): - """为补休类型创建加班明细行(vacation.over.line),类型为减少,值赋给workday(增加重复校验)""" - # 1. 计算报表月份的起始和结束日期,简化代码结构 - report_month = date(period_start.year, period_start.month, 1) - month_end = date(period_start.year, period_start.month, - calendar.monthrange(period_start.year, period_start.month)[1]) - - # 2. 查询对应的假期报表记录 + first_day = fields.Date.today().replace(day=1) vacation_report = self.env['yuthon.vacation.reports'].search([ ('employee_id', '=', self.users_id.employee_ids.id), - ('vacation_date', '>=', fields.Date.to_string(report_month)), - ('vacation_date', '<=', fields.Date.to_string(month_end)) + ('vacation_date', '=', first_day), ], limit=1) existing_overtime_line = self.env['vacation.over.line'].search([ ('employee_id', '=', self.users_id.employee_ids.id), @@ -583,13 +576,10 @@ class HolidaysRequestBatch(models.Model): def _create_annual_leave_line(self, period_start, leave_data, hours, period): """更新年假记录,使用小时作为单位(增加重复校验,避免重复创建)""" - report_month = date(period_start.year, period_start.month, 1) - month_end = date(period_start.year, period_start.month, - calendar.monthrange(period_start.year, period_start.month)[1]) + first_day = fields.Date.today().replace(day=1) vacation_report = self.env['yuthon.vacation.reports'].search([ ('employee_id', '=', self.users_id.employee_ids.id), - ('vacation_date', '>=', fields.Date.to_string(report_month)), - ('vacation_date', '<=', fields.Date.to_string(month_end)) + ('vacation_date', '=', first_day), ], limit=1) existing_annual_leave_line = self.env['vacation.leave.line'].search([ ('employee_id', '=', self.users_id.employee_ids.id), @@ -850,69 +840,50 @@ class HolidaysRequestBatch(models.Model): @api.depends('users_id') def _compute_holiday_allowance(self): current_date = fields.Date.today() - vacation_date = current_date + current_year = current_date.year + year_start = fields.Date.from_string(f"{current_year}-01-01") + year_end = fields.Date.from_string(f"{current_year}-12-31") + for record in self: - result_parts = [] - reports_id = self.env['yuthon.vacation.reports'].search([ - ('employee_id', '=', record.users_id.employee_ids.id), - ('vacation_date', '=', vacation_date.replace(day=1)) - ], limit=1) - if not reports_id: - record.holiday_allowance = "" + record.holiday_allowance = "年假0.000天, 补休0.000天, 育儿假0.000天" + if not record.users_id or not record.users_id.employee_ids: continue - holiday_configs = [ - ("年假", "previous_year", "year_distribution"), - ("补休", "previous_year1", "this_year1"), - ("育儿假", None, "remaining_parental_leave") - ] + employee = record.users_id.employee_ids[0] - for name, prev_field, curr_field in holiday_configs: - parts = [] - # ========== 核心修改:年假专属扣减逻辑 ========== - if name == "年假" and prev_field and curr_field: - used_this_year = getattr(reports_id, 'used_this_year', 0.0) # 本年已用 - prev_value = getattr(reports_id, prev_field, 0.0) # 上年结余(previous_year) - curr_value = getattr(reports_id, curr_field, 0.0) # 本年额度(year_distribution) - valid_date = getattr(reports_id, 'valid_date', None) # previous_year的有效期 + vacation_date = current_date.replace(day=1) # 当月1号 + reports_id = self.env['yuthon.vacation.reports'].search([ + ('employee_id', '=', employee.id), + ('vacation_date', '=', vacation_date) + ], limit=1) - is_prev_valid = True - if valid_date: - is_prev_valid = date.today() <= valid_date + # 3. 基础字段取值(年假、补休) + leave_days = reports_id.leave or 0.0 if reports_id else 0.0 + overtime_days = reports_id.working_overtime or 0.0 if reports_id else 0.0 + remaining_parental_leave = 0.0 + parental_leave_type = self.env['hr.leave.type'].search([ + ('name', 'ilike', '育儿假'), + ], limit=1) - remain_used = used_this_year - final_prev = prev_value - final_curr = curr_value + if parental_leave_type: + allocation_records = self.env['hr.leave.allocation'].search([ + ('employee_id', '=', employee.id), + ('holiday_status_id', '=', parental_leave_type.id), + ('state', 'in', ['validate', 'done']), + ('create_date', '>=', year_start), + ('create_date', '<=', year_end) + ]) + used_parental_leave_list = self.env['hr.leave'].search([ + ('employee_id', '=', employee.id), + ('holiday_status_id', '=', parental_leave_type.id), + ('date_from', '>=', year_start), + ('date_from', '<=', year_end) + ]) + allocation_records -= used_parental_leave_list + remaining_parental_leave = max(0.0, allocation_records) - if is_prev_valid and final_prev > 0 and remain_used > 0: - # 扣减previous_year:取剩余已用和previous_year的较小值 - deduct_prev = min(remain_used, final_prev) - final_prev -= deduct_prev - remain_used -= deduct_prev - - # 4. 剩余已用扣减year_distribution - if remain_used > 0 and final_curr > 0: - deduct_curr = min(remain_used, final_curr) - final_curr -= deduct_curr - remain_used -= deduct_curr - - # 5. 根据扣减后的值判断是否显示 - if final_prev > 0: - parts.append(f"上年结余{final_prev:.3f}天") - if final_curr > 0: - parts.append(f"本年剩余{final_curr:.3f}天") - else: - if prev_field: - prev_value = getattr(reports_id, prev_field, 0.0) - if prev_value > 0: - parts.append(f"上年结余{prev_value:.3f}天") - curr_value = getattr(reports_id, curr_field, 0.0) - if curr_value > 0: - parts.append(f"本年剩余{curr_value:.3f}天") - - if parts: - result_parts.append(f"{name}:{','.join(parts)}") - - record.holiday_allowance = "\n".join(result_parts) + record.holiday_allowance = ( + f"年假{leave_days:.3f}天, 补休{overtime_days:.3f}天, 育儿假{remaining_parental_leave:.3f}天" + ) def action_print_leave_batch(self): """按钮触发打印请假单""" diff --git a/yuthon_hr_attendance/models/yuthon_vacation_reports.py b/yuthon_hr_attendance/models/yuthon_vacation_reports.py index 30bb1fc15..c99b4f090 100644 --- a/yuthon_hr_attendance/models/yuthon_vacation_reports.py +++ b/yuthon_hr_attendance/models/yuthon_vacation_reports.py @@ -24,6 +24,8 @@ class YuthonVacationReports(models.Model): open_start_time = fields.Date(related='employee_id.open_start_time',string="参加工作时间") company_old = fields.Char(related='employee_id.company_old', string="工作年限") previous_year = fields.Float(string="上年剩余", digits=(16, 3)) # 固定值 + dynamic_previous_year = fields.Float(string="上年剩余", digits=(16, 3)) # 动态值 + dynamic_remainder_year = fields.Float(string="本年剩余", digits=(16, 3)) # 动态值 valid_date = fields.Date(string="有效期至") year_distribution = fields.Float(string="本年发放", digits=(16, 3)) used_this_year = fields.Float(string="本年已用", digits=(16, 3)) @@ -34,7 +36,8 @@ class YuthonVacationReports(models.Model): year_holiday = fields.Float(string="本年公休日", digits=(16, 3)) year_workday = fields.Float(string="本年工作日", digits=(16, 3)) year_sum = fields.Float(string="本年调休合计", digits=(16, 3), compute="_compute_year_sum") - previous_year1 = fields.Float(string="上年剩余(补休)", digits=(16, 3)) + previous_year1 = fields.Float(string="上年剩余(补休)", digits=(16, 3)) # 固定值 + dynamic_previous_year1 = fields.Float(string="上年剩余(补休)", digits=(16, 3)) # 动态值 this_year1 = fields.Float(string="本年剩余(补休)", digits=(16, 3), compute="_compute_year_sum") used_this_year1 = fields.Float(string="本年已休", digits=(16, 3)) remainder_year1 = fields.Float(string="剩余(补休)", digits=(16, 3), compute="_compute_year_sum") @@ -106,6 +109,7 @@ class YuthonVacationReports(models.Model): tracking=3, default='not_sent') + def update_overtime(self): today = date.today() over_line_domain = [ From eeba65b71d6a9c2c49c9125c0cace6fa9e96bedb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= <9664676+pengyuthon@user.noreply.gitee.com> Date: Fri, 30 Jan 2026 18:34:38 +0800 Subject: [PATCH 2/2] =?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 | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/yuthon_holiday/models/inherit_hr_leave.py b/yuthon_holiday/models/inherit_hr_leave.py index 024c0ecbb..d15f6e511 100644 --- a/yuthon_holiday/models/inherit_hr_leave.py +++ b/yuthon_holiday/models/inherit_hr_leave.py @@ -869,17 +869,23 @@ class HolidaysRequestBatch(models.Model): ('employee_id', '=', employee.id), ('holiday_status_id', '=', parental_leave_type.id), ('state', 'in', ['validate', 'done']), - ('create_date', '>=', year_start), - ('create_date', '<=', year_end) + ('date_from', '<=', current_date), + '|', + ('date_to', '=', False), + ('date_to', '>=', current_date) ]) + used_days = 0.0 used_parental_leave_list = self.env['hr.leave'].search([ ('employee_id', '=', employee.id), ('holiday_status_id', '=', parental_leave_type.id), - ('date_from', '>=', year_start), - ('date_from', '<=', year_end) + ('date_from', '>=', allocation_records.date_from), + ('date_to', '<=', allocation_records.date_to) ]) - allocation_records -= used_parental_leave_list - remaining_parental_leave = max(0.0, allocation_records) + for leave in used_parental_leave_list: + need_deduct = True + if need_deduct: + used_days += leave.number_of_days_display + remaining_parental_leave = max(0.0, allocation_records.number_of_days_display - used_days) record.holiday_allowance = ( f"年假{leave_days:.3f}天, 补休{overtime_days:.3f}天, 育儿假{remaining_parental_leave:.3f}天"