تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
29266 أدوات العرض

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

الصورة الرمزية
إهمال
أفضل إجابة

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


الصورة الرمزية
إهمال
أفضل إجابة

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

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
2
فبراير 24
24974
1
أغسطس 23
2328
1
يوليو 22
3140
2
مارس 22
2923
0
نوفمبر 20
6874