Skip to content

Commit

Permalink
Merge pull request #26 from odoo-java/16.0-MIG-API-TRY2
Browse files Browse the repository at this point in the history
[WIP][MIG][16.0]Odooo 16
  • Loading branch information
flotho authored Feb 9, 2024
2 parents 183fe11 + f057b8b commit 7f8b827
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 18 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.odoojava</groupId>
<artifactId>odoo-java-api</artifactId>
<version>3.2.2</version>
<version>3.3.3</version>
<packaging>jar</packaging>

<name>odoo-java-api</name>
Expand Down
48 changes: 31 additions & 17 deletions src/main/java/com/odoojava/api/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
* *
Expand Down Expand Up @@ -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");
}

}

/**
Expand Down Expand Up @@ -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();
Expand All @@ -246,17 +247,22 @@ private int authenticate_json_rpc() throws Throwable {
// TODO: fast and uggly implementation of json rpc, has to be refactored in the
// future

Map<String, String> articleMapOne = new HashMap<>();
articleMapOne.put("password", password);
articleMapOne.put("login", userName);
articleMapOne.put("db", databaseName);
jsonclient.setServiceUrl(getJsonurl("jsonrpc"));
Map<String, Object> jsonparams = new HashMap<>();
jsonparams.put("service", "common");
jsonparams.put("method", "login");

// Object[] result = call_json_rpc(, "common", "login", articleMapOne);
ArrayList<Object> methodparams = new ArrayList<>();
methodparams.add(databaseName);
methodparams.add(userName);
methodparams.add(password);
//TODO : maybe also use the same syntax as reporting
jsonparams.put("args", methodparams);

jsonclient.setServiceUrl(getJsonurl("web/session/authenticate"));
int result = jsonclient.invoke("call", jsonparams, int.class);

Map<String, Object> 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<Object> args)
Expand All @@ -275,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<Object> 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;

}
Expand Down

0 comments on commit 7f8b827

Please sign in to comment.