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

左心房为你撑大大i 提交于 2019-11-30 17:23:16

问题


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

And I was inheriting the invoice_form and add the corresponding attribute.

<record id="invoice_form_inherit" model="ir.ui.view">
    <field name="name">invoice.form.inherit</field>
    <field name="model">account.invoice</field>
    <field name="inherit_id" ref="account.invoice_form"/>
    <field name="arch" type="xml">
        <xpath expt='//form[@string="Invoice"]' possition='attributes'>

            <!-- Frist intent : nothing happened -->
            <attribute name="edit" attrs="{'invisible:[('state','=','paid')]'}"/>

            <!-- Second intent : edit, always hide -->
            <attribute name="edit" attrs="{'invisible:[('state','=','paid')]'}">false</field>

            <!-- Thirds intent : edit, never hide -->
            <attribute name="edit" attrs="{'invisible:[('state','=','paid')]'}">true</field>
    </field>

Please help me, what it's wrong? Thanks!!

EDIT

Following the recomendations of @Sathiyan, I created a /security/invoice_security.xml file and add in my __opnenerp__.py, inside I added this lines:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data noupdate="1">
        <record id="rule_no_edit_invoice_paid" model="ir.rule">
            <field name="name">rule.no.edit.invoice.paid</field>
            <field name="model_id" ref="account.model_account_invoice"/>
            <field name="group" eval="[(4,ref('account.group_account_invoice'))]"/>
            <field name="domain_force">[('state','=','paid')]</field>
            <field eval="1" name="perm_read"/>
            <!--
            <field eval="0" name="perm_create"/>
            <field eval="0" name="perm_write"/>
            <field eval="0" name="perm_unlink"/>
            -->
        </record>
    </data>
</openerp>

As I put noupdate="1" I created a new database and installed it there, but nothing is happened! Can you tell me what I doing wrong? please.


回答1:


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




回答2:


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')]}"/>




回答3:


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



来源:https://stackoverflow.com/questions/31014443/how-to-hide-the-edit-button-form-based-on-state-field-of-invoice-odoo-v8

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!