maharshi maharshi - 11 months ago 55
Python Question

How to get all the columns from id and filter to specific column? odoo9

I am getting the id of a customer by

customer = context.get('partner_id')
print customer


Now i want to fetch all the values of all columns from
id == 6

This will will give me many a recordset i guess

How do i filter the recordset so i can get the value which i want to work with.

Or if it is possible can i get the specific columns value not all. (that would be great)

If possible tell me how to do it in

Answer Source

Old api

self.pool.get('res.partner').search(cr, uid, [('id', '=', customer)])

This would return a list of id's that matched the search so you have to call browse to actually get the records

New api

self.env['res.partner'].search([('id', '=', customer)])

to get only a specific column, instead of all columns use the search_read method it's very similar to search only that it takes a second argument which is a list of the attributes you're interested in and it returns a list of dictionaries instead of a record sets. so let's say we're only interested in the column value

self.env['res.partner'].search_read([('id', '=', customer)], ['value'])

your result should look like this

[{'id': 1, 'value': 'some value'}, ...]