zoukankan      html  css  js  c++  java
  • odoo12 修行提升篇之 自定义消息弹框 (三)

    在odoo12开发过程中很可能会遇到部分页面需要进行消息提示的情况。

    odoo12中可以使用raise抛出如UserError、Warning等异常进行消息提示,但是效果不友好。

    上面有个Odoo Server Error提示,很不美观,并且在Dialog框中弹出提示时,存在订单行字段值丢失的情况。

    方案:

    1、创建my_message_wizard.py文件,并在__init__.py中添加。

    2、my_message_wizard.py的内容如下:

    class MyMessageWizard(models.TransientModel):
        _name = 'my.message.wizard'
    
        message = fields.Text('message', required=True)
    
        @api.multi
        def action_confirm(self):
            return {'type': 'ir.actions.act_window_close'}
    

    3、在view文件夹下创建my_message_wizard.xml文件,并在__manifest__.py中引入。

    <odoo>
        <record id="my_message_wizard_form" model="ir.ui.view">
            <field name="name">my.message.wizard.form</field>
            <field name="model">my.message.wizard</field>
            <field name="arch" type="xml">
                <form>
                    <p>
                        <field name="message" readonly="1"/>
                    </p>
                    <footer>
                        <button name="action_confirm"
                                string="确认"
                                type="object"
                                default_focus="1"
                                class="oe_highlight"/>
                    </footer>
                </form>
            </field>
        </record>
    </odoo>
    

    4、使用:

    if <condition>:
        message = self.env['my.message.wizard'].create({'message': 'message'})
        return {
            'name': '提示',
            'type': 'ir.actions.act_window',
            'view_mode': 'form',
            'res_model': 'my.message.wizard',
            'res_id': message.id,
            'target': 'new'
        }
    

    5、效果:

    以上就是自定义消息提示的过程。

    温馨提示,记得升级对应的模块。

    git地址:https://github.com/SamNicole1809/odoo12_my_pro

    知止而后有定;定而后能静;静而后能安;安而后能虑;虑而后能得。
  • 相关阅读:
    PL/SQL中判断字段为空
    ArrayList知识详解
    那些碰到过的异常
    Java中的==和equals( )方法
    String,StringBuilder和StringBuffer
    树莓派3b+_32位linux系统arm架构安装JDK
    [杂]右键拷贝文件路径
    [023]模板成员函数为什么不能是虚函数
    [杂]几个好玩的网址
    [022]c++虚函数、多态性与虚表
  • 原文地址:https://www.cnblogs.com/SamNicole1809/p/14544719.html
Copyright © 2011-2022 走看看