odoo开发笔记 -- odoo10 视图界面根据字段状态,动态隐藏创建&编辑按钮

场景描述:

 

解决方式:

网络搜索,vnsoft_form_hide_edit 找到了这个odoo8的模块,

odoo10语法和视图界面有新的变化,所以需要修改一些地方,感兴趣的小伙伴可以对比下两个代码的不同。

 

odoo10:

注意:该js代码是全局生效的。

odoo.define('vnsoft_form_hide_edit', function (require) {
    "use strict";
    var FormView = require('web.FormView');

    FormView.include({do_push_state: function (state) {
                // alert("hahahahahaha");
                try {
                    var self = this;
                    this._super.apply(this, arguments);
                    var no_edit = this.options.action.context.form_no_edit
                    // console.log("%o",no_edit);
                    if(no_edit!=undefined){
                        var result = this.compute_domain(no_edit);
                        // console.log("%o",result);
                        if(result==true){
                            this.$buttons.find(".o_form_buttons_view").hide();
                            this.$buttons.find(".o_dropdown_toggler_btn").hide()
                        }else{
                            if(this.get("actual_mode")=="view") {
                                this.$buttons.find(".o_form_buttons_view").show()
                            }
                        }
                    }
                  } catch (e) {
                    { /* empty */ }
                  }
            }
        }
    );
});

关键部分:视图里边添加限制条件,来根据定义的条件,动态显示编辑按钮--显示or隐藏

        <record id="your_test_action" model="ir.actions.act_window">
            <field name="name">测试视图</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">teset.test_dec</field>
            <field name="view_mode">tree,form</field>
            <field name="context">{ 'form_no_edit':['|',('state','in',['submitted','approved']),
                ('city', 'in', ['beijing','shanghai'])],}
            </field>
            <field name="view_id" ref="customs_declaration_tree"/>
        </record>
<field name="context">{ 'form_no_edit':['|',('state','in',['submitted','approved']),
                ('city', 'in', ['北京','上海'])],}</field>
当form视图的相关字段: 字段(state状态)的值在“提交”或者“批准”时,或者 字段(city城市)的值在“北京”或者”上海“的条件下,但前界面左上角的”编辑“按钮就会隐藏。

 

转载于:https://www.cnblogs.com/hellojesson/p/9035739.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值