跳至内容
菜单
此问题已终结
2 回复
4258 查看

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

形象
丢弃
最佳答案

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

形象
丢弃
最佳答案

use this:

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

形象
丢弃
相关帖文 回复 查看 活动
22
12月 23
49333
8
7月 24
16240
2
3月 15
5654
0
3月 15
8344
1
3月 15
3800