8 答案
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
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.
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.
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.
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.
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)]}"/>
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
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