This question has been flagged
1 Reply
10189 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):

_name="wizard.pets"


_columns={
          'owner_id':fields.many2one('gs.owner','ID Owner'),
          'pets':fields.one2many('gs.pet','owner_id','teste'),
          '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,
             'epf_eligible':False
             }

wizard_pets()

<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"/>   

                 </group>
               </form>
                   </field>
               </record>
Avatar
Discard
Author

any advice?

Best Answer

Hi!

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.

Avatar
Discard