18
18
*/
19
19
package com .odoojava .api ;
20
20
21
- import java .util .ArrayList ;
21
+ import java .util .* ;
22
22
import javax .xml .bind .DatatypeConverter ;
23
23
24
- import java .io .InputStream ;
25
- import java .io .OutputStream ;
26
24
import java .net .MalformedURLException ;
27
25
import java .net .URL ;
28
26
import java .nio .ByteBuffer ;
29
- import java .nio .charset .Charset ;
30
- import java .util .HashMap ;
31
- import java .util .Map ;
32
27
33
28
import org .apache .xmlrpc .XmlRpcException ;
34
29
35
30
import com .odoojava .api .OdooXmlRpcProxy .RPCProtocol ;
36
31
import com .odoojava .api .OdooXmlRpcProxy .RPCServices ;
37
32
import com .googlecode .jsonrpc4j .JsonRpcHttpClient ;
38
- import com .odoojava .api .OdooApiException ;
39
- import java .util .Arrays ;
40
33
41
34
/**
42
35
* *
@@ -190,7 +183,7 @@ public void startSession() throws Exception {
190
183
private void checkVersionCompatibility () throws XmlRpcException , OdooApiException {
191
184
192
185
if (this .getServerVersion ().getMajor () < 8 || this .getServerVersion ().getMajor () > 13 ) {
193
- throw new OdooApiException ("Only Odoo Version from v8.x to 12 .x are maintained. "
186
+ throw new OdooApiException ("Only Odoo Version from v8.x to 13 .x are maintained. "
194
187
+ "Please choose another version of the library" );
195
188
}
196
189
@@ -278,10 +271,6 @@ public Object[] call_report_jsonrpc(String reportModel, String reportMethod, Arr
278
271
methodparams .add (reportModel );
279
272
methodparams .add (reportMethod );
280
273
methodparams .add ( args );
281
-
282
- // methodparams.put("color", 8);
283
- // methodparams.put("memo", "another note");
284
- // note_id = call(url, "object", "execute", DB, uid, PASS, 'note.note', 'create', args)
285
274
286
275
jsonparams .put ("args" , methodparams );
287
276
@@ -390,6 +379,36 @@ public Object executeCommand(final String objectName, final String commandName,
390
379
return objectClient .execute ("execute" , params );
391
380
}
392
381
382
+ /**
383
+ * Executes any command on the server linked to the /xmlrpc/object service. All
384
+ * parameters are prepended by: "databaseName,userID,password" This method
385
+ * execute the command without the context parameter Its purpose is to be used
386
+ * by Odoo version prior to v10 or for v10 methods that mustn't use the context
387
+ *
388
+ * @param objectName Object or model name to execute the command on
389
+ * @param commandName Command name to execute
390
+ * @param parameters List of parameters for the command. For easy of use,
391
+ * consider the OdooCommand object or ObjectAdapter
392
+ * @param context The user context
393
+ * @return The result of the call
394
+ * @throws XmlRpcException
395
+ */
396
+ public Object executeCommandKw (final String objectName , final String commandName , final Object [] parameters , Context context )
397
+ throws XmlRpcException {
398
+
399
+ List <Object > paramsList = new ArrayList <>();
400
+ paramsList .addAll (Arrays .asList (new Object [] { databaseName , userID , password , objectName , commandName }));
401
+ if (parameters != null && parameters .length > 0 ) {
402
+ paramsList .add (Arrays .asList (parameters ));
403
+ }
404
+
405
+ Map <String , Context > c = new HashMap <>();
406
+ c .put ("context" ,context );
407
+ paramsList .add (c );
408
+ return objectClient .execute ("execute_kw" , paramsList );
409
+
410
+ }
411
+
393
412
/**
394
413
* Executes any command on the server linked to the /xmlrpc/object service.
395
414
* parameters and Context are prepended .The context MUST NOT have been already
@@ -406,13 +425,18 @@ public Object executeCommandWithContext(final String objectName, final String co
406
425
final Object [] parameters ) throws XmlRpcException {
407
426
Object [] connectionParams = new Object [] { databaseName , userID , password , objectName , commandName };
408
427
409
- // Combine the parameters with the context
410
- Object [] params = new Object [1 + (parameters == null ? 0 : parameters .length )];
411
- if (parameters != null && parameters .length > 0 ) {
412
- System .arraycopy (parameters , 0 , params , 0 , parameters .length );
428
+ if (this .getServerVersion ().getMajor () < 13 ){
429
+ // Combine the parameters with the context
430
+ Object [] params = new Object [1 + (parameters == null ? 0 : parameters .length )];
431
+ if (parameters != null && parameters .length > 0 ) {
432
+ System .arraycopy (parameters , 0 , params , 0 , parameters .length );
433
+ }
434
+ System .arraycopy (new Object [] { getContext () }, 0 , params , parameters .length , 1 );
435
+ return executeCommand (objectName , commandName , params );
436
+ }else {
437
+ return executeCommandKw (objectName , commandName , parameters ,getContext ());
413
438
}
414
- System .arraycopy (new Object [] { getContext () }, 0 , params , parameters .length , 1 );
415
- return executeCommand (objectName , commandName , params );
439
+
416
440
}
417
441
418
442
/**
0 commit comments