Assert isinstance(value, datetime.datetime) or value is None

class Signature(ModelSQL, ModelView):
    """User Signature."""

    __name__ = "user.signature"
    _history = True

    signed_by = fields.Many2One('res.user', 'Signed By', required=True)
    signed_on = fields.DateTime('Signed On', required=True)
    ea = fields.Many2One(
        'hr.allo', 'ea Bill', ondelete='CASCADE')
    action = fields.Char('Action')
    signature = fields.Char('Signature')
Imports::
    >>> from trytond.tests.tools import activate_modules
    >>> from proteus import config, Model
    >>> import datetime
    >>> from dateutil.relativedelta import relativedelta
    >>> today = datetime.date.today()
    >>> yesterday = today - relativedelta(days=1)
    
Create user signature

   >>> Signature = Model.get('user.signature.ea')
   >>> signature = Signature()
   >>> signed_by_user = Model.get('res.user')
   >>> Signed_by_user, = signed_by_user.find([('id', '=', 1)])
   >>> signature.signed_by_user = Signed_by_user
   >>> signature.signed_on = today
  >>>  signature.save()

Failed example:
signature.signed_on = today

Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python3.8/doctest.py", line 1336, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest cea.rst[75]>", line 1, in <module>
        signature.signed_on = today
      File "/home/sa/workspace/tryton/tryton50/lib/python3.8/site-packages/proteus/__init__.py", line 237, in __set__
        assert isinstance(value, datetime.datetime) or value is None
    AssertionError

You must fill a DateTime field with a datetime.datetime instance not a datetime.date.

1 Like