Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
8689 Visualizzazioni

When i am saving any record the id of the current record is only fetched but i want to fetch all the ids of the table.

Any idea??

Avatar
Abbandona
Risposta migliore

You can fetch all IDs of particular object by passing blank list [] in search method.

For example you can fetch all the IDs of the purchase.order like this:

purchase_order_ids = self.pool.get('purchase.order').search(cr, uid, [], context=context)

In background it will be executed like this:

select id from purchase_order

There are two methods which can be called when you click on save button

  1. create: when you create new record.
  2. write: when you update existing record.

You can overwrite create & write methods and inside it you can search for IDs.

Create is called when you create the records:

def create(cr, uid, vals, context=None):
    #Todo code
    my_search_ids = self.pool.get('object.name').search(cr, uid, [], context=context)
    #Todo code
    return super(your_class_name, self).create(cr, uid, vals, context=context)

Write is called when you update the records:

def write(cr, uid, ids, vals, context=None):
    #Todo code
    my_search_ids = self.pool.get('object.name').search(cr, uid, [], context=context)
    #Todo code
    return super(your_class_name, self).write(cr, uid, ids, vals, context=context)
Avatar
Abbandona
Risposta migliore

By using search method you can fetch all ids of that method. Suppose you want to fetch all the records of the purchase order. Write self.pool.get('purchase.order').search(cr, uid, [])

Avatar
Abbandona