Handle Date and Datetime Variables In Odoo XML Domain

Hello…!!

I was creating the dashboard for an object in odoo where there was filtering on data based on specific definite.

I came across this scenario I hope this would helpful and can reduce your development time.

Image

Odoo Domain To Get The Data For Current Date

[(“DATE_TYPE_VARIABLE_NAME”, “=”, context_today().strftime(‘%Y-%m-%d’))]

Odoo Domain To Get The Data For Current Week

[(‘DATE_TYPE_VARIABLE_NAME’ , ’>=’, (context_today() — relativedelta(days=context_today().weekday())).strftime(‘%Y-%m-%d’)),
(‘DATE_TYPE_VARIABLE_NAME’, ’<=’, ((context_today() — relativedelta(days=context_today().weekday())) + relativedelta(days=6)).strftime(‘%Y-%m-%d’))]

Odoo Domain To Get The Data For Current Month

[(‘create_date’, ’>=’, context_today().strftime(‘%Y-%m-01’)), (‘create_date’, ’<’,(context_today()+relativedelta(months=1)).strftime(‘%Y-%m-01’))]

Odoo Domain To Get The Data of Previous Month

[(‘create_date’, ’<’, context_today().strftime(‘%Y-%m-01’)),
(‘create_date’, ’>’, (context_today()-relativedelta(months=1)).strftime(‘%Y-%m-01’))]

Thanks.

--

--