I have a trouble with implementing the user field validation based on the constraint that at least one of the fields is mandatory
the trouble code:
'required': Equal(Eval('business_phone'), '') and Equal(Eval('home_phone'), '') and Equal(Eval('business_cellphone'), '') and Equal(Eval('personal_cellphone'), '')
}
_dep = ['business_phone', 'home_phone', 'business_cellphone', 'personal_cellphone']
in this script:
from trytond.model import fields, ModelSQL, ModelView
from trytond.pool import PoolMeta, Pool
from trytond.pyson import Eval, Equal, If, And, Bool, Not, Or
class Contact(ModelSQL, ModelView): #Exo 1
"emp Contact"
__name__ = 'hr.contact'
_req = {
'required': Equal(Eval('business_phone'), '') and Equal(Eval('home_phone'), '') and Equal(Eval('business_cellphone'), '') and Equal(Eval('personal_cellphone'), '')
}
_dep = ['business_phone', 'home_phone', 'business_cellphone', 'personal_cellphone']
emp = fields.Many2One('company.emp', 'emp', required=True)
first_name = fields.Char('First Name', required=True)
last_name = fields.Char('Last Name', required=True)
business_phone = fields.Char('Phone (Work)', required=_req, depends=_dep)
home_phone = fields.Char('Phone (Home)', required=_req, depends=_dep)
business_cellphone = fields.Char('Professional Cell', required=_req, depends=_dep)
personal_cellphone = fields.Char('Personal Cell', required=_req, depends=_dep)
active = fields.Boolean('Active')
del _req, _dep
@staticmethod
def default_active():
return True
then i get the error :
Traceback (most recent call last):
File "/usr/local/lib/python37/dist-packages/trytond/wsgipy", line 109, in dispatch_request
return endpoint(request, **requestview_args)
File "/usr/local/lib/python37/dist-packages/trytond/protocols/dispatcherpy", line 48, in rpc
request, database_name, *requestrpc_params)
File "/usr/local/lib/python37/dist-packages/trytond/wsgipy", line 77, in auth_required
return wrapped(*args, **kwargs)
File "/usr/local/lib/python37/dist-packages/trytond/protocols/wrapperspy", line 131, in wrapper
return func(request, pool, *args, **kwargs)
File "/usr/local/lib/python37/dist-packages/trytond/protocols/dispatcherpy", line 212, in _dispatch
response = appmake_response(request, result)
File "/usr/local/lib/python37/dist-packages/trytond/wsgipy", line 128, in make_response
response = clsresponse(data, request)
File "/usr/local/lib/python37/dist-packages/trytond/protocols/jsonrpcpy", line 185, in response
response, cls=JSONEncoder, separators=(',', ':')),
File "/usr/lib/python37/json/__init__py", line 238, in dumps
**kw)encode(obj)
File "/usr/lib/python37/json/encoderpy", line 199, in encode
chunks = selfiterencode(o, _one_shot=True)
File "/usr/lib/python37/json/encoderpy", line 257, in iterencode
return _iterencode(o, 0)
File "/usr/local/lib/python37/dist-packages/trytond/protocols/jsonrpcpy", line 68, in default
return marshaller(obj)
File "/usr/lib/python37/json/encoderpy", line 179, in default
raise TypeError(f'Object of type {o__class____name__} '
TypeError: Object of type Equal is not JSON serializable
Could you tell me why and how to solve it?