I have a 'day/month' string, I want to convert that string to date object and compare the last day of than month to another date
Example:
For '08/2021' (august, 2021) i whant to compare the last day of that month (31-08-2021) to another date (date field),
For '02/2020' i what to compare 29-02-2020 < another_date (date field)
For '02/2021' i what to compare 28-02-2020 < another_date (date field)
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
Hello,
You could do something like this:
# get the string field in the format "mm/yyyy" and add 1 to the date
date_object = datetime.datetime.strptime("1/"+record.string_date, "%d/%m/%Y")
# add a month to the date object and minus a day to get last day of month
date_object = date_object + dateutil.relativedelta.relativedelta(months=1) + dateutil.relativedelta. relativedelta(days=-1)
id date_object < record.other_date:
# if the date field is less than another field, do something
The idea is to get the first day of the field month, add a month to get the first day of the next month and minus a day to get the last day of the field month.
I think this would be the best way to solve this problem using the libraries supplied by Odoo using the UI. This is an example of how it would look in a server action, you just need to change the fields to the fields which are in your database table.
I hope this helps,
Thanks,
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!
Aanmelden