I have created a Validation Error to show up when the submit button is clicked and the condition of the field is empty. But when I try to test it when the field is filled, the validation error still showing up. What's wrong with my code ?
def action_approved(self):
for rec in self:
expense_account = self.env['account.pettycash.voucher.wizard.line'].search([('expense_account','=',False)])
if expense_account :
raise ValidationError('Fill the expense account!')
else :
rec.state = 'approved'
I expect validation error to show up when field is empty and approve when filled
To check if one expense account in voucher lines is not set and raise a validation error, loop over
voucher_linefield and check ifexpense_accountis not set (if not line.expense_accountthen raise the validation error.Example: