Search code examples
apiodooopenerp-8

Odoo 8 - records browse equivalent with new api?


I read Odoo 8 new api documentation, but could not find it (if there is any). How to directly browse record/records with new api, when you have that models id/ids?

For example let say I want to browse res.partner model and have list of ids: ids = [1, 2, 3].

With old api, you could do it like this:

partners = self.pool.get('res.partner').browse(cr, uid, ids)

With new api, the only way I could think of was to use search as it returns records (not ids as in old api), like this:

partners = self.env['res.partner'].search([('id', 'in', ids)])

This gives same results, but I'm wondering about performance (is it the same?) and convenience (to avoid using search, when you already know ids, just need to browse the records)?

Or search is preferred way in new api to be used when you need to browse records?


Solution

  • You can still use browse with the new api. There is much less reason to do so, because with the new API you usually deal with sets of records, instead of lists of numeric ids. But you absolutely can use browse during the odd times when you actually need it:

    partner_ids = [1, 2, 3]
    partners = self.env['res.partner'].browse(partner_ids)