Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
Hi. I wonder when to use within a XML field definition:
I ask because I have seen different options to semingly the same cases.
For example, for boolean fields, I find:
- <field name="dayofweek">1</field>
- <field name="priority" eval="1"/>
For refs, I find:
- <field name="calendar_id" ref="timesheet_group1"/>
- <field name="parent_id" eval="ref('mt_task_new')"/>
Odoo document link for eval and ref attribute are:-
The eval attribute evaluate its content as if it was Python code. This allows you to define values that are not strings.
Normally, content inside <field> tags are always evaluated as strings.
This will evaluate to the string '2.3' and not the float 2.3
This will evaluate to the string 'False' and not the boolean False
If you want to evaluate the value to a float, a boolean or another type, except string, you need to use the eval attribute:
<field name="value" eval="2.3" /> <field name="value" eval="False" />
The ref attribute allows to fill relations between the records :
<field name="company_id" ref="main_company"/>
The``company_id`` field is a many-to-one relation from the user object to the company object, and main_company is the id of to associate.
In xml using eval and ref attribute to assign the value for field and create new master record:-
<record id="product_uom_categ_vol" model="product.uom.categ">
<record id="product_uom_gal" model="product.uom">
<field name="category_id" ref="product_uom_categ_vol"/>
<field name="factor_inv" eval="3.78541"/>
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 platform 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.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 1/5/15, 2:19 PM|
|Seen: 7519 times|
|Last updated: 12/2/16, 12:25 AM|