Skip to Content
Menu
This question has been flagged
5 Replies
3398 Views

Hi all, 

how can I filter with 'OR' and 'AND'?

I would like to filter following:
['|', [('date', '=', (datetime.now() + timedelta(days=3)).strftime('%Y-%m-%d')), ('country_id', '!=', 'Germany')],
[('date', '=', (datetime.now() + timedelta(days=3)).strftime('%Y-%m-%d'))), ('country_id', '=', 'Germany')]]

In words:
Country != Germany AND date = 3 days in the future
OR
Country = Germany AND dates = 1 day in the future.


This gives me the error: ValueError: <class 'TypeError'>: "unhashable type: 'list'" while evaluating 


What am I doing wrong?

Thanks!

Avatar
Discard

Please specify that in which you want AND and OR.

Author

@Mital I updated my text above.

This tips will help you in odoo customization: https://github.com/sehrishnaz/learnopenerp/wiki

Best Answer

Hello ,

please try this code,

['|','&',
('country_id','!=','Germany'),
('date','=', (datetime.now() + timedelta(days=3)).strftime('%Y-%m-%d')),
'&',
('country_id','=','Germany'),
('date','=', (datetime.now() + timedelta(days=1)).strftime('%Y-%m-%d')),
]

Hope this will help you,

Thanks,


Avatar
Discard
Author

Hi Malay!

Thanks for you answer! It's working!!

Best Answer

Use the below code and try:

['|', (('date', '=', (datetime.now() + timedelta(days=3)).strftime('%Y-%m-%d')), ('country_id', '!=', 'Germany')),
(('date', '=', (datetime.now() + timedelta(days=3)).strftime('%Y-%m-%d'))), ('country_id', '=', 'Germany'))]

Avatar
Discard
Author

I get following error:

ValueError: <class 'ValueError'>: "Invalid leaf (('date', '=', '2019-10-04'), ('country_id', '!=', 'Germany'))" while evaluating