콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
5 답글
7217 화면

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') 
아바타
취소
관련 게시물 답글 화면 활동
1
1월 24
14390
2
12월 19
9264
0
11월 19
4382
1
7월 19
7094
0
7월 19
2525