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??
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
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
create
: when you create new record.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, [])
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up