Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

2

Filter last year and last month

By
sepdau
on 4/24/13, 6:22 AM 5,581 views

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

4

Francesco OpenCode

--Francesco OpenCode--
3608
| 5 7 9
Grottaglie, Italy
--Francesco OpenCode--

Italian Odoo (OpenERP) Modules Developer LINKEDIN: http://www.linkedin.com/in/francescoapruzzese

Francesco OpenCode
On 4/24/13, 3:44 PM

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'))]"/>

The problem is, maybe, in another point

Francesco OpenCode
on 6/19/13, 10:31 AM
1
Niraj Pajwani
On 5/17/16, 5:51 AM

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'))]"/>


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 4/24/13, 6:22 AM
Seen: 5581 times
Last updated: 6/13/16, 3:28 PM