Estoy haciendo una aplicación en python que obtiene algunos campos customizados del modelo sale.order para un servidor externo de etiquetas, el archivo ya funcionaba en una versión de Odoo v12 pero recientemente estoy migrando este proceso para Odoo v15, sin embargo, al enviar el json que trae de vuelta la info en los campos manda el siguiente error:
2022-08-30 22:23:02,868 16792 ERROR yuju odoo.http: Exception during JSON request handling.
Traceback (most recent call last):
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Odoo 15e\server\odoo\http.py", line 643, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "C:\Odoo 15e\server\odoo\http.py", line 301, in _handle_exception
raise exception.with_traceback(None) from new_cause
werkzeug.exceptions.BadRequest:
400 Bad Request: <function Home.index at 0x000002F31ABDD318>, /: Function declared as capable of handling request of type 'http' but called with a request of type 'json'
Esta es la configuración del programa y la función que manda a llamar la info desde odoo:
dir_path = os.path.dirname(os.path.realpath(__file__))
server_url ='http://localhost:8090/'
db_name = 'yuju'
username = 'odoo'
password = '1234'
json_endpoint = "%s/jsonrpc" % server_url
headers = {"Content-Type": "application/json"}
def get_json_payload(service, method, *args):
return json.dumps({
"jsonrpc": "2.0",
"method": 'call',
"params": {
"service": service,
"method": method,
"args": args
},
"id": 6,
})
user_id = 6
def get_order_id(name):
try:
payload = get_json_payload("common", "version")
response = requests.post(json_endpoint, data=payload, headers=headers)
if user_id:
search_domain = [['name', '=', name]]
payload = get_json_payload("object", "execute_kw",db_name, user_id, password,'sale.order', 'search_read', [search_domain, ['marketplace_order_id', 'name', 'seller_marketplace']],
{'limit': 1})
print(payload)
res = requests.post(json_endpoint, data=payload, headers=headers)#.json()
#logging.info(default_code+str(res))
print (res)
marketplace_order_id = res['result'][0]['marketplace_order_id']
print('marketplace_order_id', marketplace_order_id)
seller_marketplace = res['result'][0]['seller_marketplace']
order_odoo_id = res['result'][0]['id']
return dict(marketplace_order_id = marketplace_order_id, seller_marketplace =seller_marketplace, order_odoo_id = order_odoo_id )
else:
logging.error("Failed: wrong credentials")
return False
except Exception as e:
logging.error ('Error:'+str(e))
return False
Debugeando pude ver que es justo en la línea que contiene lo siguiente donde se genera el error:
res = requests.post(json_endpoint, data=payload, headers=headers)#.json()
ACTUALIZACIÓN
El error anterior era debido a que la variable json_endpoint ya tiene una diagonal y chocaba con la digonal final de la variable server_url, coloco a continuación la correción:
server_url ='http://localhost:8090' #aquí estaba el fallo
json_endpoint = "%s/jsonrpc" % server_url
además instalé en odoo una aplicación que viene por defecto llamada test_rpc para solicitudes rpc y json-rpc como librería de python
El error que tengo ahora es este:
Traceback (most recent call last):
File "C:\Odoo 15e\server\odoo\http.py", line 141, in dispatch_rpc
result = dispatch(method, params)
File "C:\Odoo 15e\server\odoo\service\model.py", line 41, in dispatch
res = fn(db, uid, *params)
File "C:\Odoo 15e\server\odoo\service\model.py", line 94, in wrapper
return f(dbname, *args, **kwargs)
File "C:\Odoo 15e\server\odoo\service\model.py", line 176, in execute
res = execute_cr(cr, uid, obj, method, *args, **kw)
File "C:\Odoo 15e\server\odoo\service\model.py", line 160, in execute_cr
result = odoo.api.call_kw(recs, method, args, kw)
File "C:\Odoo 15e\server\odoo\api.py", line 457, in call_kw
result = _call_kw_model(method, model, args, kwargs)
File "C:\Odoo 15e\server\odoo\api.py", line 430, in _call_kw_model
result = method(recs, *args, **kwargs)
File "C:\Odoo 15e\server\odoo\models.py", line 5012, in search_read
records = self.search(domain or [], offset=offset, limit=limit, order=order)
File "C:\Odoo 15e\server\odoo\models.py", line 1810, in search
res = self._search(args, offset=offset, limit=limit, order=order, count=count)
File "C:\Odoo 15e\server\odoo\models.py", line 4675, in _search
if expression.is_false(self, args):
File "C:\Odoo 15e\server\odoo\osv\expression.py", line 229, in is_false
elif token[1] == 'in' and not (isinstance(token[2], Query) or token[2]):
IndexError: tuple index out of range