Hiding column in treeview on specific model

Hi,

I need some help to hide a column in a treeview in some cases.

I defined a button for a custom wizard on outgoing assigned inventory moves (customer shipment).

class Move(metaclass=PoolMeta):
    __name__ = 'stock.move'

    @classmethod
    def __setup__(cls):
        super().__setup__()
        cls._buttons.update({
                'update_quantity_wizard': {
                    'invisible': ~Eval('state').in_(['assigned']),
                    'depends': ['state'],
                    },
                })

    @classmethod
    @ModelView.button_action('module.wizard_update_quantity')
    def update_quantity_wizard(cls, moves):
        pass

Updating stock.move_list_shipment.xml:

<data>
    <xpath expr="/tree" position="inside">
        <button name="update_quantity_wizard" string="Pick"/>
    </xpath>
</data>

With this result:

Button is visible when move state is “Assigned”:

Button is invisible for other states:

Until now, everything is ok :slight_smile:

But this button is specific to Customer Shipment. So i don’t want to display the column “Pick” in Supplier Shipment model.

After a discuss on Irc, the suggestion was to use view_attributes and context to hide the column.

class Move(metaclass=PoolMeta):
    __name__ = 'stock.move'

    @classmethod
    def view_attributes(cls):
        return super().view_attributes() + [
            ('/tree/button[@name="update_quantity_wizard"]', 'tree_invisible',
                Eval('context', {}).get('shipment_in', False)),
            ]

And adding a variable in the action context:

<?xml version="1.0"?>
<tryton>
    <data>
        <record model="ir.action.act_window" id="stock.act_shipment_in_form">
            <field name="context" eval="{'shipment_in': True}" pyson="1"/>
        </record>
    </data>
</tryton>

But, this is not working and i’m still viewing the column “Pick” in the supplier shipment form:

Thanks for your help :slight_smile:

It must be Eval('shipment_in', Fase)

Are you sure this is actually updated? It is always odd to update existing XML record.

Indeed this can not work because the view you try to modify is not the view of the action because it is a One2Many.
For now the context is not passed to the screen of One2Many. I guess it could be taken via the view.

Ok, i did this way previously.

Yes, i saw the variable in the context when doing “tryton -v”

What do you mean by “taken via the view” ? Adding ‘context’ in the field definition of “inventory_moves” ?

When the widget instantiate its Screen, it could retrieve the context from the parent Screen via the view attribute.

I tried this:

    @classmethod
    def view_attributes(cls):
        return super().view_attributes() + [
            ('/tree/button[@name="update_quantity_wizard"]', 'tree_invisible',
                Eval('_parent_shipment', {}).get('shipment_in', False)),
            ]

and this:

    @classmethod
    def view_attributes(cls):
        return super().view_attributes() + [
            ('/tree/button[@name="update_quantity_wizard"]', 'tree_invisible',
                Eval('_parent_context', {}).get('shipment_in', False)),
            ]

but not working :frowning:

I can not as the screen context of a One2Many is always empty.

So it’s not possible ?

Not until this is solved:

1 Like