在 odoo 10 中,如何显示 bootstrap 警报之类的消息?

In odoo 10, how can I show a message like bootstrap alert?

我想在更改方法中添加警报,但不会引发警告或用户错误。仅显示 like-bootstrap 警报,而不会中断用户保存数据的可能性。类似于验证发票时发生的情况。

请问怎么做?

我不知道这是否是最好的方法,但这对我有用。

在您的视图中,在您的 xml 字段中放置一个 bootstrap 警报:

<field name="arch" type="xml">
    <form string="My Form">
        <div class="alert alert-success alert-dismissible" invisible="not context.get('show_message', False)">
            <a href="#" class="close" data-dismiss="alert" aria-label="close">X</a>
            <strong>Success!</strong> Indicates a successful or positive action.
        </div>
...

注意 div 元素中的 invisible 属性。所以在你的模型中,当处理一个动作时,你可以在上下文中传递一个变量show_message。这对我有用:

@api.multi
def my_action(self):
    return {
        "type": "ir.actions.act_window",
        "res_model": "my_module.my_model",
        "views": [[False, "form"]],
        "res_id": self.id,
        "target": "main",
        "context": {'show_message': True},
    }