Reputation: 85
In an Odoo v17 application, in a tree view inside a page, I need to show a column depending on a certain field. There is a transport field whose value can either be 'air' or 'ocean'. If 'air', I need to show the 'flight_no' column in the tree view, if it is 'ocean', I need to show 'voyage_no' instead.
Here is the current code snippet of the view, which is correct if it is ocean:
<record model="ir.ui.view" id="shipment_form_view">
<field name="name">shipment.form.view</field>
<field name="model">shipment</field>
<field name="arch" type="xml">
<form>
...
<page string="Routes">
<field name="freight_routes" nolabel="1" widget="one2many_list" context="{'shipper_id':shipper_id, 'consignee_id':consignee_id}">
<form>
<sheet>
...
<group>
<group>
<field name="transport" widget="radio" options="{'horizontal': true}"/>
</group>
<group>
</sheet>
</form>
<tree>
<field name="name" string="Carriage"/>
<field name="arrival_datetime"/>
<field name="voyage_no"/>
<field name="transport"/>
<field name="line_added" column_invisible="1"/>
<button name="action_insert_line_service" type="object" string="Add to Service" icon="fa-plus-square-o"/>
</tree>
</field>
</page>
...
I tried this but it did not work, maybe because transport is inside the form?
<tree>
<field name="name" string="Carriage"/>
<field name="arrival_datetime"/>
<field name="flight_no" column_invisible="transport != 'air'"/>
<field name="voyage_no" column_invisible="transport != 'ocean'"/>
<field name="transport"/>
<field name="line_added" column_invisible="1"/>
<button name="action_insert_line_service" type="object" string="Add to Service" icon="fa-plus-square-o"/>
</tree>
I have posted this in the Odoo forum , and someone answered and marked my question solved but it is incorrect. Unfortunately, I am just new and lacked karma points to reply to his answer or unmark the solved tag. First, the attrs tag is deprecated in Odoo version 17 and if the invisible tag is used, the values would be hidden but the column would still be there.
How should I fix this? Should I have 2 trees or 2 main field, each for air and ocean? How can I set-up the condition to display which tree?
Upvotes: 0
Views: 13