1
votes

I have some fields I'm showing in my One2many tree view:

  <page string="Budget Lines Planned">
            <field name="account_budget_bsi_line" colspan="4" nolabel="1" attrs="{'readonly':[('state','!=','draft')]}">
                <tree string="Budget Lines Planned" editable="bottom" >
                    <field name="opening_stock"/>
                    <field name="sales_planned" />
                    <field name="amount_total"/>
                    <field name="interauxiliary_transfers_planned" />
                    <field name="interauxiliary_receipts_planned" />
                    <field name="prod_purchased_planned" />
                    <field name="closing_stock_planned" />
                </tree>
            </field>
    </page>

This is from a custom module, which has a workflow with states, ie: draft, approved, next, done etc.

Suppose on next state, I want to hide opening_stock field, and show some other field.

I know this can be achieved on forms by using attrs="{'readonly':[('state','!=','draft')]}" or invisible or whatever.

But doesn't seem to work on One2many tree views, so, how can I achieve that in this case?

1
Put them in invisible instead of readonly, it will not show them, it will be like an empty column. Try it and tell medccdany
Hi, no it doesn't work like that, sorry, I tried before, this is a one2many tree, not a "conventional" oneNeoVe
I've seen this invisible="context.get('state')=='next'" , doesn't give me any errors, but still not hiding it, the problem is the one2many field, we'll wait for some hint about this scenarioNeoVe
but you cant modify if you put it as invisibledccdany
Thanks, but that is beyond the scope of the question, the reasons are many for me to want to achieve thisNeoVe

1 Answers

1
votes

I'm fairly sure there is no way to dynamically hide an entire column of a One2many field's tree. You can dynamically hide the column's contents per row with attrs. In the case below, if the line had a Name of "Example", then it would show as a blank cell when in a Draft state.

<field name="opening_stock" attrs="{'invisible': [('state', '!=', 'draft')]}"/>

If you really must show a different One2many tree view, then you can try using multiple field/tree definitions in the view and using the attrs on the One2many field itself like so:

<field name="account_budget_bsi_line" attrs="{'invisible': [('state', '=', 'draft')]}">
    <tree>
        ...
        <field name="opening_stock"/>
        ...
    </tree>
</field>
<field name="account_budget_bsi_line" attrs="{'invisible': [('state', '!=', 'draft')]}">
    <tree>
        ...
        <!-- Exclude field opening_stock -->
        ...
    </tree>
</field>

I'm not sure if this will work for your needs, but it's the closest I can think to a solution.