From 67cab8c1f2538ef7cc6af384dbedb374cbfb64d5 Mon Sep 17 00:00:00 2001 From: r3dge Date: Fri, 21 May 2021 16:01:04 +0200 Subject: [PATCH 1/4] bug fix : replacing orders by donations and setting required field to allow post action in rest API for url donations. See issue #17700 --- htdocs/don/class/api_donations.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/don/class/api_donations.class.php b/htdocs/don/class/api_donations.class.php index 18a8563fd89..5f70ee82a2e 100644 --- a/htdocs/don/class/api_donations.class.php +++ b/htdocs/don/class/api_donations.class.php @@ -33,7 +33,7 @@ class Donations extends DolibarrApi * @var array $FIELDS Mandatory fields, checked when create and update object */ static $FIELDS = array( - 'socid' + 'amount' ); /** @@ -193,7 +193,7 @@ class Donations extends DolibarrApi }*/ if ($this->don->create(DolibarrApiAccess::$user) < 0) { - throw new RestException(500, "Error creating order", array_merge(array($this->don->error), $this->don->errors)); + throw new RestException(500, "Error creating donation", array_merge(array($this->don->error), $this->don->errors)); } return $this->don->id; @@ -355,7 +355,7 @@ class Donations extends DolibarrApi private function _validate($data) { $don = array(); - foreach (Orders::$FIELDS as $field) { + foreach (Donations::$FIELDS as $field) { if (!isset($data[$field])) throw new RestException(400, $field." field missing"); $don[$field] = $data[$field]; From f81136231a2250e1f4767f1c0285848b8cbc73bf Mon Sep 17 00:00:00 2001 From: r3dge Date: Sun, 23 May 2021 18:09:10 +0200 Subject: [PATCH 2/4] fixing PUT request for donation update --- htdocs/don/class/api_donations.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/don/class/api_donations.class.php b/htdocs/don/class/api_donations.class.php index 5f70ee82a2e..1a17f6ff94c 100644 --- a/htdocs/don/class/api_donations.class.php +++ b/htdocs/don/class/api_donations.class.php @@ -302,7 +302,7 @@ class Donations extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - $result = $this->don->valid(DolibarrApiAccess::$user, $idwarehouse, $notrigger); + $result = $this->don->valid_promesse($id, DolibarrApiAccess::$user->id, $notrigger); if ($result == 0) { throw new RestException(304, 'Error nothing done. May be object is already validated'); } From 647997af2815c04111ea4e1831230e28f7a34364 Mon Sep 17 00:00:00 2001 From: r3dge Date: Sun, 23 May 2021 18:15:00 +0200 Subject: [PATCH 3/4] fixing error on date --- htdocs/don/class/don.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/don/class/don.class.php b/htdocs/don/class/don.class.php index 0717870ac42..9396f3a718a 100644 --- a/htdocs/don/class/don.class.php +++ b/htdocs/don/class/don.class.php @@ -390,7 +390,7 @@ class Don extends CommonObject $sql .= ", phone"; $sql .= ", phone_mobile"; $sql .= ") VALUES ("; - $sql .= "'".$this->db->idate($now)."'"; + $sql .= "'".$this->db->idate($this->date)."'"; $sql .= ", ".$conf->entity; $sql .= ", ".price2num($this->amount); $sql .= ", ".($this->modepaymentid ? $this->modepaymentid : "null"); From 0d31db0ba5bb88d6d47f6e4c5719f4a06414b02f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 25 May 2021 20:11:46 +0200 Subject: [PATCH 4/4] Update don.class.php --- htdocs/don/class/don.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/don/class/don.class.php b/htdocs/don/class/don.class.php index 9396f3a718a..3e0e300930d 100644 --- a/htdocs/don/class/don.class.php +++ b/htdocs/don/class/don.class.php @@ -390,7 +390,7 @@ class Don extends CommonObject $sql .= ", phone"; $sql .= ", phone_mobile"; $sql .= ") VALUES ("; - $sql .= "'".$this->db->idate($this->date)."'"; + $sql .= "'".$this->db->idate($this->date ? $this->date : $now)."'"; $sql .= ", ".$conf->entity; $sql .= ", ".price2num($this->amount); $sql .= ", ".($this->modepaymentid ? $this->modepaymentid : "null");