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.

0

Domain to filter the newest record?

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

Hi,

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.

thanks!

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
0

Brett Lehrer

--Brett Lehrer--
1252
| 5 4 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

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: 10/14/13, 3:57 AM
Seen: 1046 times
Last updated: 3/16/15, 8:10 AM