Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
4 ตอบกลับ
1011 มุมมอง

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:

<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>

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?

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

column_invisible works on the parent or context. In your case, you should use

<field name="voyage_no" column_invisible="parent.transport != 'ocean'"/> 
<field name="flight_no" column_invisible="parent.transport != 'air'"/>
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

You don’t need two tree views. Just use attrs to control visibility like this:

<field name="flight_no"

       attrs="{'invisible': [('transport', '!=', 'air')], 'readonly': [('transport', '!=', 'air')]}"

       string="Flight No"/>


<field name="voyage_no"

       attrs="{'invisible': [('transport', '!=', 'ocean')], 'readonly': [('transport', '!=', 'ocean')]}"

       string="Voyage No"/>


อวตาร
ละทิ้ง

Don't use attrs, its odoo 17

คำตอบที่ดีที่สุด

Hi,


Try with the following code.


<tree>
<field name="name" string="Carriage"/>
<field name="arrival_datetime"/>
<field name="flight_no" column_invisible="parent.transport != 'air'"/>
<field name="voyage_no" column_invisible="parent.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>



Hope it helps

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

It is not solved!

I do not have enough karma points to reply to Abhay Singh's answer, but as indicated, I am using Odoo version 17, and attrs is deprecated. Also if the invisible tag is used, there will still be the column though the values will not be displayed that is why I tried to use the column_invisible tag

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
5
ส.ค. 25
1314
1
ก.พ. 25
12225
0
พ.ย. 24
1134
0
พ.ค. 24
1325
1
ม.ค. 22
4544