This commit is contained in:
李鹏宇
2026-04-28 16:37:01 +08:00
parent c19268e584
commit cdd9de16af
2 changed files with 25 additions and 2 deletions
+23 -1
View File
@@ -11,7 +11,7 @@ class YuthonWillTask(models.Model):
_name = 'yuthon.will.task'
_description = '日程'
_rec_name = 'name'
_order = 'request_hour_from desc'
_order = 'task_datetime desc'
time_list = [
('0', '0:00'), ('0.25', '0:15'), ('0.5', '0:30'), ('0.75', '0:45'),
@@ -71,6 +71,7 @@ class YuthonWillTask(models.Model):
start_date = fields.Date(string='开始日期', default=fields.Date.today)
end_date = fields.Date(string='结束日期', default=fields.Date.today)
task_time = fields.Char(string='任务时间', compute='_compute_task_time', store=True)
task_datetime = fields.Datetime(string='任务时间排序', compute='_compute_task_datetime', store=True)
is_this_company = fields.Boolean(string='本公司', default=True)
task_state = fields.Selection([('will', '待办'), ('done', '已办'), ('cancel', '取消')], default='will', string='状态', store=True)
@@ -166,6 +167,27 @@ class YuthonWillTask(models.Model):
for record in will_ids:
record._compute_task_time()
@api.depends('start_date', 'request_hour_from')
def _compute_task_datetime(self):
"""将 start_date + request_hour_from 拼合为 Datetime,用于排序"""
for record in self:
if record.start_date and record.request_hour_from:
try:
hour_float = float(record.request_hour_from)
hours = int(hour_float)
minutes = int(round((hour_float - hours) * 60))
# 存储时转为UTC(界面显示是UTC+8,存储需减8小时)
record.task_datetime = datetime(
record.start_date.year,
record.start_date.month,
record.start_date.day,
hours, minutes, 0
) - timedelta(hours=8)
except Exception:
record.task_datetime = False
else:
record.task_datetime = False
@api.depends('start_date', 'task_week', 'request_hour_from', 'task_type', 'room_booking_id', 'room_booking_id.start_datetime', 'room_booking_id.stop_datetime')
def _compute_task_time(self):
for record in self:
@@ -152,7 +152,8 @@
decoration-danger="priority == 'very_urgent'"
decoration-info="priority == 'urgent'"
decoration-success="priority == 'important'" create="false" edit="false"
js_class="custom_task_tree_button" limit="15">
js_class="custom_task_tree_button" limit="15" default_order="task_datetime desc">
<field name='task_datetime' column_invisible="1"/>
<field name='start_date' column_invisible="1"/>
<field name='task_time'/>
<field name='name' required="1"/>