@@ -66,6 +66,10 @@ class OdooClient
66
66
// (6, _, ids)
67
67
const RELATION_REPLACE_ALL_LINKS = 6 ;
68
68
69
+ const API_TYPE_COMMON = 'common ' ;
70
+ const API_TYPE_OBJECT = 'object ' ;
71
+ const API_TYPE_DB = 'db ' ;
72
+
69
73
/**
70
74
* Later versions of the API include a version number e.g. /xmlrpc/2/
71
75
*/
@@ -162,7 +166,7 @@ public function getUserId()
162
166
163
167
// Fetch the user ID from the server.
164
168
165
- $ xmlRpcClient = $ this ->getXmlRpcClient (' common ' );
169
+ $ xmlRpcClient = $ this ->getXmlRpcClient (static :: API_TYPE_COMMON );
166
170
167
171
// Build login parameters array.
168
172
@@ -278,7 +282,7 @@ public function search(
278
282
$ msg ->addParam ($ this ->intValue ($ limit ));
279
283
$ msg ->addParam ($ this ->stringValue ($ order ));
280
284
281
- $ this ->response = $ this ->getXmlRpcClient (' object ' )->send ($ msg );
285
+ $ this ->response = $ this ->getXmlRpcClient (static :: API_TYPE_OBJECT )->send ($ msg );
282
286
283
287
return collect ($ this ->responseAsNative ());
284
288
}
@@ -297,7 +301,7 @@ public function searchCount(
297
301
298
302
$ msg ->addParam ($ this ->nativeToValue ($ criteria ));
299
303
300
- $ this ->response = $ this ->getXmlRpcClient (' object ' )->send ($ msg );
304
+ $ this ->response = $ this ->getXmlRpcClient (static :: API_TYPE_OBJECT )->send ($ msg );
301
305
302
306
return $ this ->valueToNative ();
303
307
}
@@ -314,7 +318,7 @@ public function searchRead(
314
318
$ order = ''
315
319
) {
316
320
if (version_compare ('8.0 ' , $ this ->serverVersion ) === 1 ) {
317
- // Less than Odoo 8.0, so search_read is not supported.
321
+ // For less than Odoo 8.0, search_read is not supported.
318
322
// However, we will emulate it.
319
323
320
324
$ ids = $ this ->search (
@@ -335,38 +339,20 @@ public function searchRead(
335
339
$ msg ->addParam ($ this ->intValue ($ limit ));
336
340
$ msg ->addParam ($ this ->stringValue ($ order ));
337
341
338
- $ this ->response = $ this ->getXmlRpcClient ('object ' )->send ($ msg );
339
- }
342
+ $ this ->response = $ this ->getXmlRpcClient (static ::API_TYPE_OBJECT )->send ($ msg );
340
343
341
- return $ this -> response ;
342
- }
344
+ // FIXME: these need to be mapped onto models instead of
345
+ // being returned as native arrays.
343
346
344
- /**
345
- * Same as searchRead but returning a native PHP array.
346
- */
347
- public function searchReadArray (
348
- string $ modelName ,
349
- array $ criteria = [],
350
- $ offset = 0 ,
351
- $ limit = self ::DEFAULT_LIMIT ,
352
- $ order = ''
353
- ) {
354
- $ this ->response = $ this ->searchRead (
355
- $ modelName ,
356
- $ criteria ,
357
- $ offset ,
358
- $ limit ,
359
- $ order
360
- );
361
-
362
- return $ this ->responseAsNative ();
347
+ return $ this ->responseAsNative ();
348
+ }
363
349
}
364
350
365
351
/**
366
352
* @param string $modelName example res.partner
367
353
* @param array $instanceIds list of model instance IDs to read and return
368
354
* @param array $options varies with API versions see documentation
369
- * @return Response
355
+ * @return Collection of ModelInterface
370
356
*/
371
357
public function read (
372
358
string $ modelName ,
@@ -381,7 +367,7 @@ public function read(
381
367
$ msg ->addParam ($ this ->nativeToValue ($ options ));
382
368
}
383
369
384
- $ this ->response = $ this ->getXmlRpcClient (' object ' )->send ($ msg );
370
+ $ this ->response = $ this ->getXmlRpcClient (static :: API_TYPE_OBJECT )->send ($ msg );
385
371
386
372
$ data = $ this ->responseAsNative ();
387
373
@@ -401,7 +387,7 @@ public function version()
401
387
{
402
388
$ msg = new Request ('version ' );
403
389
404
- $ this ->response = $ this ->getXmlRpcClient (' common ' )->send ($ msg );
390
+ $ this ->response = $ this ->getXmlRpcClient (static :: API_TYPE_COMMON )->send ($ msg );
405
391
406
392
return $ this ->responseAsNative ();
407
393
}
@@ -417,7 +403,7 @@ public function create(string $modelName, array $fields)
417
403
418
404
$ msg ->addParam ($ this ->nativeToValue ($ fields ));
419
405
420
- $ this ->response = $ this ->getXmlRpcClient (' object ' )->send ($ msg );
406
+ $ this ->response = $ this ->getXmlRpcClient (static :: API_TYPE_OBJECT )->send ($ msg );
421
407
422
408
return $ this ->responseAsNative ();
423
409
}
@@ -434,7 +420,7 @@ public function write(string $modelName, int $resourceId, array $fields)
434
420
$ msg ->addParam ($ this ->nativeToValue ([$ resourceId ]));
435
421
$ msg ->addParam ($ this ->nativeToValue ($ fields ));
436
422
437
- $ this ->response = $ this ->getXmlRpcClient (' object ' )->send ($ msg );
423
+ $ this ->response = $ this ->getXmlRpcClient (static :: API_TYPE_OBJECT )->send ($ msg );
438
424
439
425
return $ this ->responseAsNative ();
440
426
}
@@ -450,7 +436,7 @@ public function unlink(string $modelName, int $resourceId)
450
436
451
437
$ msg ->addParam ($ this ->nativeToValue ([$ resourceId ]));
452
438
453
- $ this ->response = $ this ->getXmlRpcClient (' object ' )->send ($ msg );
439
+ $ this ->response = $ this ->getXmlRpcClient (static :: API_TYPE_OBJECT )->send ($ msg );
454
440
455
441
return $ this ->responseAsNative ();
456
442
}
@@ -465,7 +451,7 @@ public function fieldsGet(string $modelName)
465
451
{
466
452
$ msg = $ this ->getBaseObjectRequest ($ modelName , 'fields_get ' );
467
453
468
- $ this ->response = $ this ->getXmlRpcClient (' object ' )->send ($ msg );
454
+ $ this ->response = $ this ->getXmlRpcClient (static :: API_TYPE_OBJECT )->send ($ msg );
469
455
470
456
return $ this ->responseAsNative ();
471
457
}
@@ -625,7 +611,7 @@ public function load(string $modelName, iterable $records)
625
611
$ msg ->addParam ($ this ->nativeToValue ($ group ['keys ' ]));
626
612
$ msg ->addParam ($ this ->nativeToValue ($ group ['records ' ]));
627
613
628
- $ this ->response = $ this ->getXmlRpcClient (' object ' )->send ($ msg );
614
+ $ this ->response = $ this ->getXmlRpcClient (static :: API_TYPE_OBJECT )->send ($ msg );
629
615
630
616
$ groupResult = $ this ->responseAsNative ();
631
617
0 commit comments