Odoo Help


many2many field with check box

Francisco Castro
on 3/11/14, 8:59 AM 4,621 views

HI guys I Have a problem.

How can I do this: image description

add check box and when I tick in on of them shows the button "more" which allow to delete the selected rows

class wizard_pets(osv.osv):


          'owner_id':fields.many2one('gs.owner','ID Owner'),
          'epf_eligible': fields.boolean("eligible for EPF"),  

#preenche o campo many2many usa default para preencher logo no inicio
def _get_default_pet_ids(self, cr, uid, context=None):
    return self.pool.get('gs.pet').search(cr, uid, [])

#Filtra campo many2many com a opção que se escolha neste caso o owner
def onchange_owner_id(self, cr, uid, ids, val):
    ids = self.pool.get('gs.pet').search(cr, uid, [('owner_id','=',val)])
    return {'value' : {'pets' : ids}} 

_defaults = {
             'pets' : _get_default_pet_ids,


<record id="lista_pets_form" model="ir.ui.view">
        <field name="name">lista.pets.form</field>
        <field name="model">wizard.pets</field>
        <field name="arch" type="xml">
            <form string="Lista de Pets" version="7.0">

                <group string="Lista de Pet" col="1">

               <field name="owner_id" on_change="onchange_owner_id(owner_id)" widget="selection"/>

                <field name="pets"/>
                 <field name="epf_eligible"/> 

           <button name="Apagar" string="Apagar" type="object" class="oe_highlight"/>   


any advice?

Francisco Castro
on 3/11/14, 12:32 PM
Anton Chepurov
On 4/3/14, 10:27 AM


Try turning 'pets' into a many2many field. This will add the 'Add' button to your wizard, where you'll be able to select several pets at once. Moreover, 'Add' button will allow you to filter/search your pets before selecting -- a very useful feature, you fill find.

Deletion of records could be then completed with a dedicated button. 'More => Delete' solution would only work in a list view of pets, I guess.

If you need some code samples of how to work with multiple selection in m2m fields, the first thing to strike my head is automatic reconciliation of accounting entries. File /account/wizard/account_automatic_reconcile.py and its corresponding view. To see how it looks in UI, go to Accounting (or Invoicing ) => Periodic Processing => Reconciliation => Automatic Reconciliation.

Hope this helps.

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 3/11/14, 8:59 AM
Seen: 4621 times
Last updated: 3/16/15, 8:10 AM