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
- Boekhouding
- Voorraad
- PoS
- Project
- MRP
Deze vraag is gerapporteerd
2
Antwoorden
3637
Weergaven
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
Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!
Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!
AanmeldenGerelateerde posts | Antwoorden | Weergaven | Activiteit | |
---|---|---|---|---|
|
3
aug. 25
|
2576 | ||
|
1
mei 25
|
2616 | ||
|
1
apr. 25
|
3597 | ||
|
1
apr. 25
|
4463 | ||
|
1
apr. 25
|
1924 |