Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


ODOO9: invisible field through a python function

Drees Far
on 5/6/16, 11:03 AM 348 views


I want to make a field invisble in the view xml.

I want to create function and call the function in my wml and there decide if the field will be invisible or not just like with DOMAIN.

Can anyone help me know how to realise that.

Thanks a lot ;)

post your code , that you have done so far

Prakash Sharma
on 5/6/16, 11:39 AM
Ajeng Shilvie
On 6/23/16, 5:04 AM

Hi Dress 

Try using this as example :

def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):

if not context: context = {}

res = super(your_class_name, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)

#call your_function_here

doc = etree.XML(res['arch'])

if your_function_condition :

    nodes_your_field_name = doc.xpath("//field[@name='your_field_name']")

    for node in nodes_your_field_name:

    node.set('invisible', 'True')

res['arch'] = etree.tostring(doc)

return res

Don't forget to import the library

from lxml import etree


Drees Far

--Drees Far--
| 5 2 6
Tunis, Tunisia
--Drees Far--
Drees Far
On 5/6/16, 11:46 AM

Here is the XML code.

                                        <field name="structure_salariale" on_change="onchange_structure(structure_salariale,type_id)" attrs="{'invisible':[('name_contract','in', ['Mandataire','SIVP'])], 'required':[('name_contract','not in', ['Mandataire','SIVP'])]}"/>

But, i want to use a function to controle this not in xml.

But, question is can we use function with invisible attribute

override the fields_view_get of the model

Prakash Sharma
on 5/6/16, 12:48 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 5/6/16, 11:03 AM
Seen: 348 times
Last updated: 6/23/16, 5:04 AM