如何根据发票Odoo v8的状态字段隐藏编辑按钮表单? [英] How to hide the edit button form based on state field of invoice Odoo v8?

查看:199
本文介绍了如何根据发票Odoo v8的状态字段隐藏编辑按钮表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在支付发票状态时隐藏编辑按钮,就像下面的图片一样.

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

我继承了 invoice_form 并添加了相应的属性.

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

编辑

按照@Sathiyan的建议,我创建了一个/security/invoice_security.xml文件并添加到我的__opnenerp__.py中,在其中添加了以下几行:

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>

当我放入noupdate="1"时,我创建了一个新数据库并将其安装在该数据库中,但是什么也没发生!你能告诉我我做错了什么吗?请.

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.

推荐答案

您可以通过覆盖FormView小部件的load_record来做到这一点:

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);
        }
    });
}

如果要查找完整代码,请选中此app:

Check this app if you looking for full code:

禁用已付款发票的编辑按钮

这篇关于如何根据发票Odoo v8的状态字段隐藏编辑按钮表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆