Hello, When creating a filter in the client, how can I indicate in the domain to filter on the stock moves before (the date of today - 10 days) for example? I tried different expressions but that didn't work. Thanks.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
The model stock.move
uses a timestamp value for field date
. The following domain should return all moves where the date is earlier than today - 10 days
:
[('date','<=', ((context_today()-datetime.timedelta(days=10)).strftime('%Y-%m-%d')))]
I assume, that you use the domain in a window action. If you want to use it in a view, you should use <=
instead of <=
.
Thank you very much, that worked.
+1 for this good answer As said Francesco, in a view you need to escape the % using %%
Hello, you used the context_today () like domain in the model and it works perfectly, but I try to do it with a datetime field and shows me an error message.
The code I use is
'agenda_id': fields.many2one ('delphos.citamedica.agenda', 'Agenda', required = True, domain = "[('doctor_id', '=', doctor_id), ('date', '> =', ((context_today ()). strftime ('% Y-% m-% d% H:% m:% S'))), ('date_deadline', '<=', ((context_today ()). strftime ('% Y-% m-% d% H:% m:% S')))] "),
The error message says: Uncaught Error: ValueError: No known conversion for% H
That could be my mistake?
probably there should not be a space between "%" and "H"?
Thank you very much for sharing this solution. It has helped me very much.
How great it is that the documentation says almost nothing about this.
Try this:
[('date', '>=', (context_today() - datetime.timedelta(10)).strftime('%%Y-%%m-%%d') )]
Unfortunately, that doesn't work.
If you share the error we can help you. Why this code doesn't work?
There's no error, it's a filter I'm creating in a view, when I use it I don't get my lines filtered. This is probably because filters in the views differ from the other filters. Anyway, thanks for your answer.
+1 for the format for views
It worked fine with just one %.
[('date', '>=', (context_today() - datetime.timedelta(10)).strftime('%Y-%m-%d') )]
The only expression that works is:
[('move_ids.date', '=' , (time.strftime('%Y-%m-%d'))]
I don't know how to integrate delay in it.
Thanks for the update. it works :). For your question you can find in search view for crm.lead examples for delays. Hope this is not too late. Cheers!
Thanks, but I didn't find the example you've mentioned in the crm.lead search view. Can you give the line number, please?
Hi, In view "crm.lead.report.select" first 3 or 4 lines are filter buttons which are using domain filters in views for current year, month or last month.
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
5
Sep 20
|
12682 | ||
|
1
Sep 16
|
56 | ||
|
0
Mar 15
|
4755 | ||
|
1
Mar 15
|
5141 | ||
|
2
Mar 15
|
7326 |
Now, I'd like to use this filter in a campaign segment. When I click on the "synchronize" button, I get an error "NameError: name 'context_today' is not defined". I don't understand why does this work only in sale order line view. Do you have any idea?