NeoVe
NeoVe

Reputation: 3897

Show/Hide fields on One2many tree - Odoo v8

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?

Upvotes: 1

Views: 1155

Answers (1)

Travis Waelbroeck
Travis Waelbroeck

Reputation: 2135

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.

Upvotes: 1

Related Questions