2
votes

this question already asked by someone, this in an example question

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

but i dont get true answer, somebody can help me, i really need to hide or disabled this button.

For your information im using odoo v.10

Thanks in advance

1
I don't think odoo allows you to hide edit button depending statekhelili miliana
See sale order...khelili miliana
You can costumise a field by statekhelili miliana
You can not hide Edit button based on the state. Instead you can make the fields readonlysfx
Yes, attrs="{'invisible': ['|',('invoice_status', '!=', 'no'), ('state', '!=', 'sale')]}khelili miliana

1 Answers

0
votes

The only way to this is by Javascript you need to add this behavior to your form view build a custom addon and just add this javascript file to your 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);
        }
    });
}

Add this to backend asset template

    <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>

Don't forget to replace your_addon_name by the real addon name that you create.