跳至内容
菜单
此问题已终结
2 回复
8694 查看

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

形象
丢弃