Odoo Help


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.


How to use method search to get the ids from a date interval?

Anabela Damas
on 9/15/14, 7:31 AM 508 views


I need to get the ids of the invoices between an interval with the start date and end date inclusive, and from this just the invoices in state paid , and type in_refund ?

I've like this :  

invoice_obj.search(cr, uid,[('date_invoice', '>=', date_from ),('date_invoice', '<=', date_to),('type','in', ['in_refund']),('state','=','paid') ])

But the result isn't the expected. 

What is the way to do it?



| 5 4 6
Zagreb | Karlovac, Croatia

there is only 10 kind of people the ones that understand binary ... and others

On 9/15/14, 7:45 AM

Serach method are using polish notation . basicly when you do some_obj.search(cr, uid, [ XXXX ])

Now.. [ XXX] can contain only one comparation.. like [ ('date_invoice','>=', date_from )] .. that is easy... 
If more then one comparation tuple is needed, then you need to put extra logical operators wich are: '|' = OR, '&' = AND ...

In your case, i would write search like this:
['&','&','&',('date_invoice', '>=', date_from ),('date_invoice', '<=', date_to),('type','in', ['in_refund']),('state','=','paid') ]

in order to serach for records that sattisfy ALL condition tuples, the way you wrote it will be interpreted as:

[('date_invoice', '>=', date_from ) OR ('date_invoice', '<=', date_to) OR ('type','in', ['in_refund']) OR ('state','=','paid') ]


I hope this will help a bit

Qamar Soft
On 9/15/14, 7:54 AM

use this:

invoice_obj.search(cr, uid,['&','&','&',('date_invoice', '>=', date_from ),('date_invoice', '<=', date_to),('type','in', ['in_refund']),('state','=','paid') ])

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)


Asked: 9/15/14, 7:31 AM
Seen: 508 times
Last updated: 3/16/15, 8:10 AM