viernes, 3 de julio de 2015

Differents cases for you don't use position="replace" in Odoo xml

Hi everybody, today i explain how to use position attribute in Odoo XML.

Realy is very easy, only you never forget this rule:

Never use this attribute position="replace" NEVER NEVER.
<field name="street" position="replace">
    <!-- .... Never use!!!! -->
</field>
Exist other for example position="attribute", position="after", position="before"
<!-- You need add new attributes to field -->
<field name="street" position="attribute">
    <attribute name="class">big_field</attribute>
    <attribute name="value">Default Value</attribute>
    <attribute name="style">boder:solid 0.1em #f00;</attribute>
</field>

<!-- You need add other field after that -->
<field name="street" position="after">
    <field name="street2"/>
</field>

<!-- You need add other field before that -->
<field name="street" position="before">
    <field name="first_name"/>
</field>
Is very importan in your addons not use replace attribute because is posible in your view or inherit view other addons touch the same part and cause error and generates incompatibilities.

Other example with xpath expresion
<!-- add in all links with class 
is menu_links text color red. -->
<xpath expr="//a[@class='menu_links']" position="attributes">
    <attribute name="style">color:#f00;</attribute>
</xpath>

<!-- add in only in first link with class 
is menu_links text color red. -->
<xpath expr="//a[@class='menu_links'][0]" position="attributes">
    <attribute name="style">color:#f00;</attribute>
</xpath>

<!-- add in only in second link with class 
is menu_links text color red. -->
<xpath expr="//a[@class='menu_links'][1]" position="attributes">
    <attribute name="style">boder:solid 0.1em #f00;</attribute>
</xpath>
The last example is very dangerous because is possible the second link not exist and cause error.

No hay comentarios:

Publicar un comentario