我遇到这种用户错误
advance_payment_percent = fields.Integer(string='Advance Payment', default=50)
if not self.advance_payment_percent:
raise UserError(_("Please enter advance payment percent under client form!"))
问题是,当我在advance_payment_percent中输入0时,由于在Python中0 = False,该UserError仍然被触发,因此我该如何解决我可以使用0且不会触发此错误的问题。仅当字段为空时才应触发它。
答案 0 :(得分:2)
也许还会检查self.advance_payment_percent是否不是int类型?
if type(self.advance_payment_percent) != int and not self.advance_payment_percent: