Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
3 Risposte
7827 Visualizzazioni

i want to export sale order to excel, but the date timezone is utc+0. my user is setted timezone to other.

how can i fix it?

Avatar
Abbandona
Risposta migliore

Hi,

See a sample code for getting the current time as in users timezone.


# Import the packages
from datetime import datetime
import pytz


user = self.env['res.users'].browse(self.env.uid)
# converting time to users timezone
if user.tz:
tz = pytz.timezone(user.tz) or pytz.utc
time = pytz.utc.localize(datetime.now()).astimezone(tz)
else:
time = datetime.now()


Thanks

Avatar
Abbandona
Risposta migliore

odoo 11

from odoo.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT, DEFAULT_SERVER_DATE_FORMAT
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
from datetime import datetime, timedelta, date
start = (datetime.strptime(self.your_date_time_field, DEFAULT_SERVER_DATETIME_FORMAT) + timedelta(hours=7)).strftime('%d/%m/%Y %H:%M:%S')







Avatar
Abbandona
Risposta migliore

If you do not use the export for a re-import, you can change the time in the Excel sheet.

Avatar
Abbandona