2

I am trying save record from django (front-end) to openerp (back-end). I am using openerp webservice using xmlrpclib. It works well with normal string and number data, but when i tried to pass date field, it throws error. cannot marshal <type 'datetime.date'> objects

Please help me..

Vimal Rughani
  • 234
  • 4
  • 14

2 Answers2

3

To solve the cannot marshal <type 'datetime.date'> objects error, first convert the date into ISO 8601 format, and then pass it as an object to xmlrpclib.

For example:

    dob = form.date_of_birth
    xmlrpc_dob = dob.strftime("%Y%m%dT%H:%M:%S")

For more details you can read the official Python documentation of xmlrpclib.

Bart Riordan
  • 436
  • 3
  • 8
  • 23
Vimal Rughani
  • 234
  • 4
  • 14
  • Actually, ISO 8601 requires dashes between year, month and day. Therefore, the strftime call becomes dob.strftime("%Y-%m-%dT%H:%M:%S"). Without the dashes, Odoo 10 still doesn't like the date. – BertD Oct 17 '18 at 20:02
0

Aternatively you can promote datetime.date() to datetime.datetime() before sending the reply.

gerod
  • 51
  • 1
  • 4