Skip to Content
Menu
This question has been flagged
1 Reply
7337 Views

How I can filter the orm search_read([]) with today, lasth month, this month

something like

a = self.env['model.model'].search_read([today])

a = self.env['model.model'].search_read([month])

a = self.env['model.model'].search_read([last_month])


I need to filter create today, create this month, create lasth_month

Avatar
Discard
Best Answer

Hi, 

Did you try the following:

from dateutil.relativedelta import relativedelta

1- Today: 

a = self.env['model.model'].search_read([('create_date', '=', fields.datetime.now())])
2- Monthly:

a = self.env['model.model'].search_read(
[('create_date', '>=', fields.datetime.now()), ('create_date', '=<', fields.datetime.now() + relativedelta(months=1))])

3- Last month:

a = self.env['model.model'].search_read(
[('create_date', '=<', fields.datetime.now()), ('create_date', '>=', fields.datetime.now() + relativedelta(months=1))])

hop this helps you. If not, write back for further analysis.

Regards.

Avatar
Discard