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.

1

What kinds of operations are available on a recordset?

By
Atte Isopuro
on 9/3/14, 4:31 AM 2,514 views

If we obtain a recordset of model instances (through search() or browse()), what kinds of operations are available? Can recordsets be added (set + set)? Can they be appended to (setA.append(record))?

Does the recordset behave like some well known Pythonic structure (like list)? If not, is there some kind of reference that lists what operations are and aren't available?

6

Dhinesh - Technical Consultant, Sodexis Inc

--Dhinesh - Technical Consultant, Sodexis Inc--
3577
| 5 4 9
Pondicherry, India
--Dhinesh - Technical Consultant, Sodexis Inc--

Passionate coder in Python/OpenERP. Knows Django/Flask MVC frameworks. Did code in Java, PHP.

Contact me at: dvdhinesh.mail@gmail.com

Dhinesh - Technical Consultant, Sodexis Inc
On 9/3/14, 4:37 AM

Hi, Operations on recordset are

record in recset1           # include
record not in recset1       # not include
recset1 + recset2           # extend
recset1 | recset2           # union
recset1 & recset2           # intersect
recset1 - recset2           # difference

Thank you for the prompt answer. I was also wondering if there are list-like operations available for single recordsets, like recordset[3:7] to get records 3 through 7 from the recordset?

Atte Isopuro
on 9/3/14, 4:55 AM
2

Akhil P Sivan

--Akhil P Sivan--
3423
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 10/29/15, 11:36 PM

Hi,

Other recordset operations:

1. sorted(): To sort a recordset

# sort records by name
recset.sorted(key=lambda r: r.name)


2. filtered(): To filter a recordset:

# only keep records whose company is the current user's
records.filtered(lambda r: r.company_id == user.company_id)

# only keep records whose partner is a company
records.filtered("partner_id.is_company")


3. mapped(): To map a recordset by applying the provided function to each record in the recordset and returns a recordset if the results are recordsets.

recordset.mapped(lambda record: record.amount + record.tax_amount)

# returns a list of name
recset.mapped('name')

# returns a recordset of partners
recset.mapped('invoice_id.partner_id')


0
Osval Reyes
On 10/29/15, 7:35 PM

Is there anyway to apply a .search([]) call in a recordset?

I'm not aware of being able to do this directly. What you need to do is explicitly narrow your domain to that recordset using the recordset's 'ids' attribute. So say you have a recordset partners, and you want to find out which of those partners are suppliers. Then you would do:

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

Atte Isopuro
on 9/16/16, 6:03 AM

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: 9/3/14, 4:31 AM
Seen: 2514 times
Last updated: 10/30/15, 3:35 AM