Ver código fonte

Merge branch 'hotfix/new_dolibarr_api'

Olivier Massot 1 ano atrás
pai
commit
c14018c9b8

+ 11 - 5
src/Service/Dolibarr/DolibarrApiService.php

@@ -34,7 +34,13 @@ class DolibarrApiService extends ApiRequestService
         // impossible to retrieve a society by its extrafield 2iopen_organization_id (thanks dolibarr), so
         // we need to store the organization id in two fields: 2iopen_organization_id and ref_int :(
         try {
-            return $this->getJsonContent("thirdparties" , [ "limit" => "1", "sqlfilters" => "ref_int=" . $organizationId])[0];
+            return $this->getJsonContent(
+                "thirdparties" ,
+                [
+                    "limit" => "1",
+                    "sqlfilters" => "(ef.2iopen_organization_id:=:" . $organizationId . ")"
+                ]
+            )[0];
         } catch (HttpException $e) {
             if ($e->getStatusCode() === 404) {
                 // /!\ The dolibarr API will return a 404 error if no results are found...
@@ -55,7 +61,7 @@ class DolibarrApiService extends ApiRequestService
         try {
             return $this->getJsonContent(
                 "contracts",
-                ["limit" => "1", "sqlfilters" => "statut=1", "thirdparty_ids" => $socId]
+                ["limit" => "1", "sqlfilters" => "statut:=:1", "thirdparty_ids" => $socId]
             )[0];
         } catch (HttpException $e) {
             if ($e->getStatusCode() === 404) {
@@ -77,7 +83,7 @@ class DolibarrApiService extends ApiRequestService
         try {
             return $this->getJsonContent(
                 "invoices",
-                ["sortfield" => "datef", "sortorder" => "DESC", "limit" => 5, "sqlfilters" => "fk_soc=" . $socId]);
+                ["sortfield" => "datef", "sortorder" => "DESC", "limit" => 5, "sqlfilters" => "fk_soc:=:" . $socId]);
         } catch (HttpException $e) {
             if ($e->getStatusCode() === 404) {
                 // /!\ The dolibarr API will return a 404 error if no results are found...
@@ -97,7 +103,7 @@ class DolibarrApiService extends ApiRequestService
     {
         return $this->getJsonContent(
             "thirdparties",
-            ["limit" => "1000000", "sqlfilters" => "client=1"]
+            ["limit" => "1000000", "sqlfilters" => "client:=:1"]
         );
     }
 
@@ -135,7 +141,7 @@ class DolibarrApiService extends ApiRequestService
         // et dolibarr est pas content :(
         try {
             return $this->getJsonContent(
-                "contacts?limit=1000&t.statut=1&thirdparty_ids=" . $socId . "&sqlfilters=(te.2iopen_person_id%3A%3E%3A0)"
+                "contacts?limit=1000&t.statut=1&thirdparty_ids=" . $socId . "&sqlfilters:=:(te.2iopen_person_id%3A%3E%3A0)"
             );
         } catch (HttpException $e) {
             if ($e->getStatusCode() === 404) {

+ 11 - 11
tests/Unit/Service/Dolibarr/DolibarrApiServiceTest.php

@@ -32,7 +32,7 @@ class DolibarrApiServiceTest extends TestCase
         $dolibarrApiService
             ->expects(self::once())
             ->method('getJsonContent')
-            ->with("thirdparties", [ "limit" => "1", "sqlfilters" => "ref_int=" . $organizationId])
+            ->with("thirdparties", [ "limit" => "1", "sqlfilters" => "(ef.2iopen_organization_id:=:" . $organizationId . ')'])
             ->willReturn([['id' => 1]]); // dummy non-empty data
 
         $society = $dolibarrApiService->getSociety($organizationId);
@@ -54,7 +54,7 @@ class DolibarrApiServiceTest extends TestCase
         $dolibarrApiService
             ->expects(self::once())
             ->method('getJsonContent')
-            ->with("contracts", ["limit" => "1", "sqlfilters" => "statut=1", "thirdparty_ids" => $socId])
+            ->with("contracts", ["limit" => "1", "sqlfilters" => "statut:=:1", "thirdparty_ids" => $socId])
             ->willReturn([['id' => 1]]); // dummy non-empty data
 
         $this->assertEquals(['id' => 1], $dolibarrApiService->getActiveContract($socId));
@@ -74,7 +74,7 @@ class DolibarrApiServiceTest extends TestCase
         $dolibarrApiService
             ->expects(self::once())
             ->method('getJsonContent')
-            ->with("contracts", ["limit" => "1", "sqlfilters" => "statut=1", "thirdparty_ids" => $socId])
+            ->with("contracts", ["limit" => "1", "sqlfilters" => "statut:=:1", "thirdparty_ids" => $socId])
             ->willThrowException(new HttpException(404));
 
         $this->assertEquals(null, $dolibarrApiService->getActiveContract($socId));
@@ -94,7 +94,7 @@ class DolibarrApiServiceTest extends TestCase
         $dolibarrApiService
             ->expects(self::once())
             ->method('getJsonContent')
-            ->with("contracts", ["limit" => "1", "sqlfilters" => "statut=1", "thirdparty_ids" => $socId])
+            ->with("contracts", ["limit" => "1", "sqlfilters" => "statut:=:1", "thirdparty_ids" => $socId])
             ->willThrowException(new HttpException(500));
 
         $this->expectException(HttpException::class);
@@ -116,7 +116,7 @@ class DolibarrApiServiceTest extends TestCase
         $dolibarrApiService
             ->expects(self::once())
             ->method('getJsonContent')
-            ->with("invoices", ["sortfield" => "datef", "sortorder" => "DESC", "limit" => 5, "sqlfilters" => "fk_soc=" . $socId])
+            ->with("invoices", ["sortfield" => "datef", "sortorder" => "DESC", "limit" => 5, "sqlfilters" => "fk_soc:=:" . $socId])
             ->willReturn([['id' => 10], ['id' => 20]]);
 
         $this->assertEquals([['id' => 10], ['id' => 20]], $dolibarrApiService->getBills($socId));
@@ -136,7 +136,7 @@ class DolibarrApiServiceTest extends TestCase
         $dolibarrApiService
             ->expects(self::once())
             ->method('getJsonContent')
-            ->with("invoices", ["sortfield" => "datef", "sortorder" => "DESC", "limit" => 5, "sqlfilters" => "fk_soc=" . $socId])
+            ->with("invoices", ["sortfield" => "datef", "sortorder" => "DESC", "limit" => 5, "sqlfilters" => "fk_soc:=:" . $socId])
             ->willThrowException(new HttpException(404));
 
         $this->assertEquals([], $dolibarrApiService->getBills($socId));
@@ -156,7 +156,7 @@ class DolibarrApiServiceTest extends TestCase
         $dolibarrApiService
             ->expects(self::once())
             ->method('getJsonContent')
-            ->with("invoices", ["sortfield" => "datef", "sortorder" => "DESC", "limit" => 5, "sqlfilters" => "fk_soc=" . $socId])
+            ->with("invoices", ["sortfield" => "datef", "sortorder" => "DESC", "limit" => 5, "sqlfilters" => "fk_soc:=:" . $socId])
             ->willThrowException(new HttpException(500));
 
         $this->expectException(HttpException::class);
@@ -177,7 +177,7 @@ class DolibarrApiServiceTest extends TestCase
         $dolibarrApiService
             ->expects(self::once())
             ->method('getJsonContent')
-            ->with("thirdparties", ["limit" => "1000000", "sqlfilters" => "client=1"])
+            ->with("thirdparties", ["limit" => "1000000", "sqlfilters" => "client:=:1"])
             ->willReturn([['id' => 10], ['id' => 20]]);
 
         $this->assertEquals([['id' => 10], ['id' => 20]], $dolibarrApiService->getAllClients());
@@ -262,7 +262,7 @@ class DolibarrApiServiceTest extends TestCase
         $dolibarrApiService
             ->expects(self::once())
             ->method('getJsonContent')
-            ->with("contacts?limit=1000&t.statut=1&thirdparty_ids=" . $socId . "&sqlfilters=(te.2iopen_person_id%3A%3E%3A0)")
+            ->with("contacts?limit=1000&t.statut=1&thirdparty_ids=" . $socId . "&sqlfilters:=:(te.2iopen_person_id%3A%3E%3A0)")
             ->willReturn([['id' => 10], ['id' => 20]]);
 
         $this->assertEquals([['id' => 10], ['id' => 20]], $dolibarrApiService->getActiveOpentalentContacts($socId));
@@ -282,7 +282,7 @@ class DolibarrApiServiceTest extends TestCase
         $dolibarrApiService
             ->expects(self::once())
             ->method('getJsonContent')
-            ->with("contacts?limit=1000&t.statut=1&thirdparty_ids=" . $socId . "&sqlfilters=(te.2iopen_person_id%3A%3E%3A0)")
+            ->with("contacts?limit=1000&t.statut=1&thirdparty_ids=" . $socId . "&sqlfilters:=:(te.2iopen_person_id%3A%3E%3A0)")
             ->willThrowException(new HttpException(404));
 
         $this->assertEquals([], $dolibarrApiService->getActiveOpentalentContacts($socId));
@@ -302,7 +302,7 @@ class DolibarrApiServiceTest extends TestCase
         $dolibarrApiService
             ->expects(self::once())
             ->method('getJsonContent')
-            ->with("contacts?limit=1000&t.statut=1&thirdparty_ids=" . $socId . "&sqlfilters=(te.2iopen_person_id%3A%3E%3A0)")
+            ->with("contacts?limit=1000&t.statut=1&thirdparty_ids=" . $socId . "&sqlfilters:=:(te.2iopen_person_id%3A%3E%3A0)")
             ->willThrowException(new HttpException(500));
 
         $this->expectException(HttpException::class);