Help

2

Filter last year and last month

Avatar
sepdau

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
Discard
2 Answers
4
Best Answer

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'))]"/>
1 Comment
Avatar
Discard
Avatar
Francesco OpenCode
-

The problem is, maybe, in another point

2
Avatar
Niraj Pajwani
Best Answer

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
Discard