Python 在odoo中引发异常时,将日期字段设置为null
我已经验证了Python 在odoo中引发异常时,将日期字段设置为null,python,odoo-10,Python,Odoo 10,我已经验证了开始日期和结束日期。在引发错误时,我需要设置空的结束日期字段。这是我的密码: @api.onchange('end_date') def onchange_end_date(self, end_date, start_date): if (start_date and end_date) and (start_date < end_date): raise exceptions.except_orm(_('Warning!'),_('The start
开始日期
和结束日期
。在引发错误时,我需要设置空的结束日期字段。这是我的密码:
@api.onchange('end_date')
def onchange_end_date(self, end_date, start_date):
if (start_date and end_date) and (start_date < end_date):
raise exceptions.except_orm(_('Warning!'),_('The start date must be less than to the end date.'))
@api.onchange('end\u date')
更改结束日期(自我、结束日期、开始日期)的定义:
如果(开始日期和结束日期)和(开始日期<结束日期):
引发异常。除异常('Warning!')外,'('start date必须小于end date'))
在Odoo on change方法中,您无需传递任何参数,系统将直接从self对象获取它
@api.onchange('end_date')
def onchange_end_date(self):
if (self.start_date and self.end_date) and (self.start_date < self.end_date):
raise exceptions.except_orm(_('Warning!'),_('The start date must be less than to the end date.'))
@api.onchange('end\u date')
def onchange_end_日期(自我):
如果(self.start\u日期和self.end\u日期)和(self.start\u日期
这可能会对您有所帮助。在odooon-change方法中,您无需传递任何参数,系统将直接从self对象获取它
@api.onchange('end_date')
def onchange_end_date(self):
if (self.start_date and self.end_date) and (self.start_date < self.end_date):
raise exceptions.except_orm(_('Warning!'),_('The start date must be less than to the end date.'))
@api.onchange('end\u date')
def onchange_end_日期(自我):
如果(self.start\u日期和self.end\u日期)和(self.start\u日期
这可能对你有帮助。你好,你可以试试这个,我希望它对你有帮助
import ValidationError
@api.onchange('end_date')
def onchange_end_date(self):
if (self.start_date and self.end_date) and (self.start_date < self.end_date):
raise ValidationError(''The start date must be less than to the end date.'))
导入验证错误
@api.onchange(“结束日期”)
def onchange_end_日期(自我):
如果(self.start\u日期和self.end\u日期)和(self.start\u日期
谢谢您好,您可以试试这个,希望对您有所帮助
import ValidationError
@api.onchange('end_date')
def onchange_end_date(self):
if (self.start_date and self.end_date) and (self.start_date < self.end_date):
raise ValidationError(''The start date must be less than to the end date.'))
导入验证错误
@api.onchange(“结束日期”)
def onchange_end_日期(自我):
如果(self.start\u日期和self.end\u日期)和(self.start\u日期
谢谢除了一次更改之外,我们还可以使用约束。。。它有助于在创建和编辑以及更改时验证某些内容。。 这是我的代码,它运行良好
@api.multi
@api.constrains('start_date', 'start_date')
def _check_date(self):
start_date = self.start_date
end_date = self.end_date
if (start_date and end_date) and (start_date > end_date):
raise ValidationError(_('The start date must be less than to the end date. '))
谢谢除了一次更改之外,我们还可以使用约束。。。它有助于在创建和编辑以及更改时验证某些内容。。 这是我的代码,它运行良好
@api.multi
@api.constrains('start_date', 'start_date')
def _check_date(self):
start_date = self.start_date
end_date = self.end_date
if (start_date and end_date) and (start_date > end_date):
raise ValidationError(_('The start date must be less than to the end date. '))
谢谢你嗨,Ridma,你找到解决办法了吗?嗨,Ridma,你找到解决办法了吗?