I tried to export datetime field of Attendance but i am getting wrong date time value. It is giving UTC date time instead my my timezone datetime.
How can i resolve this issue? Please help me.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
I tried to export datetime field of Attendance but i am getting wrong date time value. It is giving UTC date time instead my my timezone datetime.
How can i resolve this issue? Please help me.
I just update in main.py file of controller of Web module. You can do this in inherit the main.py file.
Import below package in main.py
from dateutil.parser import parse
import datetime
import pytz
-->Update in CSVExport class for CSV. Add below code in this class.
def check_date(self, value):
try:
parse_data = parse(value)
return parse_data
except Exception as e:
return False
Update from_data() function like below code.
def from_data(self, fields, rows):
fp = io.BytesIO()
writer = pycompat.csv_writer(fp, quoting=1)
writer.writerow(fields)
for data in rows:
row = []
for d in data:
if isinstance(d, pycompat.string_types) and d.startswith(('=', '-', '+')):
d = "'" + d
if type(d) is str:
parse_data = self.check_date(d)
if parse_data:
if len(d) > 10:
tz = pytz.timezone(request._context.get('tz'))
d = (pytz.utc.localize(datetime.datetime.strptime(d,'%Y-%m-%d %H:%M:%S')).astimezone(tz)).strftime('%Y-%m-%d %H:%M:%S')
row.append(pycompat.to_text(d))
writer.writerow(row)
return fp.getvalue()
-->For Excel Update below code in ExcelExportV class in datetime condition.
elif isinstance(cell_value, datetime.datetime):
tz = pytz.timezone(request._context.get('tz'))
cell_value = (pytz.utc.localize(cell_value).astimezone(tz)).strftime('%Y-%m-%d %H:%M:%S')
cell_style = datetime_style
After that, restart your odoo service and check.
Hello, nice feedback, I will try for my reports; btw, I'm having a problem with UTC-0; some date fields are not getting our correct tz for interpretation in Odoo, like: a ticket in UI shows create_day as 31/07/2019 22:00:00 (UTC -4), but from server (i think its server), it's set at 01/08/2019 02:00:00 (UTC-0), in display while we group it for month it will be shown in August instead of July, that is making trouble for us in all ways, and we don't know if changing the server timezone (have tried but failed) would affect Odoo usage for 1 company or multicompany. You know a way to solve this?
Sorry for commenting on another issue, and forgive me for my english, im not native.
Thanks beforehand.
Rodrigo
All datetime information is exported in the UTC timezone, no matter your local timezone. This is so all Users anywhere in the world can collaborate. If your Business Support team in San Jose, California extracts data and sends it to the New York City office to be updated who then sends it to the London office, the only way this works is with a common underlying timezone. By using UTC we prevent any data corruption due to a User importing data while in a different timezone than the User who exported it.
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
0
Nov 24
|
58 | ||
|
0
Mar 15
|
3082 | ||
|
1
Mar 15
|
5909 | ||
|
2
Jul 22
|
2745 | ||
|
3
Feb 20
|
5848 |
There is no way to export the date in your timezone. You can change it in excel.