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

i am adding a Computed field through Technical -> Models

i want to check some values but i can't use UserError because it needs to import related module.

when i am using: 

from odoo.exceptions import UserError

it is throwing error on above mentioned line.

i think this is not allowing to use it, is there any other way to show the value like UserError etc. ? and what if i want to import any other library module? 

please help.

regards


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

Hi,

You are right, it's not allowed do import other libraries from UI, but some of them are already imported, like datetime or UserError.
So you can just write UserError("Needed value") and get a result. It working also in scheduled actions.

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

If you are doing from the UI side you don't need to import it just use
raise UserError('Hellooooo')


Ảnh đại diện
Huỷ bỏ
Tác giả

thank you @Jaiswal but it is showing error as below:

ValueError: <class 'NameError'>: "name 'UserError' is not defined"

i can't add screenshot in Comment.

Tác giả Câu trả lời hay nhất

i added code as below:

abcd = self._origin.id

    raise UserError(f'{abcd}')


here is screenshot of error:

regards

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 9 24
2588
0
thg 1 24
1882
0
thg 8 25
157
1
thg 6 25
15539
4
thg 5 25
2741