From 3d881f27c529737f98ce83b512dc7afb4af063e6 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: Wed, 15 Apr 2026 20:57:03 +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 --- .../models/vacation_overtime_active.py | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/yuthon_hr_attendance/models/vacation_overtime_active.py b/yuthon_hr_attendance/models/vacation_overtime_active.py index 54f355a2c..25998e64d 100644 --- a/yuthon_hr_attendance/models/vacation_overtime_active.py +++ b/yuthon_hr_attendance/models/vacation_overtime_active.py @@ -165,17 +165,21 @@ class VacationOvertimeActive(models.Model): def open_record(self): self.ensure_one() import datetime + import math + year = int(self.select_year) month = int(self.select_month) + # 计算当月月底 if month == 12: last_day_date = datetime.date(year, 12, 31) else: next_month_first = datetime.date(year, month + 1, 1) last_day_date = next_month_first - datetime.timedelta(days=1) - last_day = last_day_date.strftime("%Y-%m-%d") - domain = [ + + # 原始完整条件 + original_domain = [ ('over_line_id.vacation_id.employee_id', '=', self.employee_id.id), ('is_void', '=', False), '|', @@ -187,6 +191,21 @@ class VacationOvertimeActive(models.Model): ('leave_id.start_date', '>', last_day), ] + # 1. 先查询,计算总和 + records = self.env['overtime.carryover'].search(original_domain) + total = sum(r.carry_forward_quantity for r in records) + + if math.isclose(total, self.carry_forward_quantity, abs_tol=1e-9): + final_domain = original_domain + else: + final_domain = [ + ('over_line_id.vacation_id.employee_id', '=', self.employee_id.id), + ('is_void', '=', False), + ('carryover_type', '=', 'fee'), + ('carry_forward_date', '=', self.carry_forward_date), + ] + + # 打开视图 view_id = self.env.ref('yuthon_hr_attendance.view_overtime_carryover_tree1').id return { 'name': f'加班明细', @@ -194,6 +213,6 @@ class VacationOvertimeActive(models.Model): 'res_model': 'overtime.carryover', 'view_mode': 'tree', 'view_id': view_id, - 'domain': domain, + 'domain': final_domain, 'target': 'current', }