Home > other >  one2many field view - attribute
one2many field view - attribute

Time:11-29

I have the following wizard structure [ field name and data type ]

  • Type :- Selection :- Type 1 and Type 2
  • Route :- One2many

When Users select Type 1, I want to allow them to add records in the Route table. While on the Type 2, I want to make Route readonly and don't allow deletion. I will fill it with default route information.

I write following code in the .xml file:

<group attrs="{'invisible': [('type', '=', 'type_2')]}">
    <field name="route_ids" string="Testing 1">
        <tree>
            <field name="x"/>
            <field name="y"/>
        </tree>
    </field>
</group>

<group attrs="{'invisible': [('type', '=', 'type_1')]}">
    <field name="route_ids" string="Testing 2">
        <tree delete="false" create="false">
            <field name="x"/>
            <field name="y"/>
        </tree>
    </field>
</group>

I notice that based on Type selection, route field label is changing but tree attributes (readonly, delete) remain same / whatever set in the last.

Expectation:

One2many field attribute should be refreshed instead of keeping last.

I resolved it by adding a new field and onchange method but I'm looking for a better approach to resolve it.

CodePudding user response:

  1. Have you tried to make your delete-attribute dynamic:
    <tree t-att-delete="'false' if type=='type_1' else 'true'" >
    ...

CodePudding user response:

You can use the web_action_conditionable module, it adds support for conditions on create and delete actions on One2Many fields.

Example:

<field name="route_ids">
    <tree delete="type=='type_2'" create="type=='type_2'">
        <field name="x"/>
        <field name="y"/>
    </tree>
</field>
  • Related