diff --git a/yuthon_will_task/models/yuthon_will_task.py b/yuthon_will_task/models/yuthon_will_task.py index bb7a0287a..8b92147ea 100644 --- a/yuthon_will_task/models/yuthon_will_task.py +++ b/yuthon_will_task/models/yuthon_will_task.py @@ -1,7 +1,7 @@ from odoo import api, fields, models, modules import datetime from datetime import datetime, timedelta, time -from odoo.exceptions import UserError +from odoo.exceptions import UserError, ValidationError import logging _logger = logging.getLogger(__name__) @@ -49,8 +49,8 @@ class YuthonWillTask(models.Model): hour = (now.hour + 1) % 24 return str(hour) - request_hour_from = fields.Selection(time_list, string='开始时间') - request_hour_to = fields.Selection(time_list, string='结束时间') + request_hour_from = fields.Selection(time_list, string='开始时间', default=_default_request_hour_from) + request_hour_to = fields.Selection(time_list, string='结束时间', default=_default_request_hour_to) priority = fields.Selection([('important', '重要不紧急'), ('urgent', '紧急不重要'), ('very_urgent', '重要且紧急')], string='优先级') code = fields.Char(string="任务编号", default=lambda self: self.env['ir.sequence'].next_by_code('task_code')) user_id = fields.Many2one('res.users', string="创建人", default=lambda self: self.env.user) @@ -67,6 +67,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) + end_date = fields.Date(string='结束日期', default=fields.Date.today) task_time = fields.Char(string='任务时间', compute='_compute_task_time', store=True) is_this_company = fields.Boolean(string='本公司', default=True) task_state = fields.Selection([('will', '待办'), ('done', '已办'), ('cancel', '取消')], default='will', string='状态', store=True) @@ -87,6 +88,14 @@ class YuthonWillTask(models.Model): ], string='类型', default='task') room_booking_id = fields.Many2one('room.booking', string='会议室') + @api.onchange('start_date', 'end_date') + def _onchange_date_range(self): + if self.start_date and self.end_date: + start = fields.Datetime.from_string(self.start_date) + end = fields.Datetime.from_string(self.end_date) + if start > end: + raise ValidationError("开始日期必须小于结束日期,请重新设置。") + def back_wecom_msg(self): self.env['wecom.apps'].back_message(category='task', msg_id=self.msg_id) diff --git a/yuthon_will_task/views/yuthon_will_task_views.xml b/yuthon_will_task/views/yuthon_will_task_views.xml index 28a162554..44253ecf2 100644 --- a/yuthon_will_task/views/yuthon_will_task_views.xml +++ b/yuthon_will_task/views/yuthon_will_task_views.xml @@ -69,6 +69,7 @@ +
@@ -90,7 +91,7 @@ - + + + @@ -184,6 +195,7 @@ +
@@ -205,12 +217,22 @@ - + + +