Odoo根据状态禁用编辑按钮

时间:2017-10-10 09:52:44

标签: openerp odoo-8 odoo-9 odoo-10 odoo-view

这个问题已被某人提出,这是一个示例问题

How to hide the edit button form only when invoice' state is 'paid' Odoo v8?

但我没有得到真实答案,有人可以帮助我,我真的需要隐藏或禁用此按钮。

使用odoo v.10

获取您的信息

提前致谢

1 个答案:

答案 0 :(得分:0)

唯一的方法是通过 return DB::table('customers') ->select(DB::raw('email, max(created_at)')) ->groupBy('email') ->orderBy('max(created_at)', 'desc') ->get(); ,您需要将此行为添加到表单视图中 构建自定义插件,然后将此JavaScript文件添加到您的Javascript

backend assets template

将此添加到后端资产模板

//file: static/src/js/disable_edit_for_paid_invoice.js

openerp.your_addon_name = function(instance, local) {
    var instance = openerp;
    var FormView = instance.web.FormView;

    // override load_record
    FormView.include({
        load_record: function(record) {
        // disable only for cancel and paid account.invoice
        if (record){
            if (this.model == 'account.invoice' & _.contains(['paid', 'cancel'], record.state)){
                    $('button.oe_form_button_edit').hide()
                }else {
                    $('button.oe_form_button_edit').show()
                }
        }
        // call super
        return this._super(record);
        }
    });
}

不要忘记将 <template id="assets_backend" name="disable edit paid invoice assets" inherit_id="web.assets_backend"> <xpath expr="." position="inside"> <script type="text/javascript" src="/your_addon_name/static/src/js/disable_edit_for_paid_invoice.js"></script> </xpath> </template> 替换为your_addon_name