[英]constrains in odoo 12
我想在 product_qty < 0 时引发 ValidationError。它会打印错误但不会引发错误,并且 product_qty 接受负数。 print: ('Product Quantity must be positive.', None)
class CustomEmployee(models.Model):
_name = 'employee.custom'
name = fields.Char(string=_('Employee'), required=True)
device_model = fields.Many2one('product.product', string=_('Device Model'), required=True)
product_qty = fields.Integer(string=_('Custody Quantity'))
@api.one
@api.constrains('product_qty')
def _check_product_qty(self):
if self.product_qty < 0:
raise ValidationError(_('Product Quantity must be positive.'))
检查您是否已导入 odoo 异常:
from odoo import exceptions
并且您正在使用引发异常的 odoo 形式:
raise exceptions.ValidationError(_('Product Quantity must be positive.'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.