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.

1

Next week filter

By
Yogesh
on 2/16/15, 9:44 PM 1,083 views

How to create next week filter not from today's date +/- 7 days but from Monday to Sunday of next week.

This is a python question in general and does not have much to do with Odoo. Nonetheless, lookup the python docs for datetime and the gregorian calendar. You can get week information and even an entire calendar out with simple imports.

Ludo - Neobis
on 2/17/15, 6:27 AM

@Ludo-Neobis: You may be right but unfortunately you are not. I can do this in python to get next monday but datetime.weekday() is not supported by openerp xml, gives error and is not able to filter. next_mondy = datetime.today() + timedelta(days=(7 - datetime.today().weekday()))

Yogesh
on 2/17/15, 11:18 AM
0
Yogesh
On 2/17/15, 1:20 PM

I am using following code for compute next week filter, It does correct computation on python terminal but in filter it gives no result

<filter string = "Next Week" domain="[( 'date_deadline', '&gt;=', (context_today() + relativedelta(weeks=0, weekday=0)).strftime('%Y-%m-%d')) ,  ( 'date_deadline', '&lt;', (context_today() + relativedelta(weeks=1, weekday= 0, days = 6)).strftime('%Y-%m-%d')  )]" />

It is because context_today and relativedelta are not available during the domain evaluation time.

Ivan
on 2/17/15, 1:56 PM

@Ivan: but that's not right, filter for last week works

Yogesh
on 2/17/15, 10:08 PM
0

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 2/17/15, 7:20 AM

In the Advance Search, you can enter phrases like: Last Monday, Next Sunday to date fields.

@Ivan : Interesting but this won't work because I need filter between Next Monday and Next to Next Sunday. Also In Advance filter user has calendar to choose dates but I need this behaving dynamically.

Yogesh
on 2/17/15, 11:34 AM
-1

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 2/17/15, 11:57 AM

You define computed field next_mondy_start and next_mondy_end and use them as domain filter.

UPDATE:

In my test system, this example, with stored fields, filter works without any problem:

<field name="domain">[('test_dt','=',True)]</field>

   

@api.one
    @api.depends(
      'test',
    )
    def _get_dates(self):
        self.start = fields.Datetime.from_string(fields.Datetime.now()) + relativedelta(weeks=0, weekday=0)
        self.stop = fields.Datetime.from_string(fields.Datetime.now()) + relativedelta(weeks=0, weekday= 0, days = 6)
        self.test_dt = self.stop > self.test > self.start

    test = fields.Datetime('Date Test')  
    test_dt = fields.Boolean('Test dt',compute='_get_dates',store=True)
    start = fields.Datetime('Start',compute='_get_dates',store=True)
    stop = fields.Datetime('Stop',compute='_get_dates',store=True)

PS. start and stop fields are unnecessary

          

 

those will be stored field? how those fields will be computed every day when date changes?

Yogesh
on 2/17/15, 1:17 PM

Not stored. Function based on fields.Datetime.now() or today().

zbik
on 2/17/15, 1:59 PM

so I defined next_week_monday = fields.Date(string='Next Week Monday', compute='_get_nextweek_monday'), added field in tree view, date is computed correctly. then added in filter and it gave me error on web client "Error: Failed to evaluate search criterions: {"code":400,"message":"Evaluation Error","data":{"type":"local_exception","debug":"Local evaluation failure\nNameError: name 'next_week_monday' is not defined\n\n{\"domains\":[[],\"[('date_deadline', '

Yogesh
on 2/17/15, 10:38 PM

I think I was wrong. Probably filter determine SQL and those must be stored.

zbik
on 2/18/15, 1:57 AM

stored works?

zbik
on 2/19/15, 10:19 AM

Stored works without problems, answer updated.

zbik
on 2/19/15, 4:04 PM

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

1 follower(s)

Stats

Asked: 2/16/15, 9:44 PM
Seen: 1083 times
Last updated: 9/3/15, 3:15 PM