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

    知止而后有定;定而后能静;静而后能安;安而后能虑;虑而后能得。
  • 相关阅读:
    ES5 05 Function扩展
    ES5 04 Array扩展
    ES5 03 Object扩展
    ES5 02 JSON对象
    ES5 01 严格模式
    Oracle 数据库复制
    PB函数大全
    Handle( ) //得到PB窗口型对象的句柄
    PB赋值粘贴 多个DW进行update
    pb 11 数据窗口空白,预览pb崩溃解决方案
  • 原文地址:https://www.cnblogs.com/SamNicole1809/p/14544719.html
Copyright © 2011-2022 走看看