Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
15 Vastaukset
50767 Näkymät

First, is it possible? Because, I have a code which works perfectly in Form (to hide or not), but whenever I put the same code on a tree view, it doesn't work.

<field name="arch" type="xml">
            <tree string="the tree">
                <field name="group_name" invisible="1"/>
                <field name="date_register" attrs="{'invisible':[('group_name','==',True)]}"/>
Avatar
Hylkää
Paras vastaus

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
Hylkää

worked for me , thanks
but can I understand what parent represents? ( I know it's the parent view that tree is embeded in) but how odoo understand it ?

Paras vastaus

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.

Avatar
Hylkää
Tekijä

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?

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.

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

Paras vastaus

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.

Avatar
Hylkää
Tekijä

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

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.

Paras vastaus

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
Hylkää
Paras vastaus

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

Avatar
Hylkää
Tekijä

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

Paras vastaus

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
Hylkää
Paras vastaus

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)]}"/>

Avatar
Hylkää
Tekijä

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

Paras vastaus

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
Hylkää