pythonodooodoo-website

Activate a field in a form, via boolean checkmarks - Odoo v8


I'm having this task to complete, and I'm wondering how to do it on Odoo v8.

Let's say I have three fields, ie:

columns = {
    'field1' : fields.char("My char"),
    'field2' : fields.integer("My integer"),
    'field3' : fields.selection([("tuple1", 'Tuple 1'),("tuple2", 'Tuple 2'), ("tuple3", 'Tuple 3')], "My tuple collection"),

Now, these fields will be rendered on a form into the Odoo's website, I have that covered right now, with controllers, decorators, etc.

My dilemma is, how can I activate which fields will be shown on the form with a boolean checkmark?

Let's say when I activate two of these three fields, the two activated will be rendered on the form.

I don't know if I'm explaining myself...

If you still have doubts please ask me...

Any ideas?

Thanks in advance...


Solution

  • You can define a boolean field:

    selected = fields.Boolean(search='_search_dummy', store=False)
    

    in this way it is not stored into db. Just define an empty _search_dummy method

    Then you can put it into the view and when defining the other field:

    <field name="selected"/>
    <field name="field1" attrs="{'invisible':[('selected','=',False)]}"/>  
    <field name="field2" attrs="{'invisible':[('selected','=',True)]}"/>
    

    field1 will be visible only if you check the selected field, field2 will be visible only if you uncheck the selected field.