Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
8713 Переглядів

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??

Аватар
Відмінити
Найкраща відповідь

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)
Аватар
Відмінити
Найкраща відповідь

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, [])

Аватар
Відмінити