Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explanation of eval attribute in product.template in OpenErp

Tags:

eval

odoo

openerp

I need to understand the eval attribute in the following code in the product_demo.xml in product module in Odoo:

"record id="product_product_4_product_template" model="product.template">
            field name="attribute_line_ids" eval="[(6,0,[ref('product.product_attribute_line_1'), ref('product.product_attribute_line_2'), ref('product.product_attribute_line_3')])]"/>
        </record>"

I understand that the attribute_line_ids value is being set here. I also understand that the values inside the 'ref' refers to XML ids which would, in short, return the model-'product.attribute.line associate with the XML id.

I really don't understand what each of the values in the eval attribute mean and what changes would it do on view level and db level. I have referred to many odoo documentation but none could provide clarity.

like image 902
John Avatar asked Oct 16 '14 13:10

John


1 Answers

This adds a bunch of values to a Many2many field called attribute_line_ids. Odoo has a special syntax for setting values on Many2many fields. This syntax is described here and is used in the code you asked about.

Basically, to modify a many2many relation you use a three-element tuple. The first element of the tuple is a numeric command, and two other elements are values - their exact function depend on the command.

There are six numeric commands:

  • 0 - creates a new object and adds it to the Many2many relation
  • 1 - updates an object that already exists on the relation
  • 2 - deletes an object that already exists on the relation
  • 3 - removes an existing object from the relation, without deleting it
  • 4 - adds an existing object to the relation
  • 5 - removes all objects from the relation, without deleting them
  • 6 - replaces pervious objects existing on the relation with a new set of objects

The relevant part of your code look like this:

(6,0,[ref('product.product_attribute_line_1'), ref('product.product_attribute_line_2'), ref('product.product_attribute_line_3')])

It's a three-element tuple (which is expected, since the code sets values on a Many2many relation):

  • The first element is the command. "6" means elements previously existing in the relation (if any) will be replaced with elements which ids are passed as the third element of the tuple.
  • The second argument is irrelevant. It has a role with other commands, but when used with "6" it can be anything (personally I would use None to better reflect this).
  • The third element is a list of ids. Since the first element is "6", this signifies the objects that will be put into the relation, replacing whatever was previously there.
like image 94
Ludwik Trammer Avatar answered Oct 09 '22 19:10

Ludwik Trammer