如何根据发票Odoo v8的状态字段隐藏编辑按钮表单?

时间:2015-06-23 22:12:50

标签: odoo odoo-8

我想在发票时隐藏编辑按钮'州支付,如下图所示。

enter image description here

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

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

请帮帮我,这有什么不对?谢谢!

修改

在@Sathiyan的推荐之后,我创建了一个/security/invoice_security.xml文件并添加到我的__opnenerp__.py里面,我添加了这些内容:

<?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"时,我创建了一个新数据库并将其安装在那里,但什么都没发生!你能告诉我我做错了什么吗?请。

3 个答案:

答案 0 :(得分:0)

尝试通过继承替换字段并向其添加 attrs 。使用attrs,您可以在支付状态时将字段设置为不可见

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

答案 1 :(得分:0)

仅为“读取”权限为 account.invoice 对象添加记录规则。域名过滤为[('state','=','paid')]

答案 2 :(得分:0)

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

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

Disable edit button for paid invoice