How to hide the edit button form based on state field of invoice Odoo v8?

前端 未结 3 1099
心在旅途
心在旅途 2021-01-06 05:07

I want to hide the edit button when a invoice\' state is paid, just like the image below.

\"enter

相关标签:
3条回答
  • 2021-01-06 05:32

    You can do this by overriding load_record of FormView widget:

    openerp.module_name = function(instance, local) {
        var instance = openerp;
        var FormView = instance.web.FormView;
    
        // override load_record
        FormView.include({
            load_record: function(record) {
            // disable only for purchase.order
            if (record){
                // allow this behavior only for purchase.order  
                if (this.model == 'purchase.order' & _.contains(['done', 'cancel'], record.state)){
                        $('button.oe_form_button_edit').hide()
                    }else {
                        $('button.oe_form_button_edit').show()
                    }
            }
            // call super
            return this._super(record);
            }
        });
    }
    

    Check this app if you looking for full code:

    Disable edit button for paid invoice

    0 讨论(0)
  • 2021-01-06 05:43

    Add a Record Rule for account.invoice object with Read permission alone. And a domain filter as [('state','=','paid')].

    0 讨论(0)
  • 2021-01-06 05:53

    Try replacing fields through inheritance and adding attrs to it. Using attrs, you can set the field invisible when state is paid like this,

            <field name="edit" attrs="{'invisible':[('state', '=', 'paid')]}"/>
    

    0 讨论(0)
提交回复
热议问题