跳至内容
菜单
此问题已终结
3 回复
3999 查看

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


形象
丢弃
最佳答案

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.

形象
丢弃
最佳答案

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


形象
丢弃
编写者

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.

编写者 最佳答案

i added code as below:

abcd = self._origin.id

    raise UserError(f'{abcd}')


here is screenshot of error:

regards

形象
丢弃
相关帖文 回复 查看 活动
2
9月 24
2408
0
1月 24
1762
1
6月 25
15250
4
5月 25
2465
2
5月 25
5806