Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
3 Vastaukset
24110 Näkymät

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
Hylkää
Paras vastaus

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
Hylkää

The problem is, maybe, in another point

Paras vastaus

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
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
3
huhtik. 23
34322
1
tammik. 16
11327
0
maalisk. 15
5041
1
huhtik. 24
14217
3
maalisk. 15
20673