2
votes

I am trying to make a module for Odoo and I don't know how to hide a field using python code This line doesn't work for me :

'form_id': fields.many2one('dev.test', 'candidat', select=False,invisible=True),

I want to hide it using python and not using xml because I didn't declare that many2one field in my xml it's just a simple field in my test relation, the field will be created inside the popup to create new "formation".

This is the definition of the field that make the relationship

    'test_form_ids': fields.one2many('dev.form', 'form_id','formations'),

test_form_ids one2many field capture

This is my formation class

class dev_form(osv.Model):
_name='dev.form'
_description='rel between test & formations'

_columns = {
    'name': fields.many2one('dev.name', 'Formation'),
  'form_id': fields.many2one('dev.test', 'candidat', select=False,invisible=True),
}

highlighted the field I want to hide here the popup to create new formation capture

1
If you want to hide any field than it's simple to not write in .xml file as in your case. Following link will be help you. stackoverflow.com/questions/27553169/… stackoverflow.com/questions/26054744/…Bhavesh Odedra
I didn't understand your solution because I can't see any python code in it... I tried using atrrs in python it doesn't work too 'cand_lan_id': fields.many2one('dev.test', 'test', select=False,attrs="{'invisible':True}"'),' can you please explainkhaled bed
If you want to hide field by programmatic than we need to override method. In which condition you want to hide that field ?Bhavesh Odedra
I want to remove it from the users view without any conditions, it seems a bit silly but I can't find a better solution I just need that field to make the one2many relationship ,sorry, am I doing it the wrong way?khaled bed
there is no xml, it's a field inside a relationshipkhaled bed

1 Answers

2
votes

You need to open your view .xml file where cand_lan_id you declared.

Now replace field

<field name="cand_lan_id"/>

with

<field name="cand_lan_id" invisible="1"/>

invisible="1" is attribute which will hide your field from the User.

EDIT:

Open .xml file in which test_form_ids field is declare.

Now replace field

<field name="test_form_ids"/>

with

<field name="test_form_ids">
    <form string="Form Name">
        <field name="name"/>
        <field name="form_id" invisible="1"/>
        <!-- List of field that User want to see in form view -->
    </form>
    <tree string="Form Name" editable="bottom">
        <field name="name"/>
        <!-- List of field that User want to see as a columns -->
    </tree>
</field>