i have a model using fields that has date type, i try to get month from date but i can't
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Księgowość
- Zapasy
- PoS
- Project
- MRP
To pytanie dostało ostrzeżenie
2
Odpowiedzi
6688
Widoki
You just have to use python datetime library.
Ex:
from datetime import datetime
# Get month from your date
datetime.strftime(datetime.strptime(your_date_field, "%Y-%m-%d"), %m)
(This works for Odoo 11 or older versions... for odoo 12 there are important changes in this matter)
Using the Sudhir's answer as a base:
from datetime import datetime
...
...
def _get_month(self, date):
"""Get month from date"""
return datetime.strftime(datetime.strptime(date, "%Y-%m-%d"), "%m")
...
...
self.month = _get_month(self.date)
Podoba Ci się ta dyskusja? Dołącz do niej!
Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!
Zarejestruj się