Odoo Help


Domain to filter the newest record?

Eyal Marantenboim
on 10/14/13, 3:57 AM 1,510 views


I have a list of documents (knowledge), I have my views where I filter these document by 'parent_id'. I wanted to know if there's a way to have a domain/filter that will show me:

  1. Only the newest document with parent_id='1'
  2. All the document with parent_id='1' excluding the newest.


How would you accomplish this with an SQL SELECT statement? That should inform how you'd accomplish it in a domain, since the domain is essentially the contents of the WHERE clause.

Brett Lehrer
on 10/21/13, 5:03 PM

I'd do some kind of 'sort by' and then 'limit 1'.. is there a way to do this with domains?

Eyal Marantenboim
on 10/21/13, 7:06 PM

Brett Lehrer

--Brett Lehrer--

| 5 5 8
Milwaukee, United States
--Brett Lehrer--
Director of IT and open source enthusiast.
Brett Lehrer
On 10/21/13, 9:47 PM

Ordering and result limiting are both separate parts of the search function, unrelated to domain. Check the technical memento for the search() method on page 4: https://www.openerp.com/files/memento/OpenERP_Technical_Memento_v0.7.4.pdf

You'll have to put it into a separate function to generate the proper search result, but it would look something like this:

# newest_id will be a list of length 1, not an integer
newest_id = self.search(cr, uid, [('parent_id','=',1)], limit=1, order='id desc')

Once you have the id of the newest record, you can difference that from the unlimited list of IDs after doing another search without the limit.

other_ids = self.search(cr, uid, [('parent_id','=',1)], limit=1, order='id desc')
other_ids = other_ids - newest_id

About This Community

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


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 10/14/13, 3:57 AM
Seen: 1510 times
Last updated: 3/16/15, 8:10 AM