From 568a2ff437220e15cbee01f6af4e3c9dedff9663 Mon Sep 17 00:00:00 2001 From: Florent THOMAS Date: Tue, 14 Nov 2023 13:50:08 +0100 Subject: [PATCH 1/3] [IMP]Use proper entry point for JSONRPC authentication --- pom.xml | 2 +- src/main/java/com/odoojava/api/Session.java | 35 ++++++++++++--------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index 216e389..1a5e7ce 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.odoojava odoo-java-api - 3.2.2 + 3.3.1 jar odoo-java-api diff --git a/src/main/java/com/odoojava/api/Session.java b/src/main/java/com/odoojava/api/Session.java index 385c321..6514da7 100644 --- a/src/main/java/com/odoojava/api/Session.java +++ b/src/main/java/com/odoojava/api/Session.java @@ -30,7 +30,6 @@ import com.odoojava.api.OdooXmlRpcProxy.RPCProtocol; import com.odoojava.api.OdooXmlRpcProxy.RPCServices; import com.googlecode.jsonrpc4j.*; -import com.googlecode.jsonrpc4j.JsonRpcClientException; /** * * @@ -183,11 +182,10 @@ public void startSession() throws Exception { private void checkVersionCompatibility() throws XmlRpcException, OdooApiException { - if (this.getServerVersion().getMajor() < 8 || this.getServerVersion().getMajor() > 15) { - throw new OdooApiException("Only Odoo Version from v8.x to 15.x are maintained. " + if (this.getServerVersion().getMajor() < 8 || this.getServerVersion().getMajor() > 16) { + throw new OdooApiException("Only Odoo Version from v8.x to 16.x are maintained. " + "Please choose another version of the library"); } - } /** @@ -222,12 +220,15 @@ int authenticate() throws XmlRpcException, Exception { // JSONRPC part try { - // id = authenticate_json_rpc(); + id = authenticate_json_rpc(); System.out.println("json rpc login"); } catch (JsonRpcClientException e) { - System.out.println("Json rpc issue possibly caused by https://github.com/OCA/server-tools/issues/1237"); - e.printStackTrace(); + if (this.getServerVersion().getMajor() == 10){ + System.out.println("ODOO 10.0 : Json rpc issue possibly caused by https://github.com/OCA/server-tools/issues/1237"); + e.printStackTrace(); + System.out.println("ODOO 10.0 : if the trace match the issue, you could ignore this message"); + } } catch (Throwable e) { System.out.println("General exception"); e.printStackTrace(); @@ -246,17 +247,21 @@ private int authenticate_json_rpc() throws Throwable { // TODO: fast and uggly implementation of json rpc, has to be refactored in the // future - Map articleMapOne = new HashMap<>(); - articleMapOne.put("password", password); - articleMapOne.put("login", userName); - articleMapOne.put("db", databaseName); + jsonclient.setServiceUrl(getJsonurl("jsonrpc")); + Map jsonparams = new HashMap<>(); + jsonparams.put("service", "common"); + jsonparams.put("method", "login"); - // Object[] result = call_json_rpc(, "common", "login", articleMapOne); + ArrayList methodparams = new ArrayList<>(); + methodparams.add(databaseName); + methodparams.add(userName); + methodparams.add(password); + jsonparams.put("args", methodparams); - jsonclient.setServiceUrl(getJsonurl("web/session/authenticate")); + int result = jsonclient.invoke("call", jsonparams, int.class); - Map result = jsonclient.invoke("call", articleMapOne, HashMap.class); - return (int) result.get("uid"); + return (int) result; + } public Object[] call_report_jsonrpc(String reportModel, String reportMethod, ArrayList args) From 9d045badfa9dbec1a1e2c73671a79ee5e72371a6 Mon Sep 17 00:00:00 2001 From: Florent THOMAS Date: Tue, 14 Nov 2023 14:14:40 +0100 Subject: [PATCH 2/3] [IMP]json rpc needs empty record when @api.model is used --- pom.xml | 2 +- src/main/java/com/odoojava/api/Session.java | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 1a5e7ce..8628fe5 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.odoojava odoo-java-api - 3.3.1 + 3.3.2 jar odoo-java-api diff --git a/src/main/java/com/odoojava/api/Session.java b/src/main/java/com/odoojava/api/Session.java index 6514da7..103b630 100644 --- a/src/main/java/com/odoojava/api/Session.java +++ b/src/main/java/com/odoojava/api/Session.java @@ -256,6 +256,7 @@ private int authenticate_json_rpc() throws Throwable { methodparams.add(databaseName); methodparams.add(userName); methodparams.add(password); + //TODO : maybe also use the same syntax as reporting jsonparams.put("args", methodparams); int result = jsonclient.invoke("call", jsonparams, int.class); @@ -280,12 +281,20 @@ public Object[] call_report_jsonrpc(String reportModel, String reportMethod, Arr methodparams.add(password); methodparams.add(reportModel); methodparams.add(reportMethod); - methodparams.add(args); + ArrayList empty_recordset_for_model_annotation_in_odoo = new ArrayList<>(); + //The render method is annotated @model in Odoo, so we must pass an empty value as the first + //paramter otherwise Odoo will only interpret 1 parameter from the 2 given + //TODO: find a way to identify if a metho is annotated with @api.model + args.add(0, empty_recordset_for_model_annotation_in_odoo ); + methodparams.add(args); jsonparams.put("args", methodparams); - Object[] result = jsonclient.invoke("call", jsonparams, Object[].class); + // methodparams.add(args); + // jsonparams.put("args", methodparams); + // Object[] result = jsonclient.invoke("call", jsonparams, Object[].class); + return result; } From f057b8be11453b456773d7ad6d22730c23eac0ce Mon Sep 17 00:00:00 2001 From: Florent THOMAS Date: Fri, 9 Feb 2024 23:25:43 +0100 Subject: [PATCH 3/3] BUMP version Doc : explain the printing regression --- README.md | 14 ++++++++++++++ pom.xml | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b474cc0..b018c13 100644 --- a/README.md +++ b/README.md @@ -118,3 +118,17 @@ saveToDatabaseForTrackingPurpose(newPartner.getID()); * https://sourceforge.net/p/openerpjavaapi/wiki/Dependencies/ * https://sourceforge.net/p/openerpjavaapi/wiki/Examples/ + + +# Known bugs + +Since v14, the render method is now private. +So printing is no more possible with rpc call. +For the references : +* https://github.com/odoo/odoo/issues/78528 +* https://github.com/OCA/odoorpc/issues/65 + +A workaround is to create a module to make the render method public until we implement this method https://github.com/OCA/odoorpc/issues/88#issuecomment-1907870776 +a better workaround is to propose a PR in this repo to implement the missing part + + diff --git a/pom.xml b/pom.xml index 8628fe5..62a40c1 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.odoojava odoo-java-api - 3.3.2 + 3.3.3 jar odoo-java-api