python - 如何在odoo中弹出成功消息?

标签 python popup odoo message

我在点击按钮后点击按钮发送邀请,成功发送邀请后会弹出邀请发送成功的消息。但问题是弹出消息的主要标题是 Odoo 服务器错误。那是因为我正在使用

raise osv.except_osv("Success", "Invitation is successfully sent")

有什么办法可以让它更好。

最佳答案

当我需要这样的东西时,我有一个虚拟 wizardmessage字段,并有一个简单的表单 View 来显示该字段的值。

当我想在单击按钮后显示消息时,我会这样做:

     @api.multi
     def action_of_button(self):
        # do what ever login like in your case send an invitation
        ...
        ...
        # don't forget to add translation support to your message _()
        message_id = self.env['message.wizard'].create({'message': _("Invitation is successfully sent")})
        return {
            'name': _('Successfull'),
            'type': 'ir.actions.act_window',
            'view_mode': 'form',
            'res_model': 'message.wizard',
            # pass the id
            'res_id': message_id.id,
            'target': 'new'
        }
form view消息向导就像这样简单:

<record id="message_wizard_form" model="ir.ui.view">
    <field name="name">message.wizard.form</field>
    <field name="model">message.wizard</field>
    <field name="arch" type="xml">
        <form >
            <p class="text-center">
                <field name="message"/>
            </p>
        <footer>
            <button name="action_ok" string="Ok" type="object" default_focus="1" class="oe_highlight"/> 
        </footer>
        <form>
    </field>
</record>
Wizard很简单是这样的:

class MessageWizard(model.TransientModel):
    _name = 'message.wizard'

    message = fields.Text('Message', required=True)

    @api.multi
    def action_ok(self):
        """ close wizard"""
        return {'type': 'ir.actions.act_window_close'}

注:从不使用 exceptions显示信息留言因为一切都在一个大 transaction 内运行当你点击按钮时,如果
有没有exception 凸起 一个 Odoo 会做 rollbackdatabase ,否则您将丢失数据 commit在此之前先手动完成您的工作,女巫不是 推荐 在 Odoo 中也是如此

关于python - 如何在odoo中弹出成功消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58302569/

相关文章:

python - Django 1.4 定义用户

python - Spark 中的 Word2Vec 是否在整个文本列上进行训练

python - 满足条件时终止多处理进程

python - 创建从字符串命名的类对象实例?

javascript - 无法获取 Odoo 9 中 javascript 文件的内容

python - 来自可运行一半 Odoo 10 的字段的函数

css - 将弹出窗口中的文本和图标从右移到左,反之亦然

javascript - Ionic 弹出窗口确认未执行 if 语句中的代码

Javascript - 弹出窗口(按名称)是否打开?

postgresql - 具有不同模式的 2 个 Odoo 8.0 postgresql 数据库之间的数据库复制