Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
29118 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 2 24
24815
1
thg 8 23
2214
1
thg 7 22
3043
2
thg 3 22
2802
0
thg 11 20
6718