From c5766359049ddb8e5697995d772ad21d507ab367 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: Sat, 18 Apr 2026 23:59:32 +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/overtime_carryover.py | 44 ---------------
.../models/vacation_overtime_active.py | 56 ++++++-------------
.../models/yuthon_overtime_line.py | 33 +----------
.../models/yuthon_vacation_reports.py | 26 ++++-----
.../views/overtime_carryover_views.xml | 11 ++--
.../views/yuthon_overtime_line_views.xml | 6 +-
.../wizard/vacation_overtime_active_wizard.py | 7 +--
7 files changed, 42 insertions(+), 141 deletions(-)
diff --git a/yuthon_hr_attendance/models/overtime_carryover.py b/yuthon_hr_attendance/models/overtime_carryover.py
index 0cc96db9c..e2a37407a 100644
--- a/yuthon_hr_attendance/models/overtime_carryover.py
+++ b/yuthon_hr_attendance/models/overtime_carryover.py
@@ -17,14 +17,7 @@ class OvertimeCarryover(models.Model):
carry_result = fields.Selection(related='over_line_id.carry_result', string='结转结果', store=True)
over_line_id1 = fields.Many2one('vacation.over.line', string='加班记录(销假)')
carry_forward_date = fields.Date(string="结转日期")
- # carry_forward_date1 = fields.Date(string="动态结转日期")
carry_forward_quantity = fields.Float(string="结转时长")
- carry_forward_quantity1 = fields.Float(
- string="动态结转时长",
- compute="_compute_carry_forward_leave_total",
- store=False,
- )
- duration1 = fields.Float(string='动态时长')
last_month = fields.Float(string="上月剩余")
this_month = fields.Float(string="本月结余")
is_void = fields.Boolean(string='作废')
@@ -33,43 +26,6 @@ class OvertimeCarryover(models.Model):
leave_id = fields.Many2one('hr.leave.batch', string='请假单')
text = fields.Text(string='备注')
- @api.depends('over_line_id.carry_forward_quantity', 'over_line_id.carryover_ids.carry_forward_date',
- 'carry_forward_date')
- def _compute_carry_forward_leave_total(self):
- for record in self:
- total = 0.0
- record.carry_forward_quantity1 = 0.0
- main_date = record.carry_forward_date
- if not main_date or not record.over_line_id.carryover_ids:
- continue
- first_day = main_date.replace(day=1)
- last_day = fields.Date.end_of(first_day, 'month')
- for line in record.over_line_id.carryover_ids:
- line_date = line.carry_forward_date
- if not line_date:
- continue
- if first_day <= line_date <= last_day and not line.is_void:
- total += line.carry_forward_quantity
-
- if record.over_line_id.is_initial_number:
- previous_month_date = first_day - timedelta(days=1)
- last_month_first_day = previous_month_date.replace(day=1)
- vacation_report = self.env['yuthon.vacation.reports'].search([
- ('vacation_date', '=', last_month_first_day),
- ('employee_id', '=', record.employee_id.id)
- ], limit=1)
- if vacation_report:
- dynamic_previous_year1 = vacation_report.dynamic_previous_year1 or 0.0
- this_year1 = vacation_report.this_year1 or 0.0
- sum_year = dynamic_previous_year1 + this_year1
- if sum_year * 8 > 40:
- prev_year_hours = dynamic_previous_year1 * 8
- if prev_year_hours >= sum_year * 8 - 40:
- total = sum_year * 8 - 40
- else:
- total = prev_year_hours
- record.carry_forward_quantity1 = total
-
def open_record(self):
self.ensure_one()
return {
diff --git a/yuthon_hr_attendance/models/vacation_overtime_active.py b/yuthon_hr_attendance/models/vacation_overtime_active.py
index 4974ef04c..24322bb37 100644
--- a/yuthon_hr_attendance/models/vacation_overtime_active.py
+++ b/yuthon_hr_attendance/models/vacation_overtime_active.py
@@ -146,6 +146,7 @@ class VacationOvertimeActive(models.Model):
carryover_id = self.env['overtime.carryover'].search([
('carry_forward_date', '=', self.carry_forward_date),
('employee_id', '=', self.employee_id.id),
+ ('is_void', '!=', False),
('carryover_type', '=', 'fee'),])
if carryover_id:
carryover_id.is_void = True
@@ -177,55 +178,34 @@ class VacationOvertimeActive(models.Model):
def open_record(self):
self.ensure_one()
import datetime
- from datetime import timedelta
year = int(self.select_year)
month = int(self.select_month)
- first_day_of_month = datetime.date(year, month, 1)
+
if month == 12:
- last_day_of_month = datetime.date(year, 12, 31)
+ last_day_date = datetime.date(year, 12, 31)
else:
next_month_first = datetime.date(year, month + 1, 1)
- last_day_of_month = next_month_first - timedelta(days=1)
+ last_day_date = next_month_first - datetime.timedelta(days=1)
+ last_day = last_day_date.strftime("%Y-%m-%d")
+
+ # 只显示 fee,不显示 leave
final_domain = [
('over_line_id.vacation_id.employee_id', '=', self.employee_id.id),
('is_void', '=', False),
- ('carry_forward_date', '>=', first_day_of_month + relativedelta(months=1)),
- ('carry_forward_date', '<=', last_day_of_month + relativedelta(months=1)),
+ ('carryover_type', '=', 'fee'),
+ ('carry_forward_date', '=', self.carry_forward_date),
]
- all_records = self.env['overtime.carryover'].search(final_domain, order='start_time asc')
- over_line_dict = {}
- for record in all_records:
- over_line_id = record.over_line_id.id
- qty = record.carry_forward_quantity
- if over_line_id not in over_line_dict:
- over_line_dict[over_line_id] = record
- else:
- existing_qty = over_line_dict[over_line_id].carry_forward_quantity
- if qty > existing_qty:
- over_line_dict[over_line_id] = record
- carryover_ids = self.env['overtime.carryover'].concat(*over_line_dict.values())
- keep_ids = self.env['overtime.carryover'].browse()
- current_remaining = self.vacation_sum
- found_40 = False
+ carryover_ids = self.env['overtime.carryover'].search(final_domain, order='start_time asc')
if carryover_ids:
+ total_balance = self.vacation_sum
+ current_remaining = total_balance
for carry in carryover_ids:
- new_remaining = round(current_remaining - carry.carry_forward_quantity1, 2)
- if found_40:
- continue
- if new_remaining >= 40:
- carry.sudo().write({
- 'last_month': current_remaining,
- 'this_month': new_remaining,
- })
- keep_ids += carry
- current_remaining = new_remaining
- if new_remaining == 40:
- found_40 = True
- else:
- break
- carryover_ids = keep_ids
-
+ carry.sudo().write({
+ 'last_month': current_remaining,
+ 'this_month': current_remaining - carry.carry_forward_quantity,
+ })
+ current_remaining = carry.this_month
view_id = self.env.ref('yuthon_hr_attendance.view_overtime_carryover_tree1').id
return {
'name': '加班明细',
@@ -233,6 +213,6 @@ class VacationOvertimeActive(models.Model):
'res_model': 'overtime.carryover',
'view_mode': 'tree',
'view_id': view_id,
- 'domain': [('id', 'in', carryover_ids.ids)],
+ 'domain': final_domain,
'target': 'current',
}
diff --git a/yuthon_hr_attendance/models/yuthon_overtime_line.py b/yuthon_hr_attendance/models/yuthon_overtime_line.py
index 1c896312b..36b21ee55 100644
--- a/yuthon_hr_attendance/models/yuthon_overtime_line.py
+++ b/yuthon_hr_attendance/models/yuthon_overtime_line.py
@@ -23,41 +23,12 @@ class YuthonOvertimeLine(models.Model):
workday = fields.Float(string='工作日')
public_holidays = fields.Float(string='公休日')
remainder_year = fields.Float(string='本年剩余')
- vacation_sum = fields.Float(string='合计数', compute='_compute_vacation_sum', store=True)
- vacation_sum1 = fields.Float(string='合计数') # 动态合计数
+ vacation_sum = fields.Float(string='合计数') # 动态合计数
carry_forward_quantity = fields.Float(string="已结转")
carry_forward_date = fields.Date(string="结转日期")
archive_state = fields.Selection([('to_do', '待归档'), ('done', '已归档')], default='to_do', string='状态')
remaining_quantity = fields.Float(string="剩余数")
- @api.depends('last_balance', 'remainder_year')
- def _compute_vacation_sum(self):
- for rec in self:
- rec.vacation_sum = 0.0
- current_year = int(rec.select_year)
- current_month = int(rec.select_month)
- next_month = current_month + 1 if current_month < 12 else 1
- next_year = current_year if current_month < 12 else current_year + 1
- cutoff_date_last = date(next_year, next_month, 1) - timedelta(days=1)
- cutoff_dt = datetime.combine(cutoff_date_last, datetime.max.time())
- dec_2025_end = datetime(2025, 12, 31, 23, 59, 59)
- if rec.employee_id.company_id.name == '集团本部':
- domain = [
- ('employee_id', '=', rec.employee_id.id),
- ('carry_forward_state', '!=', 'completed'),
- '|',
- ('is_initial_number', '=', True),
- '&', ('is_initial_number', '=', False),
- '&', ('update_type', '=', 'add'),
- '&', ('workflow_record_id', '!=', False),
- '&', ('start_time', '>=', dec_2025_end),
- '&', ('vacation_id', '!=', False),
- ('start_time', '<', cutoff_dt)
- ]
- over_ids = rec.env['vacation.over.line'].search(domain)
- for over_id in over_ids:
- rec.vacation_sum += over_id.remaining_quantity
-
def open_record(self):
self.ensure_one()
current_year = int(self.select_year)
@@ -109,7 +80,7 @@ class YuthonOvertimeLine(models.Model):
@api.model
def carryover_details(self):
- domain = [('vacation_sum1', '>', 40.1),
+ domain = [('vacation_sum', '>', 40.1),
('employee_id.company_id.name', '=', '集团本部'),
]
overtime_lines = self.env['yuthon.overtime.line'].search(domain)
diff --git a/yuthon_hr_attendance/models/yuthon_vacation_reports.py b/yuthon_hr_attendance/models/yuthon_vacation_reports.py
index 46e7ddd4f..6e9c43c3c 100644
--- a/yuthon_hr_attendance/models/yuthon_vacation_reports.py
+++ b/yuthon_hr_attendance/models/yuthon_vacation_reports.py
@@ -2020,7 +2020,6 @@ class YuthonVacationReports(models.Model):
'&', ('start_time', '>=', dec_2025_end),
'&', ('vacation_id', '!=', False),
('start_time', '<=', current_date),
- ('carry_forward_state', '!=', 'completed'),
('employee_id.is_annual_salary', '!=', True)
]
all_records = self.env['vacation.over.line'].search(domain)
@@ -2040,7 +2039,7 @@ class YuthonVacationReports(models.Model):
],
limit=1 # 避免多条记录,只取第一条
)
- vacation_sum1 = report_id.dynamic_previous_year1 * 8 + report_id.this_year1 * 8 if report_id else 0.0
+ vacation_sum = report_id.dynamic_previous_year1 * 8 + report_id.this_year1 * 8 if report_id else 0.0
active_id = self.env['vacation.overtime.active'].search(
[('employee_id', '=', emp_id),
('select_month', '=', str(last_month_first.month)),
@@ -2048,11 +2047,11 @@ class YuthonVacationReports(models.Model):
('select_revoke', '!=', 'done'),
])
if active_id:
- vacation_sum1 -= active_id.carry_forward_quantity
+ vacation_sum -= active_id.carry_forward_quantity
employee_summary[emp_id] = {
'employee_id': emp_id,
'valid_date': line.valid_date,
- 'vacation_sum1': vacation_sum1,
+ 'vacation_sum': vacation_sum,
'last_balance': report_id.dynamic_previous_year1 * 8 if report_id else 0.0,
'remainder_year': 0.0,
'carry_forward_quantity': 0.0,
@@ -2098,7 +2097,6 @@ class YuthonVacationReports(models.Model):
'&', ('start_time', '>=', dec_2025_end),
'&', ('vacation_id', '!=', False),
('start_time', '<=', current_date),
- ('carry_forward_state', '!=', 'completed'),
('employee_id.is_annual_salary', '!=', True)
]
all_records = self.env['vacation.over.line'].search(domain)
@@ -2118,7 +2116,7 @@ class YuthonVacationReports(models.Model):
],
limit=1 # 避免多条记录,只取第一条
)
- vacation_sum1 = report_id.dynamic_previous_year1 * 8 + report_id.this_year1 * 8 if report_id else 0.0
+ vacation_sum = report_id.dynamic_previous_year1 * 8 + report_id.this_year1 * 8 if report_id else 0.0
active_id = self.env['vacation.overtime.active'].search(
[('employee_id', '=', emp_id),
('select_month', '=', str(last_month_first.month)),
@@ -2126,11 +2124,11 @@ class YuthonVacationReports(models.Model):
('select_revoke', '!=', 'done'),
])
if active_id:
- vacation_sum1 -= active_id.carry_forward_quantity
+ vacation_sum -= active_id.carry_forward_quantity
employee_summary[emp_id] = {
'employee_id': emp_id,
'valid_date': line.valid_date,
- 'vacation_sum1': vacation_sum1,
+ 'vacation_sum': vacation_sum,
'last_balance': report_id.dynamic_previous_year1 * 8 if report_id else 0.0,
'remainder_year': 0.0,
'carry_forward_quantity': 0.0,
@@ -2200,7 +2198,7 @@ class YuthonVacationReports(models.Model):
],
limit=1 # 避免多条记录,只取第一条
)
- vacation_sum1 = report_id.dynamic_previous_year1 * 8 + report_id.this_year1 * 8 if report_id else 0.0
+ vacation_sum = report_id.dynamic_previous_year1 * 8 + report_id.this_year1 * 8 if report_id else 0.0
active_id = self.env['vacation.overtime.active'].search(
[('employee_id', '=', emp_id),
('select_month', '=', str(last_month_first.month)),
@@ -2208,11 +2206,11 @@ class YuthonVacationReports(models.Model):
('select_revoke', '!=', 'done'),
])
if active_id:
- vacation_sum1 -= active_id.carry_forward_quantity
+ vacation_sum -= active_id.carry_forward_quantity
employee_summary[emp_id] = {
'employee_id': emp_id,
'valid_date': line.valid_date,
- 'vacation_sum1':vacation_sum1,
+ 'vacation_sum':vacation_sum,
'last_balance': report_id.dynamic_previous_year1 * 8 if report_id else 0.0,
'remainder_year': 0.0,
'carry_forward_quantity': 0.0,
@@ -2517,10 +2515,10 @@ class VacationOverline(models.Model):
leave_id = fields.Many2one('hr.leave', string='假单')
is_visible = fields.Boolean(string='是否隐藏')
update_type= fields.Selection([('add', '增加'), ('reduce', '减少')], string='更新类型')
- workday = fields.Float(string='工作日h', digits=(16, 1))
+ workday = fields.Float(string='工作日h', digits=(16, 3))
last_balance = fields.Float(string='上年结余', compute='_compute_last_balance', store=True)
- legal_day = fields.Float(string='法定节假日h', digits=(16, 1))
- public_holidays = fields.Float(string='公休日h', digits=(16, 1))
+ legal_day = fields.Float(string='法定节假日h', digits=(16, 3))
+ public_holidays = fields.Float(string='公休日h', digits=(16, 3))
meal_number = fields.Integer(string='误餐次数')
update_date = fields.Date(string='更新时间')
is_void = fields.Boolean(string='是否作废')
diff --git a/yuthon_hr_attendance/views/overtime_carryover_views.xml b/yuthon_hr_attendance/views/overtime_carryover_views.xml
index 64f40fc31..2a24376a7 100644
--- a/yuthon_hr_attendance/views/overtime_carryover_views.xml
+++ b/yuthon_hr_attendance/views/overtime_carryover_views.xml
@@ -4,7 +4,7 @@
overtime.carryover.tree
overtime.carryover
-
+
@@ -26,7 +26,7 @@
overtime.carryover.tree1
overtime.carryover
-
+
@@ -34,11 +34,10 @@
-
-
+
+
-
-
+
diff --git a/yuthon_hr_attendance/views/yuthon_overtime_line_views.xml b/yuthon_hr_attendance/views/yuthon_overtime_line_views.xml
index e55def9b4..c41b76fb0 100644
--- a/yuthon_hr_attendance/views/yuthon_overtime_line_views.xml
+++ b/yuthon_hr_attendance/views/yuthon_overtime_line_views.xml
@@ -14,8 +14,7 @@
-
-
+
@@ -35,8 +34,7 @@
-
-
+
diff --git a/yuthon_hr_attendance/wizard/vacation_overtime_active_wizard.py b/yuthon_hr_attendance/wizard/vacation_overtime_active_wizard.py
index 53b0b1999..89eb18382 100644
--- a/yuthon_hr_attendance/wizard/vacation_overtime_active_wizard.py
+++ b/yuthon_hr_attendance/wizard/vacation_overtime_active_wizard.py
@@ -34,11 +34,10 @@ class VacationOvertimeActiveWizard(models.TransientModel):
'select_year': overtime_id.select_year,
'last_balance': overtime_id.last_balance,
'valid_date': overtime_id.valid_date,
- 'vacation_sum': round(overtime_id.vacation_sum1, 2),
- 'carry_forward_quantity': round(overtime_id.vacation_sum1, 2) - 40,
+ 'vacation_sum': round(overtime_id.vacation_sum, 2),
+ 'carry_forward_quantity': round(overtime_id.vacation_sum, 2) - 40,
'carry_forward_date': self.filing_date,
})
- overtime_id._compute_vacation_sum()
remaining_to_allocate = round(overtime_id.vacation_sum, 2) - 40
current_year = int(overtime_id.select_year)
current_month = int(overtime_id.select_month)
@@ -76,7 +75,7 @@ class VacationOvertimeActiveWizard(models.TransientModel):
('overtime_methods', '=', 'fee'),
], limit=1)
if not existing_over_line:
- workday_value = round(overtime_id.vacation_sum1, 2) - 40
+ workday_value = round(overtime_id.vacation_sum, 2) - 40
self.env['vacation.over.line'].create({
'vacation_id': report_id.id,
'employee_id': overtime_id.employee_id.id,