Last active
January 23, 2023 10:29
-
-
Save Dj0ulo/4c2dff962140b8f55055765c5e46d58f to your computer and use it in GitHub Desktop.
Bug rpc odoo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/odoo/addons/base/controllers/rpc.py b/odoo/addons/base/controllers/rpc.py | |
index e18b8acc4210..099b9ef03d8f 100644 | |
--- a/odoo/addons/base/controllers/rpc.py | |
+++ b/odoo/addons/base/controllers/rpc.py | |
@@ -6,6 +6,7 @@ from datetime import date, datetime | |
from markupsafe import Markup | |
from werkzeug.wrappers import Response | |
+from collections import defaultdict | |
import odoo | |
from odoo.http import Controller, route, dispatch_rpc, request | |
@@ -72,8 +73,8 @@ def xmlrpc_handle_exception_string(e): | |
class OdooMarshaller(xmlrpc.client.Marshaller): | |
dispatch = dict(xmlrpc.client.Marshaller.dispatch) | |
- def dump_frozen_dict(self, value, write): | |
- value = dict(value) | |
+ def dump_dict(self, value, write): | |
+ value = dict((str(k), v) for k, v in value.items() if v) | |
self.dump_struct(value, write) | |
# By default, in xmlrpc, bytes are converted to xmlrpc.client.Binary object. | |
@@ -104,7 +105,9 @@ class OdooMarshaller(xmlrpc.client.Marshaller): | |
v = value._value | |
return self.dispatch[type(v)](self, v, write) | |
- dispatch[frozendict] = dump_frozen_dict | |
+ dispatch[dict] = dump_dict | |
+ dispatch[defaultdict] = dispatch[dict] | |
+ dispatch[frozendict] = dispatch[dict] | |
dispatch[bytes] = dump_bytes | |
dispatch[datetime] = dump_datetime | |
dispatch[date] = dump_date |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import random | |
import urllib.request | |
host, db, username, password, account_move_id = "http://localhost:8569", 'oes_wycc1', 'admin', 'admin', 11 | |
def json_rpc(url, method, params): | |
data = { | |
"jsonrpc": "2.0", | |
"method": method, | |
"params": params, | |
"id": random.randint(0, 1000000000), | |
} | |
req = urllib.request.Request(url=url, data=json.dumps(data).encode(), headers={ | |
"Content-Type":"application/json", | |
}) | |
reply = json.loads(urllib.request.urlopen(req).read().decode('UTF-8')) | |
if reply.get("error"): | |
raise Exception(reply["error"]) | |
return reply["result"] | |
def call(url, service, method, *args): | |
return json_rpc(url, "call", {"service": service, "method": method, "args": args}) | |
# log in the given database | |
url = f'{host}/jsonrpc' | |
uid = call(url, "common", "login", db, username, password) | |
try: | |
res = call(url, "object", "execute", db, uid, password, 'account.move', 'read', [account_move_id]) | |
print(res) | |
except Exception as e: | |
print(str(e).replace("\\n","\n")) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import xmlrpc.client | |
host, db, username, password, account_move_id = "http://localhost:8569", 'oes_wycc1', 'admin', 'admin', 11 | |
common = xmlrpc.client.ServerProxy(f'{host}/xmlrpc/2/common') | |
uid = common.authenticate(db, username, password, {}) | |
models = xmlrpc.client.ServerProxy(f'{host}/xmlrpc/2/object') | |
try: | |
res = models.execute_kw(db, uid, password, 'account.move', 'read', [account_move_id]) | |
print(res) | |
except Exception as e: | |
print(str(e).replace("\\n","\n")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment