Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
5 Odpowiedzi
7183 Widoki

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.


Awatar
Odrzuć

Please include code and more details

Najlepsza odpowiedź

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.

Awatar
Odrzuć
Autor Najlepsza odpowiedź

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.

Awatar
Odrzuć
Autor

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

Najlepsza odpowiedź

you can add exception with raise

from odoo import exceptions 
raise exceptions.Warning('Warning message') 
raise exceptions.ValidationError('Not valid message') 
Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
sty 24
14364
2
gru 19
9160
0
lis 19
4332
1
lip 19
7044
0
lip 19
2509