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
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
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,
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng ký