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

Hi,

i have a button in a form header. i want to display a warning when the buttons function is completed. i tried:

return {'warning': {'title': 'Warning', 'message': 'Message.'}}

but nothing happens.

also when i try to return a ir.actions.window to display a wizard nothing happens.


อวตาร
ละทิ้ง

Please include code and more details

คำตอบที่ดีที่สุด

Hi Mitsch,

You cannot use the 'warning' in button, it can be used in onchange function.

If you want to show a warning or error inside the button function you can use 'UserError', but it will discard all changes made in that function. If the user tries to do something that has no sense in that record, you can use this. Syntax is

if 'condtion':
raise UserError('Message.')

Make sure you import UserError

from odoo.exceptions import UserError

Hope this helps.

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

in the view:

<record id="some_form" model="ir.ui.view">
    ...
    <field name="arch" type="xml">
        <form string="Some Name">
            <header>
                <button name="wkf_grant_order" type="object" string="Grant Order" states="confirmed"/>
            </header>
            ...
        </form>
    </field>
</record>

in the function:

def wkf_grant_order(self):
    return {'warning': {'title': 'Warning', 'message': 'Skipping granting because order is under 1000.'}}

i left out the other parts but what i tried is basically this.

อวตาร
ละทิ้ง
ผู้เขียน

an exception would actually work for the warning. but i also need to open a wizard.

คำตอบที่ดีที่สุด

you can add exception with raise

from odoo import exceptions 
raise exceptions.Warning('Warning message') 
raise exceptions.ValidationError('Not valid message') 
อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ม.ค. 24
14393
2
ธ.ค. 19
9270
0
พ.ย. 19
4388
Error on Warning in Odoo 12 แก้ไขแล้ว
1
ก.ค. 19
7109
0
ก.ค. 19
2540