Skip to main content

Hi,

 

there are already some topics in the forum dealing with this - and as it seems it is not fixed yet. We did encountered the same problem here - on a odoo self hosted zap with a datetime value we do get

 

object of type 'DateTime' has no len()

 

Part of the payload which is problematic is this one (i think so)

<member>
<name>legal_basis_calculated</name>
<value><dateTime.iso8601>20220914T08:10:06</dateTime.iso8601></value>
</member>

 

It seems that a change in the python xmlrpc lib has caused this, because we get this value in the function to_datetime (on odoo side):

Got value: 20220914T08:24:05 of type: <class 'xmlrpc.client.DateTime'> 

 

And this function does not work with such an object type

 

You can work around on odoo side with this monkey patch

 

import xmlrpc.client
from odoo.fields import Datetime
from datetime import date, datetime, time
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT as DATETIME_FORMAT

@staticmethod
def to_datetime(value):
"""Convert an ORM ``value`` into a :class:`datetime` value.

:param value: value to convert.
:type value: str or date or datetime
:return: an object representing ``value``.
:rtype: datetime or None
"""
if not value:
return None
if isinstance(value, date):
if isinstance(value, datetime):
if value.tzinfo:
raise ValueError("Datetime field expects a naive datetime: %s" % value)
return value
return datetime.combine(value, time.min)
# Check for type xmlrpc.client.DateTime - and convert to python datetime
if isinstance(value, xmlrpc.client.DateTime):
return datetime.strptime(str(value), '%Y%m%dT%H:%M:%S')
# TODO: fix data files
return datetime.strptime(value, DATETIME_FORMATE:len(value) - 2])


# Monkey patch this one
Datetime.to_datetime = to_datetime

 

 

Hi @Eimsig Admin!

Thank you SO MUCH for sharing this workaround, I’m going to add a note on the other posts related to this to let the other members know about what you found  🙌🏻


Hello,

could someone of you please tell me how to use this monkey patch in odoo?

 

Thanks in advance,

Marco


Hello,

thank you for your help, it's great to see that the problem is not due to my date formatting ^^

Also, by any chance, isn't it possible for you to share your private application @Eimsig Admin

 ? Because paying 65€/month to patch their platform knowing that I have no use for odoo.sh is sad...

Thanks a lot! 
Simon

 


Reply