From 58cc45f8079490a3d0eae1fc440d024703889ddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= Date: Mon, 9 Mar 2026 11:43:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E7=A8=8B=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yuthon_will_task/models/yuthon_will_task.py | 94 +++++++++---------- .../views/yuthon_will_task_views.xml | 7 +- 2 files changed, 48 insertions(+), 53 deletions(-) diff --git a/yuthon_will_task/models/yuthon_will_task.py b/yuthon_will_task/models/yuthon_will_task.py index c4f39832c..3b3f28838 100644 --- a/yuthon_will_task/models/yuthon_will_task.py +++ b/yuthon_will_task/models/yuthon_will_task.py @@ -125,56 +125,54 @@ class YuthonWillTask(models.Model): for record in will_ids: record._check_task_time() - @api.constrains('start_date', 'request_hour_from', 'request_hour_to', 'task_type', 'room_booking_id') + @api.constrains('start_date', 'request_hour_from', 'request_hour_to') def _check_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.25': '0:15', '0.5': '0:30', '0.75': '0:45', - '1': '01:00', '1.25': '01:15', '1.5': '01:30', '1.75': '01:45', - '2': '02:00', '2.25': '02:15', '2.5': '02:30', '2.75': '02:45', - '3': '03:00', '3.25': '03:15', '3.5': '03:30', '3.75': '03:45', - '4': '04:00', '4.25': '04:15', '4.5': '04:30', '4.75': '04:45', - '5': '05:00', '5.25': '05:15', '5.5': '05:30', '5.75': '05:45', - '6': '06:00', '6.25': '06:15', '6.5': '06:30', '6.75': '06:45', - '7': '07:00', '7.25': '07:15', '7.5': '07:30', '7.75': '07:45', - '8': '08:00', '8.25': '08:15', '8.5': '08:30', '8.75': '08:45', - '9': '09:00', '9.25': '09:15', '9.5': '09:30', '9.75': '09:45', - '10': '10:00', '10.25': '10:15', '10.5': '10:30', '10.75': '10:45', - '11': '11:00', '11.25': '11:15', '11.5': '11:30', '11.75': '11:45', - '12': '12:00', '12.25': '12:15', '12.5': '12:30', '12.75': '12:45', - '13': '13:00', '13.25': '13:15', '13.5': '13:30', '13.75': '13:45', - '14': '14:00', '14.25': '14:15', '14.5': '14:30', '14.75': '14:45', - '15': '15:00', '15.25': '15:15', '15.5': '15:30', '15.75': '15:45', - '16': '16:00', '16.25': '16:15', '16.5': '16:30', '16.75': '16:45', - '17': '17:00', '17.25': '17:15', '17.5': '17:30', '17.75': '17:45', - '18': '18:00', '18.25': '18:15', '18.5': '18:30', '18.75': '18:45', - '19': '19:00', '19.25': '19:15', '19.5': '19:30', '19.75': '19:45', - '20': '20:00', '20.25': '20:15', '20.5': '20:30', '20.75': '20:45', - '21': '21:00', '21.25': '21:15', '21.5': '21:30', '21.75': '21:45', - '22': '22:00', '22.25': '22:15', '22.5': '22:30', '22.75': '22:45', - '23': '23:00', '23.25': '23:15', '23.5': '23:30', '23.75': '23:45' - } - 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: - # 当类型为会议且关联了会议室预订时,拼接结束时间 - if record.task_type == 'meet' and record.room_booking_id: - # 获取会议室预订的结束时间(本地时间 UTC+8) - stop_datetime = record.room_booking_id.stop_datetime - if stop_datetime: - # 转换为本地时间 - local_stop = stop_datetime + timedelta(hours=8) - stop_time_str = local_stop.strftime("%H:%M") - record.task_time = f"{date_str} {record.task_week} {from_time}-{stop_time_str}" - else: - record.task_time = f"{date_str} {record.task_week} {from_time}" - else: - record.task_time = f"{date_str} {record.task_week} {from_time}" + record._compute_task_time_value() + + def _compute_task_time_value(self): + """计算并写入 task_time 字段""" + date_str = "" + if self.start_date: + date_str = self.start_date.strftime("%Y/%m/%d") + hour_mapping = { + '0': '0:00', '0.25': '0:15', '0.5': '0:30', '0.75': '0:45', + '1': '01:00', '1.25': '01:15', '1.5': '01:30', '1.75': '01:45', + '2': '02:00', '2.25': '02:15', '2.5': '02:30', '2.75': '02:45', + '3': '03:00', '3.25': '03:15', '3.5': '03:30', '3.75': '03:45', + '4': '04:00', '4.25': '04:15', '4.5': '04:30', '4.75': '04:45', + '5': '05:00', '5.25': '05:15', '5.5': '05:30', '5.75': '05:45', + '6': '06:00', '6.25': '06:15', '6.5': '06:30', '6.75': '06:45', + '7': '07:00', '7.25': '07:15', '7.5': '07:30', '7.75': '07:45', + '8': '08:00', '8.25': '08:15', '8.5': '08:30', '8.75': '08:45', + '9': '09:00', '9.25': '09:15', '9.5': '09:30', '9.75': '09:45', + '10': '10:00', '10.25': '10:15', '10.5': '10:30', '10.75': '10:45', + '11': '11:00', '11.25': '11:15', '11.5': '11:30', '11.75': '11:45', + '12': '12:00', '12.25': '12:15', '12.5': '12:30', '12.75': '12:45', + '13': '13:00', '13.25': '13:15', '13.5': '13:30', '13.75': '13:45', + '14': '14:00', '14.25': '14:15', '14.5': '14:30', '14.75': '14:45', + '15': '15:00', '15.25': '15:15', '15.5': '15:30', '15.75': '15:45', + '16': '16:00', '16.25': '16:15', '16.5': '16:30', '16.75': '16:45', + '17': '17:00', '17.25': '17:15', '17.5': '17:30', '17.75': '17:45', + '18': '18:00', '18.25': '18:15', '18.5': '18:30', '18.75': '18:45', + '19': '19:00', '19.25': '19:15', '19.5': '19:30', '19.75': '19:45', + '20': '20:00', '20.25': '20:15', '20.5': '20:30', '20.75': '20:45', + '21': '21:00', '21.25': '21:15', '21.5': '21:30', '21.75': '21:45', + '22': '22:00', '22.25': '22:15', '22.5': '22:30', '22.75': '22:45', + '23': '23:00', '23.25': '23:15', '23.5': '23:30', '23.75': '23:45' + } + from_time = hour_mapping.get(self.request_hour_from, "") + if date_str and from_time and self.task_week: + base_time = f"{date_str} {self.task_week} {from_time}" + # 会议类型:拼接结束时间 + if self.task_type == 'meet' and self.room_booking_id and self.room_booking_id.stop_datetime: + stop_local = self.room_booking_id.stop_datetime + timedelta(hours=8) + stop_str = stop_local.strftime("%H:%M") + self.task_time = f"{base_time}-{stop_str}" else: - record.task_time = "" + self.task_time = base_time + else: + self.task_time = "" @api.onchange('employee_ids', 'user_id') def _onchange_employee_ids(self): @@ -288,7 +286,7 @@ class YuthonWillTask(models.Model): def write(self, vals): """修改日程时,先删除旧提醒任务,再创建新的""" res = super(YuthonWillTask, self).write(vals) - key_fields = ['start_date', 'request_hour_from', 'task_time_ids', 'employee_ids', 'employee_ids2'] + key_fields = ['start_date', 'request_hour_from', 'task_time_ids', 'employee_ids', 'employee_ids2', 'task_type', 'room_booking_id'] if any(field in vals for field in key_fields): self._sync_dates_task() return res diff --git a/yuthon_will_task/views/yuthon_will_task_views.xml b/yuthon_will_task/views/yuthon_will_task_views.xml index d51183866..3bf830273 100644 --- a/yuthon_will_task/views/yuthon_will_task_views.xml +++ b/yuthon_will_task/views/yuthon_will_task_views.xml @@ -11,8 +11,7 @@ decoration-success="priority == 'important'" limit="15" action="open_record" type="object"> - - + @@ -134,9 +133,7 @@ decoration-success="priority == 'important'" create="false" edit="false" js_class="custom_task_tree_button" limit="15"> - - - +