如何在odoo中弹出成功消息? [英] How to popup success message in odoo?

查看:378
本文介绍了如何在odoo中弹出成功消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am sending invitation by clicking button after clicking button and successfully sending invitation there is pop up message of successfully invitation send. But the problem is that the main heading of pop up message is Odoo Server Error. That is because I am using

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

有没有其他办法可以让它变得更好.

Is there any alternative to make it better.

推荐答案

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

When I need something like this I have a dummy wizard with message field, and have a simple form view that show the value of that field.

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

When ever I want to show a message after clicking on a button I do this:

     @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'
        }

消息向导的表单视图就这么简单:

The form view of message wizard is as simple as this:

<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 raised,Odoo 将在database 中执行rollback,如果你在此之前不要提交你的工作,在Odoo中也不推荐

Note: Never use exceptions to show Info message because everything run inside a big transaction when you click on button and if there is any exception raised a Odoo will do rollback in the database, and you will lose your data if you don't commit your job first manually before that, witch is not recommended too in Odoo

这篇关于如何在odoo中弹出成功消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆