Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

odoorpc is not able to manage jsonfield in v16 (account_move_line with analytic_distribution) #90

Closed
vanderperre opened this issue Jul 18, 2023 · 1 comment
Labels

Comments

@vanderperre
Copy link

Module

The name of the module that has a bug.
odoorpc

Describe the bug

odoorpc is not able to manage jsonfield in v16

To Reproduce

Affected versions:
16.0

Steps to reproduce the behavior:
1.odoo = odoorpc.ODOO(url, port=port)
2.odoo.login(database, user, psw)
3.Mod = odoo.env['account.move.line']
4.records = Mod.search_read([],[], limit=5)

because the analytic_distribution field (json field) we have an exception:
keys must be str, int, float, bool or None, not frozendict

Also, i have try with the "read" method, obviously we have the same ;)
# ids = Mod.search_read(domain, ['id'], limit=limit)
# ids = [elem['id'] for elem in ids]
# records = odoo.execute(Mod._name, 'read', ids)

Expected behavior
We expect a stringify json value for analytic_distribution ....

@sebalix
Copy link
Collaborator

sebalix commented Aug 23, 2023

Hello,

I tested, and JSON field analytic_distribution is working well. But I was able to reproduce the issue not on analytic_distribution but on compute_tax_all with a really simple RPC call:

o.env["account.move.line"].read(IDS, ["compute_all_tax"])
o.env["account.move.line"].read([8830], ["compute_all_tax"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/salix/dev/OCA/odoorpc/odoorpc/models.py", line 59, in rpc_method
    result = cls._odoo.execute_kw(cls._name, method, args, kwargs)
  File "/home/salix/dev/OCA/odoorpc/odoorpc/odoo.py", line 524, in execute_kw
    data = self.json(
  File "/home/salix/dev/OCA/odoorpc/odoorpc/odoo.py", line 273, in json
    raise error.RPCError(
odoorpc.error.RPCError: keys must be str, int, float, bool or None, not frozendict

An RPCError is raised, meaning that an exception probably occurred on the server, not in OdooRPC, and indeed on the server we can see this:

2023-08-23 18:13:08,486 1 ERROR DB-20230807-164544 odoo.http: Exception during request handling. 
Traceback (most recent call last):
  File "/odoo/src/odoo/http.py", line 1998, in __call__
    response = request._serve_db()
  File "/odoo/src/odoo/http.py", line 1584, in _serve_db
    return service_model.retrying(self._serve_ir_http, self.env)
  File "/odoo/src/odoo/service/model.py", line 133, in retrying
    result = func()
  File "/odoo/src/odoo/http.py", line 1611, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
  File "/odoo/src/odoo/http.py", line 1818, in dispatch
    return self._response(result)
  File "/odoo/src/odoo/http.py", line 1854, in _response
    return self.request.make_json_response(response)
  File "/odoo/src/odoo/http.py", line 1438, in make_json_response
    data = json.dumps(data, ensure_ascii=False, default=date_utils.json_default)
  File "/usr/lib/python3.9/json/__init__.py", line 234, in dumps
    return cls(
  File "/usr/lib/python3.9/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.9/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
TypeError: keys must be str, int, float, bool or None, not frozendict

So it is a bug on Odoo side, in fact this type of field is still in development, and today it can be used only internally in Odoo code but cannot be used on a view for instance (try to display this field on any account.move.line view and you'll trigger the same error, I just checked). In other words, this type of field cannot be read by the RPC layer of Odoo itself.

Still, this Odoo bug is blocking you because you are requesting all fields when using read or search_read with the empty list [] as first parameter. What you can do is requesting all fields except this compute_all_tax:

Mod = odoo.env['account.move.line']
fields = list(Mod._columns)    # Get all fields of 'account.move.line'
fields.remove("compute_all_tax")    # Remove the buggy field
records = Mod.search_read(fields,[], limit=5)

As it is not a bug tied to OdooRPC, I'm closing the issue.

Have a good day,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants