From 3b272e4f866283b001306615b84f25f54aa9788c 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, 25 Oct 2025 15:47:36 +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_hr_attendance/models/hr_attendance.py | 2 +-
.../models/yuthon_vacation_reports.py | 17 ++++----
yuthon_will_task/models/yuthon_will_task.py | 39 +++++++++++++++++++
.../views/yuthon_will_task_views.xml | 10 ++---
4 files changed, 53 insertions(+), 15 deletions(-)
diff --git a/yuthon_hr_attendance/models/hr_attendance.py b/yuthon_hr_attendance/models/hr_attendance.py
index 593a8fc6f..ecab501bf 100644
--- a/yuthon_hr_attendance/models/hr_attendance.py
+++ b/yuthon_hr_attendance/models/hr_attendance.py
@@ -69,7 +69,7 @@ class HrAttendance(models.Model):
"""
att_ids = self.sudo().env['hr.attendance']
# 补充假期橙色逻辑,班次逻辑
- for emp in self.sudo().env['hr.employee'].search([]):
+ for emp in self.sudo().env['hr.employee'].search([('user_state', '!=', 'withdraw')]):
test1 = att_ids.search([('current_data', '=', fields.Date.today()), ('employee_id', '=', emp.id)])
resource_user_ids = emp.resource_calendar_id.resource_user_ids.ids
is_resource_user = True if emp.id in resource_user_ids else False
diff --git a/yuthon_hr_attendance/models/yuthon_vacation_reports.py b/yuthon_hr_attendance/models/yuthon_vacation_reports.py
index 838b6860a..b9d63daee 100644
--- a/yuthon_hr_attendance/models/yuthon_vacation_reports.py
+++ b/yuthon_hr_attendance/models/yuthon_vacation_reports.py
@@ -178,10 +178,7 @@ class YuthonVacationReports(models.Model):
if rec.employee_id and rec.vacation_date:
year = rec.vacation_date.year
month = rec.vacation_date.month
- days_in_month = calendar.monthrange(year, month)[1]
month_start = date(year, month, 1)
- month_end = date(year, month, days_in_month)
- leave_days, holiday_days = rec._create_leave_record(rec.employee_id, month_start, month_end)
entry_date = rec.employee_id.entry_date
if not entry_date or month_start > entry_date:
start_day = 1
@@ -232,13 +229,17 @@ class YuthonVacationReports(models.Model):
actual_attendance = actual_attendance - total_leave_days - is_abnormal
+ employee = rec.employee_id
+ print(employee.name)
+ contract = employee.contract_id
+ is_outside = employee.user_role_id.name == '外派'
month_start = date(year, month, 1)
month_end = date(year, month, calendar.monthrange(year, month)[1])
- start_date = max(rec.employee_id.contract_id.date_start, month_start)
- if rec.employee_id.contract_id.date_end:
- end_date = min(rec.employee_id.contract_id.date_end, month_end)
- else:
- end_date = month_end
+ # 计算start_date:外派且无合同时用month_start,否则取合同开始日与month_start的最大值
+ start_date = month_start if (is_outside and not contract) else max(contract.date_start, month_start)
+ # 计算end_date:外派且无合同时用month_end;有合同且有结束日则取最小值;其他情况用month_end
+ end_date = month_end if (is_outside and not contract) else (min(contract.date_end, month_end) if contract.date_end else month_end)
+
leave_days, statutory_days = rec._create_leave_record(rec.employee_id, start_date, end_date)
probation_contract = self.env['hr.contract'].search([
('employee_id', '=', rec.employee_id.id),
diff --git a/yuthon_will_task/models/yuthon_will_task.py b/yuthon_will_task/models/yuthon_will_task.py
index a63ad7bba..e141f6ef9 100644
--- a/yuthon_will_task/models/yuthon_will_task.py
+++ b/yuthon_will_task/models/yuthon_will_task.py
@@ -82,6 +82,7 @@ class YuthonWillTask(models.Model):
document_ids = fields.Many2many('ir.attachment', string="附件")
address = fields.Char(string='地点')
start_date = fields.Date(string='开始日期', default=fields.Date.today)
+ task_time = fields.Char(string='任务时间', compute='_compute_task_time')
is_this_company = fields.Boolean(string='本公司', default=True)
task_state = fields.Selection([('will', '待办'), ('done', '已办'), ('cancel', '取消')], default='will', string='状态', store=True)
@@ -105,6 +106,44 @@ class YuthonWillTask(models.Model):
store=True, default=lambda self: [(6, 0, [self.env.user.id])]
)
+ @api.depends('start_date', 'request_hour_from', 'request_hour_to')
+ def _compute_task_time(self):
+ for record in self:
+ date_str = ""
+ if record.start_date:
+ date_str = record.start_date.strftime("%Y/%m/%d")
+ hour_mapping = {
+ '0': '0:00', '0.5': '0:30',
+ '1': '01:00', '1.5': '01:30',
+ '2': '02:00', '2.5': '02:30',
+ '3': '03:00', '3.5': '03:30',
+ '4': '04:00', '4.5': '04:30',
+ '5': '05:00', '5.5': '05:30',
+ '6': '06:00', '6.5': '06:30',
+ '7': '07:00', '7.5': '07:30',
+ '8': '08:00', '8.5': '08:30',
+ '9': '09:00', '9.5': '09:30',
+ '10': '10:00', '10.5': '10:30',
+ '11': '11:00', '11.5': '11:30',
+ '12': '12:00', '12.5': '12:30',
+ '13': '13:00', '13.5': '13:30',
+ '14': '14:00', '14.5': '14:30',
+ '15': '15:00', '15.5': '15:30',
+ '16': '16:00', '16.5': '16:30',
+ '17': '17:00', '17.5': '17:30',
+ '18': '18:00', '18.5': '18:30',
+ '19': '19:00', '19.5': '19:30',
+ '20': '20:00', '20.5': '20:30',
+ '21': '21:00', '21.5': '21:30',
+ '22': '22:00', '22.5': '22:30',
+ '23': '23:00', '23.5': '23:30'
+ }
+ from_time = hour_mapping.get(record.request_hour_from, "")
+ to_time = hour_mapping.get(record.request_hour_to, "")
+ if date_str and from_time and to_time:
+ record.task_time = f"{date_str} ({from_time}--{to_time})"
+ else:
+ record.task_time = ""
@api.onchange('employee_ids', 'user_id')
def _onchange_employee_ids(self):
diff --git a/yuthon_will_task/views/yuthon_will_task_views.xml b/yuthon_will_task/views/yuthon_will_task_views.xml
index 63debe02d..963f40a99 100644
--- a/yuthon_will_task/views/yuthon_will_task_views.xml
+++ b/yuthon_will_task/views/yuthon_will_task_views.xml
@@ -10,9 +10,8 @@
decoration-info="priority == 'urgent'"
decoration-primary="priority == 'general'"
decoration-success="priority == 'important'">
-
-
-
+
+
@@ -122,9 +121,8 @@
decoration-info="priority == 'urgent'"
decoration-primary="priority == 'general'"
decoration-success="priority == 'important'" create="false" edit="false" js_class="custom_task_tree_button">
-
-
-
+
+