Ir al contenido
Menú
Se marcó esta pregunta
4 Respuestas
9134 Vistas

Hello Community

I have a problem , i have on2many tree-view with multiple columns(fields) , i want some fields to be shown under Condition (A) and the others on Condition(B)  without hiding the Fields in condition A  , i tried the attrs it didn't work I've tried some solution like this : invisible="context.get('type') == 'out_invoice' "   but it work only one if i change the condition later the fields still hiding 

Avatar
Descartar
Mejor respuesta

hello 

you can hide column using the following example. this example available in sale order. 

you can try like this

<field name="qty_invoiced"attrs="{'column_invisible': [('parent.state', 'not in', ['sale', 'done'])]}"/>

Avatar
Descartar
Mejor respuesta
This is for Account Move line 
set as per your requiremt 
@api.model
def fields_view_get(self, view_id=None, view_type=False, toolbar=False, submenu=False):
res = super(AccountMoveLine, self).fields_view_get(view_id, view_type, toolbar=toolbar, submenu=submenu)
print ('----type---', view_type)
if view_type == 'tree':
print ('OOOOOOOOOOOOOOOOOO')
doc = etree.XML(res['arch'])
partner_string = _('Supplier')
for node in doc.xpath("//field[@name='partner_id']"):
node.set('string', partner_string)
for node in doc.xpath("//field[@name='name']"):
node.set('invisible', 'True')
doc.remove(node)

res['arch'] = etree.tostring(doc)
return res
Avatar
Descartar
Mejor respuesta

You have to do it by inheriting the fields_view_get function.

This example is for sale order line view, just modify to meet you requirements to hide product_id column

@api.model   

def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
        res = super(yourClassName, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar,                     submenu=submenu)

         if res['name'] == 'thisIsTheIDofYourView': #to filter your view
         doc = etree.XML(res['fields']['order_line']['views']['tree']['arch'])

         if CONDITION A:
                for node in doc.xpath("//field[@name='product_id']"):
                    node.set('invisible', '0')                   

                    setup_modifiers(node)

        res['fields']['order_line']['views']['tree']['arch'] = etree.tostring(doc)

return res

Avatar
Descartar
Autor

Thank you Juan for your answer , unfortunately it didn't work in my case