Skip to Content
Menú
This question has been flagged
2 Respostes
29025 Vistes

I want to raise an error if something specific happens and also show it in the UI. how can I do it?

Avatar
Descartar
Best Answer

You can raise any odoo exception which will show the error message in the popup.

Ex:

from odoo.exceptions import ValidationError

raise ValidationError("This is error message.")


Avatar
Descartar
Best Answer

UserError exception should be used in all cases where some action should not be allowed, when it goes against logic.

        if not self.checkout_ids:
            raise exceptions.UserError('Select at least one Checkout to send messages to.')
        if not self.message_body:
            raise exceptions.UserError('Write a message body to send.')

To Know More About different types of exceptions refer :

https://www.cybrosys.com/blog/raising-exceptions-odoo-13

Avatar
Descartar
Related Posts Respostes Vistes Activitat
2
de febr. 24
24710
1
d’ag. 23
2155
1
de jul. 22
2973
2
de març 22
2718
0
de nov. 20
6641