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

Ada*_*uss 5 python message popup odoo

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

raise osv.except_osv("Success", "Invitation is successfully sent")
Run Code Online (Sandbox Code Playgroud)

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

Cha*_* DZ 8

当我需要这样的东西时,我有一个wizard带有message字段的虚拟对象,并有一个简单的表单视图来显示该字段的值。

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

     @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'
        }
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

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'}
Run Code Online (Sandbox Code Playgroud)

注意: 不要使用exceptions,以显示信息消息,因为一个大内的一切运行transaction当你点击按钮,如果有任何exception 提出一个Odoo会做rollbackdatabase,如果你不这样做,你将失去你的数据commit在此之前,先手动你的工作,Odoo 中也不推荐女巫