Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
4298 มุมมอง

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

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ก.ย. 24
2587
0
ม.ค. 24
1881
0
ส.ค. 25
140
1
มิ.ย. 25
15538
4
พ.ค. 25
2739