如何验证 'project.task.work' 模块中的 'hours' 字段

How to validate 'hours' field in 'project.task.work' module

我想验证 'hours' 字段,该字段不能超过 24hr.For 我在代码中为此编写的一个函数的验证是。

'hours': fields.float('Time Spent')

classtask_timemanage(models.Model): _inherit = 'project.task.work'

@api.multi
@api.onchange('hours')
def check_timing(self):
    self.r=0
    if self.hours > 00.00:
        if self.hours > 23.59:
            self.hours == self.r
            raise Warning('Please Enter the valid time')
    if self.hours < 0:
        self.hours == 0
        raise Warning('Please Enter the valid time')

功能正常问题是

示例:时间是 11:30 我的功能正在运行。 如果要给11:72 也是working.here 分钟不会比11:59 多。所以请帮助我。

You can change the condition to check

@api.multi
@api.onchange('hours')
def check_timing(self):
    self.r=0
    hours = str(self.hour)
    hour = int(hours.split(".")[0])
    minutes = int(hours.split(".")[1])
    if hour and minutes and hour <= 23 and minutes <= 59:
       #do your code
       pass
    else:
       raise Warning('Please Enter the valid time')