Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
5 Risposte
12142 Visualizzazioni

Use case : In the CRM app, I want to be able to filter on the task changed this week/last24H/no change in the past 30 days.


How to :


1. Create a new filter with the date you want to filter in Odoo with studio (search view). Any filter would work, we just need Studio to create a view. 


2. Open the studio view that was created (Odoo Studio: MODEL.search.inherit.VIEW customization) 


3. Change the domain :


CHANGED THIS WEEK : 

domain="[('date','<',time.strftime('%%Y-%%m-%%d 23:59:59')),('date','>=',(datetime.date.today()-datetime.timedelta(days=7)).strftime('%%Y-%%m-%%d 00:00:00'))]"


CHANGED THIS DAY  : 

domain="[('date','<',time.strftime('%%Y-%%m-%%d 23:59:59')),('date','>=',(datetime.date.today()-datetime.timedelta(hours=24)).strftime('%%Y-%%m-%%d 00:00:00'))]"


NO CHANGE LAST 30 DAYS

domain="[('date','<',(datetime.date.today()-datetime.timedelta(days=30)).strftime('%%Y-%%m-%%d 00:00:00'))]"


'date' = update this field and use the name of field you need to filter.


********

Example : 

<xpath expr="//filter[@name='activities_upcoming_all']" position="after">

<separator/>

<filter name="stage_change_week" string="Stage Changed This Week"  domain="[('date_last_stage_update','&lt;',time.strftime('%%Y-%%m-%%d 23:59:59')),('date_last_stage_update','>=',(datetime.date.today()-datetime.timedelta(days=7)).strftime('%%Y-%%m-%%d 00:00:00'))]"/>

<filter name="stage_change_day" string="Stage Changed 24 Hrs" domain="[('date_last_stage_update','&lt;',time.strftime('%%Y-%%m-%%d 23:59:59')),('date_last_stage_update','>=',(datetime.date.today()-datetime.timedelta(hours=24)).strftime('%%Y-%%m-%%d 00:00:00'))]"/>

<filter name="no_stage_change_month" string="No Stage Change 30 Days" domain="[('date_last_stage_update','&lt;',(datetime.date.today()-datetime.timedelta(days=30)).strftime('%%Y-%%m-%%d 00:00:00'))]"/>

</xpath>

Avatar
Abbandona

Hello,

If you're looking for a dynamic solution for date filters, other filters, or group by options, check out the link below, it could be helpful.
https://apps.odoo.com/apps/modules/17.0/cr_smart_filters

Thanks,
info@creyox.com

Risposta migliore

Doesn't work anymore on v17,


Anytips ?

Avatar
Abbandona
Risposta migliore

Marked as solved

Avatar
Abbandona
Risposta migliore

Interesting, but why this is not embedded in Odoo directly? It's useful for dashboards...

Avatar
Abbandona
Risposta migliore

The following structure works in v17: 

[("date", "<", (datetime.date.today()+datetime.timedelta(days=7)))]

Avatar
Abbandona
Risposta migliore

I have used this example to make a filter for vendor bills that are due in the coming week. Thanks a lot!

domain="[('invoice_date_due','<',(datetime.date.today()+datetime.timedelta(days=7)).strftime('%%Y-%%m-%%d 00:00:00')),'&', ('state', '=', 'posted'), ('payment_state', 'not in', ('paid', 'in_payment','reversed'))]"/>

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
ott 21
4886
3
feb 25
29442
2
mar 24
4458
1
ott 22
83
1
mag 21
5391