Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

XML ParseError in custom module

By
César Bustíos Benites
on 12/5/14, 4:03 PM 1,555 views

In a custom module I have this working fine:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record id="purchase_order_budget_reference" model="ir.ui.view">
            <field name="name">purchase.order.form</field>
            <field name="model">purchase.order</field>
            <field name="inherit_id" ref="purchase.purchase_order_form" />
            <field name="arch" type="xml">
                <field name="partner_ref" position="after">
                    <field name="budget_ref" />
                </field>
            </field>
        </record>
    </data>
</openerp>

Now I added the "attrs" parameter:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record id="purchase_order_budget_reference" model="ir.ui.view">
            <field name="name">purchase.order.form</field>
            <field name="model">purchase.order</field>
            <field name="inherit_id" ref="purchase.purchase_order_form" />
            <field name="arch" type="xml">
                <field name="partner_ref" position="after">
                    <field name="budget_ref" attrs="{'readonly': [('state', 'not in' ('draft', 'send'))]}" />
                </field>
            </field>
        </record>
    </data>
</openerp>

And now I'm getting an error:

...

ParseError: "ValidateError
Field(s) `arch` failed against a constraint: Invalid view definition

Error details:
'str' object is not callable" while parsing /opt/odoo/addons/purchase_order_budget_reference/purchase_order_budget_reference.xml:4, near
<record id="purchase_order_budget_reference" model="ir.ui.view">
            <field name="name">purchase.order.form</field>
            <field name="model">purchase.order</field>
            <field name="inherit_id" ref="purchase.purchase_order_form"/>
            <field name="arch" type="xml">
                <field name="partner_ref" position="after">
                    <field name="budget_ref" attrs="{'readonly': [('state', 'not in' ('draft', 'send'))]}"/>
                </field>
            </field>
        </record>

How can I solve this issue?

Comma omitted!?

zbik
on 12/5/14, 4:18 PM
1

Med Said BARA

--Med Said BARA--
2664
| 5 5 7
Algeria
--Med Said BARA--
Med Said BARA
On 12/5/14, 4:50 PM

Not only the Comma, The square brackets ... [ ]

replace: <field name="budget_ref" attrs="{'readonly':[('state', 'not in' ('draft', 'send'))]}" />

 

With:    <field name="budget_ref" attrs="{'readonly':[('state', 'not in', ['draft', 'send'])]}" />

 

 

Why list and not tuple?

zbik
on 12/5/14, 5:23 PM

According to OpenERP_Technical_Memento_v0.7.0.4: • attrs: Python map defining dynamic conditions on these attributes: readonly, invisible, required based on search tuples on other field values. You can also read: this http://www.serpentcs.com/serpentcs-attrs-in-openerp and this http://openerp-server.readthedocs.org/en/latest/03_module_dev_03.html#field

Med Said BARA
on 12/6/14, 6:03 AM

Ok, conditions on attributes: readonly, invisible, required - should be a list, but after 'not in', why? I looked through the code *.xml. In many cases is used list and likewise often is used tuple. In my opinion tuple is better, in this situation. Specs ('draft', 'send') is immutable - this is a tuple.

zbik
on 12/6/14, 5:46 PM
1

zbik

--zbik--
5976
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 12/5/14, 4:22 PM

Comma omitted!?

<field name="budget_ref" attrs="{'readonly': [('state', 'not in', ('draft', 'send'))]}"/>

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 12/5/14, 4:03 PM
Seen: 1555 times
Last updated: 3/16/15, 8:10 AM