0

I am working on a code of exporting values to excel using xlwt and came across the following error

TypeError: can't subtract offset-naive and offset-aware datetimes

Here's my code

for leave in leave_data:
    tes = ''
    date1 = ''
    user_pool = self.env['res.users']
    user = user_pool.browse(SUPERUSER_ID)
    tz = pytz.timezone(user.partner_id.tz) or pytz.utc
    date1 = pytz.utc.localize(datetime.strptime(leave.date_from, 
DEFAULT_SERVER_DATETIME_FORMAT)).astimezone(tz)
    single_leave_data = []
    single_leave_data.append(leave.employee_id.name)
    single_leave_data.append(leave.employee_id.x_EmployeeId)
    single_leave_data.append(date1)

I am not able to figure out the reason behind this error. I have searched for many solutions, but none seem to work.

Satendra
  • 6,755
  • 4
  • 26
  • 46
Shravy
  • 656
  • 1
  • 23
  • 61
  • Are you sure the error is being raised from this part of the code? Could you confirm the line number in your traceback? Also, I'd suggest using `ipdb` to debug this. – Indradhanush Gupta Feb 19 '18 at 05:24
  • Yes Indradhanush Gupta, I get while appending it to the list. Traceback shows error coming out from xlwt package file.. – Shravy Feb 19 '18 at 06:03
  • File "/home/administrator/Test_OdooDemo/python/lib/python2.7/site-packages/xlwt/Row.py", line 104, in __excel_date_dt delta = date - epoch TypeError: can't subtract offset-naive and offset-aware datetimes – Shravy Feb 19 '18 at 06:03
  • In that case the code you have posted is probably not relevant to the error. The `date` variable is offset-naive in this case and you should look into `Row.py` and see where that variable is being passed from. – Indradhanush Gupta Feb 20 '18 at 05:58

0 Answers0