This question has been flagged
2 Replies
3260 Views

Hi, 

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?
Thanks

Avatar
Discard
Best Answer

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

Avatar
Discard
Best Answer

use this:

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

Avatar
Discard