Help

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

Hide column tree view

Avatar
odoo
Avatar
Discard
8 Answers
0
Avatar
odoo
Best Answer

In order to have tour changes when you do a modification,, you need to upgrade the module and update it..That way you will see the changes, else you wont have any

Avatar
Discard
0
Avatar
odoo
Best Answer

You can use 'column_invisible' (Odoo 12 at least) attribute like this! :)

<field name="arch" type="xml">
    <tree string="the tree">
        <field name="group_name" invisible="1"/>
        <field name="date_register" attrs="{'column_invisible':[('parent.some_field_in_parent_record', '==', True)]}"/>

This works when your tree view is inside another view, for example a form. With 'parent' magic word you can access one of the fields in the parent.

As some other people pointed in this thread, hiding column fields for conditions based on tree lines is not possible, but here we use the parent, so no problem.

Avatar
Discard
0
Avatar
odoo
Best Answer

Imho in a Tree-View attr functionality does not work since a Tree-View displays several objects. There would be a problem if some of the objects fulfill the attr-domain and some do not.

Its not possible to hide a column only for certain objects.

3 Comments
Avatar
Discard
Avatar
odoo
-

Yes, I came to the same result searching "deeper" in google. It only hides the values, not the column it-self. Will this be available in next version or something?

Avatar
odoo
-

Instead of attrs="{'invisible':[('group_name','==',True)]}" It hides only data/content of that column. So, I tried to use invisible=context.get('group_name' = True" It hides the complete column from that Tree view.

Avatar
odoo
-

invisible= "Flag = True" this in not working for me. I am using open erp version 7,

Flag is my model variable , if selected date is before june 2017 flag value is false and seleted date is greater than jsune 2017 flag value is the false (GST,Service tax). Please help me

0
Avatar
odoo
Best Answer

If you want to hide a column in the tree view simply look for that column (this is for practice) in the code and add some thing like group=base.group_system for admin configuration login view or base.group_erp_manager for admin access right or base.group_extended for extended view only or base.group_user for all employees. You can also create your own group and add the id of this group to the field

   e.g <field name="you_required_column_id" group="base.group_user"/>

you can add this in the view code for the tree of your module.

<field name="arch" type="xml">
        <tree string="the tree">
            <field name="date_register" group="base.group_system"/>
<!-- this should hide this field from anyone that does not have admin configuration access-->

if you want to hide a column from a specific group a way you can do that is to create a group and add the group to all the other groups by inheritance except the one you don't wish to give access to then add the id of the created field as above.

2 Comments
Avatar
Discard
Avatar
odoo
-

Please, see the following link: http://pastebin.com/7ZG58pY9

Avatar
odoo
-

When you tried this were you logged in as an administrator or as a user with not admin right? After adding the group to the xml you will need to upgrage or reinstall the module, restarting the server will not affect changes made in your xml.

0
Avatar
odoo
Best Answer

In Tree view, it doesn't hide a complete column when you use attrs like this

attrs="{'invisible':[('group_name','==',True)]}

Because, I found it only hides the content in that column. So I tried to using

invisible="context.get('group_name') = True"

instead of above one. It hides the complete column in Tree view. I hope it will help you.

Avatar
Discard
0
Avatar
odoo
Best Answer

Hello

I have hide button in tree view using this code and its working fine for me

<button name="%(purchase.act_res_partner_2_supplier_invoices)d" icon="gtk-go-forward" type="action" attrs="{'invisible': ['|',('customer','=',True), ('interger_field','=',0)]}"/>

1 Comment
Avatar
Discard
Avatar
odoo
-

Please, see the following link: http://pastebin.com/7ZG58pY9

0
Avatar
odoo
Best Answer

As far as I know it is possible.. What type of field is your group_name?? It is possible to hide it but if you want to hide it then their is a certain condition that trigger to become visible i think it is not possible.. :D

1 Comment
Avatar
Discard
Avatar
odoo
-

It's not possible to hide a entire column with certain condition. Hope this is released soon.

0
Avatar
odoo
Best Answer

You can remove a column from a tree view, based on context or other conditions, by overriding fields view get:


    def fields_view_get(self, view_id=None, view_type='tree', toolbar=False, submenu=False):
result = super(ThisModel, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
if not self.env.context.get('show_the_column', False) and view_type == 'tree':
doc = etree.fromstring(result['arch'])
for field in doc.xpath('//field[@name="name_of_conditional_column"]'):
field.set('invisible', '1')
modifiers = json.loads(field.get('modifiers', '{}'))
modifiers['tree_invisible'] = True
modifiers['column_invisible'] = True
field.set('modifiers', json.dumps(modifiers))
result['arch'] = etree.tostring(doc)
return result
Avatar
Discard