How to hide a column in a tree ?

Asked by Thibaut DIRLIK (Logica)

Everything is in the question, I want this to work :

<record id="rent_order_line_list_view" model="ir.ui.view">
            <field name="name">rent.order.line.list</field>
            <field name="model">rent.order.line</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Rent Order Lines">
                    <field name="name"/>
                    <field name="begin_datetime" string="Begin the" attrs="{'invisible' : [('order_id.sale_type', '!=', 'rental')]}"/>
                    <field name="duration_value"/>
                    <field name="duration_unity"/>
                    <field name="discount"/>
                    <field name="product_uom_qty" string="Qty"/>
                    <field name="product_uom" string="UoM"/>
                    <field name="price_unit" string="Price per duration"/>
                    <field name="price_subtotal" string="Total price"/>
                </tree>
            </field>
        </record>

It seems that the 'attrs' doesn't work on tree views, only on form views. So how I can do what I'm trying to do?

Thanks for your help,

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
Thibaut DIRLIK (Logica)
Solved:
Last query:
Last reply:
Revision history for this message
Quentin THEURET @Amaris (qtheuret) said :
#1

Hello Thibaut,

Try to use the fields_view_get to change the view before send it to
the client.

Best regards

Quentin THEURET
<email address hidden>

+33 (0)6 33 23 20 84
http://www.quentin-theuret.net

► Propulsé par l'Association Sud-Ouest.org
 └ Plateforme Libre d'hébergement mail à prix libre

Le 12/01/2011 14:30, Thibaut DIRLIK a écrit :
> New question #141158 on OpenObject Server:
> https://answers.launchpad.net/openobject-server/+question/141158
>
> Everything is in the question, I want this to work :
>
> <record id="rent_order_line_list_view" model="ir.ui.view">
> <field name="name">rent.order.line.list</field>
> <field name="model">rent.order.line</field>
> <field name="type">tree</field>
> <field name="arch" type="xml">
> <tree string="Rent Order Lines">
> <field name="name"/>
> <field name="begin_datetime" string="Begin the" attrs="{'invisible' :
[('order_id.sale_type', '!=', 'rental')]}"/>
> <field name="duration_value"/>
> <field name="duration_unity"/>
> <field name="discount"/>
> <field name="product_uom_qty" string="Qty"/>
> <field name="product_uom" string="UoM"/>
> <field name="price_unit" string="Price per duration"/>
> <field name="price_subtotal" string="Total price"/>
> </tree>
> </field>
> </record>
>
> It seems that the 'attrs' doesn't work on tree views, only on form
views. So how I can do what I'm trying to do?
>
> Thanks for your help,
>

Revision history for this message
Thibaut DIRLIK (Logica) (thibaut-dirlik) said :
#2

Thanks for your help, but the problem is that order_id.sale_type (which is a field in the order header) may be changed on-the-fly byt the user. It's a fields.selection. I want to show/hide columns in the tree view depending of this field (dynamically).

Revision history for this message
Husen Daudi (husendaudi) said :
#3

we can hide columns dynamically using attrs but 'order_id.sale_type' will not work with it.
you can directly match with fields name. you can add relative field in your object for sale_type and use that in attrs.

Revision history for this message
Thibaut DIRLIK (Logica) (thibaut-dirlik) said :
#4

Thanks for answer Husen, but it doesn't work. I tried, but no result, which seems logic to me : In a tree view, you can't hide a column on a per-object condition. Indeed, what would happend if the condition is True on an object and False on a other ?

Maybe I'm not doingmy module the good way, here is what I want to do :

- Create a rent module to handle leasing of products
- I replace the sale.order model/view to add a 'sale_type' field which can be 'sale' or 'rental'.
- If the type is 'sale', nothing change.
- If the type is 'rental', I want to change the sale.order.line tree view by hiding/showing fields.
- The sale.order.line model has also been modified to handle rent OR sale (columns like 'duration' has been added).

I directly edited sale.order and sale.order.line to keep compatibility with all others modules: stock, invoicing, etc. The goal is that a rent is just a special case of a sale.

So, when the use select 'Rental' in the order type, I need to immediately add/remove colums in the tree view.

Revision history for this message
Quentin THEURET @Amaris (qtheuret) said :
#5

I don't know it's this behaviour works on v6 but on v5 it didn't work.

Revision history for this message
Thibaut DIRLIK (Logica) (thibaut-dirlik) said :
#6

I'm working on v6, I didn't tell it. If you have a better idea on how to implement my problem (and keep compatibility with the sale module: generate invoice, workflows, etc), tell me !

Revision history for this message
Quentin THEURET @Amaris (qtheuret) said :
#7

IMHO, I think it's not implemented because the tree view is a table
with defined columns and I haven't any AJAX to change the defined
columns on table when you change a field value.

Quentin

Le 13/01/2011 08:59, Thibaut DIRLIK a écrit :
> Question #141158 on OpenObject Server changed:
> https://answers.launchpad.net/openobject-server/+question/141158
>
> Status: Answered => Open
>
> Thibaut DIRLIK is still having a problem: I'm working on v6, I
> didn't tell it. If you have a better idea on how to implement my
> problem (and keep compatibility with the sale module: generate
> invoice, workflows, etc), tell me !
>

Revision history for this message
Thibaut DIRLIK (Logica) (thibaut-dirlik) said :
#8

Okay so I'll have to find an other way. Thanks for your answers.

Revision history for this message
Husen Daudi (husendaudi) said :
#9

Its working in V6, check task view, install project_gtd module. you will find dynamic colums in task tree view.
we can make columns visible/invisible based on conditions in V6.
after installing project_gtd you can open task tree view and press inbox button or other gtd buttons.
the other thing is to change sequence of columns, if you check group by functionality of V6 you can see that column sequences are getting changed based on group by.
this functionality is not exist in V5. attrs will not work on tree view in V5.

Revision history for this message
Thibaut DIRLIK (Logica) (thibaut-dirlik) said :
#10

Hum indeed. In this case it's "real" tree view, with filters that change the context on the fly. In my case it's a tree view inside a form view. But I'll take a look, I'll tell you if it works too.

Revision history for this message
Thibaut DIRLIK (Logica) (thibaut-dirlik) said :
#11

I don't think I can't make it works. In the case of project_gtd, the context is changed using the search view and filters. And there is an "convisible" conidtion like this :

invisible=" not context.get('gtd_visible', False)"

The problem is that in my case, I don't have filters to change the context. And it's not possible to change the context from an on_change event (I could have bind on_change on my selection field).

Any idea?

Revision history for this message
Quentin THEURET @Amaris (qtheuret) said :
#12

Try to change the view with an attrs attribute.

Quentin THEURET
<email address hidden>

+33 (0)6 33 23 20 84
http://www.quentin-theuret.net

► Propulsé par l'Association Sud-Ouest.org
 └ Plateforme Libre d'hébergement mail à prix libre

Le 13/01/2011 10:58, Thibaut DIRLIK a écrit :
> Question #141158 on OpenObject Server changed:
> https://answers.launchpad.net/openobject-server/+question/141158
>
> Thibaut DIRLIK posted a new comment: I don't think I can't make it
> works. In the case of project_gtd, the context is changed using the
> search view and filters. And there is an "convisible" conidtion
> like this :
>
> invisible=" not context.get('gtd_visible', False)"
>
> The problem is that in my case, I don't have filters to change the
> context. And it's not possible to change the context from an
> on_change event (I could have bind on_change on my selection
> field).
>
> Any idea?
>

Revision history for this message
Husen Daudi (husendaudi) said :
#13

yeah, in your case it will not work, need development on client side.

Revision history for this message
Thibaut DIRLIK (Logica) (thibaut-dirlik) said :
#14

Thanks for your help.

Revision history for this message
Anton Chepurov (anton-chepurov) said :
#15

Has anybody found a solution to this problem?