I have a datetime field in my sale order, how i add filter by in portal list view , for filtering last week,last monthe,last year using python controller.How i add domain in this code .
searchbar_filters = {
'today': {
'label': 'Today',
'domain': []
},
'week': {
'label': 'Last Week',
'domain': []
},
'month': {
'label': 'Last Month',
'domain': []
},
'year': {
'label': 'Last Year',
'domain': []
}
}
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Contabilidad
- Inventario
- PoS
- Project
- MRP
Se marcó esta pregunta
2
Respuestas
3493
Vistas
Hi,
from dateutil.relativedelta import relativedelta
from odoo.tools import date_utils
write this code in your controller:
today = fields.Date.today()
last_week = today + relativedelta(weeks=-1)
last_month = today + relativedelta(months=-1)
last_year = today + relativedelta(years=-1)
searchbar_filters = {
'today': {
'label': 'Today',
'domain': [("date", ">=",
fields.Datetime.to_string(fields.Datetime.today())), (
"date", "<=", fields.Datetime.to_string(
fields.Datetime.today().replace(hour=23, minute=59,
second=59)))]
},
'week': {
'label': 'Last Week',
'domain': [('date', '>=', date_utils.start_of(last_week, "week")),
('date', '<=', date_utils.end_of(last_week, 'week'))]
},
'month': {
'label': 'Last Month',
'domain': [('date', '>=', date_utils.start_of(last_month, 'month')),
('date', '<=', date_utils.end_of(last_month, 'month'))]
},
'year': {
'label': 'Last Year',
'domain': [('date', '>=', date_utils.start_of(last_year, 'year')),
('date', '<=', date_utils.end_of(last_year, 'year'))]
}
}
Regards
You can add the domains as below ( Replace 'Your_datetime_field' with your datetime field:
searchbar_filters = {
'all': {'label': _('All'), 'domain': []},
'today': {'label': _('Today'), 'domain': [("Your_datetime_field", ">=", fields.Datetime.to_string(fields.Datetime.today())),("Your_datetime_field", "<=", fields.Datetime.to_string(fields.Datetime.today().replace(hour=23, minute=59, second=59)))]},
'last_week': {'label': _('Last week'), 'domain': [('Your_datetime_field', '>=', date_utils.start_of(last_week, "week")),
('Your_datetime_field', '<=', date_utils.end_of(last_week, 'week'))]},
'last_month': {'label': _('Last month'),
'domain': [('Your_datetime_field', '>=', date_utils.start_of(last_month, 'month')),
('Your_datetime_field', '<=', date_utils.end_of(last_month, 'month'))]},
'last_year': {'label': _('Last year'), 'domain': [('Your_datetime_field', '>=', date_utils.start_of(last_year, 'year')),
('Your_datetime_field', '<=', date_utils.end_of(last_year, 'year'))]},
}
Also you need to import the below:
from odoo.tools import date_utils
¿Le interesa esta conversación? ¡Participe en ella!
Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.
InscribirsePublicaciones relacionadas | Respuestas | Vistas | Actividad | |
---|---|---|---|---|
|
1
may 25
|
2417 | ||
|
1
abr 25
|
3435 | ||
|
1
abr 25
|
4255 | ||
|
1
abr 25
|
1746 | ||
|
4
mar 25
|
6850 |