Search code examples
pythonpython-2.7odooodoo-8odoo-9

UserError triggered on value 0


I have this kinda usererror

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!"))

the problem is that when I enter 0 in advance_payment_percent this UserError is still triggered because 0 = False in python, so how can I work around this that I could use 0 and this error wouldn't be triggered. It only should be triggered when field is empty.


Solution

  • Maybe also check that self.advance_payment_percent is not of the type int?

    if type(self.advance_payment_percent) != int and not self.advance_payment_percent: