Odoo Help

Welcome!

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

0

how to fetch all id of table when saving the record?

By
Chintan Ram
on 4/15/13, 11:10 AM 2,181 views

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

3

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 4/15/13, 11:28 AM

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)
1

Keyur

--Keyur--
1165
| 4 4 8
Ahmedabad, India
--Keyur--

Odoo Expert

Keyur
On 4/15/13, 11:20 AM

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 4/15/13, 11:10 AM
Seen: 2181 times
Last updated: 3/16/15, 8:10 AM