Se rendre au contenu
Menu
Cette question a été signalée
3 Réponses
24093 Vues

I've created a filter for filter last month and last year of order it doesn't work correctly

<filter icon="terp-go-month" string="Last Year"
                         domain="[('date_order','&lt;=', (context_today()-relativedelta(day=31,months=12,years=1)).strftime('%%Y-%%m-%%d')),
                         ('date_order','&gt;=',(context_today()-relativedelta(day=1,months=1,years=1)).strftime('%%Y-%%m-%%d'))]"
                         help="last year"/>

<filter icon="terp-go-month" string="Last Month"
                         domain="[('date_order','&lt;=', (context_today()-relativedelta(day=31, months=1)).strftime('%%Y-%%m-%%d')),
                         ('date_order','&gt;=',(context_today()-relativedelta(day=1,months=1)).strftime('%%Y-%%m-%%d'))]"
                         help="last month"/>

and I create filter for month like this it works correctly

<filter icon="terp-go-month" string="Month"
                             name="month"
                             domain="[('date_order','&lt;=',
                             (context_today()+relativedelta(day=31)).strftime('%%Y-%%m-%%d')),
                             ('date_order','&gt;=',
                             (context_today()-relativedelta(day=1)).strftime('%%Y-%%m-%%d'))]"
                             help="current month"/>

I dont know why? Thank for support

Avatar
Ignorer
Meilleure réponse

This is a correct way to filter the current month. Use it to create your own filter:

<filter string="Current Month" name="current_month" domain="[('data','&lt;',(context_today()+relativedelta(months=1)).strftime('%%Y-%%m-01')), ('data','&gt;=',time.strftime('%%Y-%%m-01'))]"/>

This is an example of previous month:

<filter string="Prev Month" name="prev_month" domain="[('data','&gt;=',(context_today()-relativedelta(months=1)).strftime('%%Y-%%m-01')),('data','&lt;',time.strftime('%%Y-%%m-01'))]"/>
Avatar
Ignorer

The problem is, maybe, in another point

Meilleure réponse

This is an example of 'Last Year':

<filter string="Last Year" domain="[('reg_date','&gt;=',(context_today()-relativedelta(years=1)).strftime('%%Y-01-01')),('reg_date','&lt;=', time.strftime('%%Y-01-01'))]"/>


This is an example of 'Last Month':

<filter string="Last Month" domain="[('reg_date','&gt;=',(context_today()-relativedelta(months=1)).strftime('%%Y-%%m-01')),('reg_date','&lt;',time.strftime('%%Y-%%m-01'))]"/>


Avatar
Ignorer
Publications associées Réponses Vues Activité
3
avr. 23
34306
1
janv. 16
11311
0
mars 15
5025
1
avr. 24
14201
3
mars 15
20659