Reputation: 92
I am using v7 and I want to show in a tree view
a field with image icons (like a semaphore) depending of other field values in the same row.
Actually, I get the functionality I want with a function field and put the result as string but I really want it as an image. I don't know if is possible to return HTML
from the function so I decided to do that with jQuery
.
I implemented the jQuery
code using the browser console and works but when I put the jQuery code
in the view the "data-field" selector does not selected.
Please, can anyone explain me why or tell me another way to get my objective?
Upvotes: 2
Views: 1822
Reputation: 14746
Lists
The root element of list views is tree. The list view's root can have the following attributes:
editable, default_order, colors, fonts, create, edit, delete, on_write, string
See more about ListView
You can achieve this by defining child elements button in list view. I have added icon in product to show whether product is available / hold / sold based on product's status.
button
icon: icon to use to display the button
Xml code to display icon in listview.
<xpath expr="//notebook/page[@string='Order Lines']/field[@name='order_line']/tree[@string='Sales Order Lines']/field[@name='product_id']" position="before">
<field name="product_status" invisible="1" />
<button icon='Hold' readonly="1" attrs="{'invisible':[('product_status', '!=', 'hold')]}"/>
<button icon='Available' readonly="1" attrs="{'invisible':[('product_status', '!=', 'available')]}"/>
<button icon='sold' readonly="1" attrs="{'invisible':[('product_status', '!=', 'sold')]}"/>
</xpath>
NOTE
base field must be store=True.
Why store=True ?
Reason: when you set any function field store=True then it will physically created in database, while you give this field name in domain the odoo framework add this field directly in WHERE clause, it will not access through browsable object, so if your field is store=False then it won't be able to find that field and gives you an error.
xpath is used to define at which location you want to add/update fields.
See more about xpath
Upvotes: 3