Reputation: 1382
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.
Upvotes: 1
Views: 42
Reputation: 146
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:
Upvotes: 2