Merge pull request #18320 from lainwir3d/restapi_shipment_close
CLOSE #18319 REST API - Shipment: Add 'close' action / endpoint
This commit is contained in:
commit
f412af5885
@ -530,14 +530,9 @@ class Shipments extends DolibarrApi
|
||||
if ($result < 0) {
|
||||
throw new RestException(500, 'Error when validating Shipment: '.$this->shipment->error);
|
||||
}
|
||||
|
||||
// Reload shipment
|
||||
$result = $this->shipment->fetch($id);
|
||||
if (!$result) {
|
||||
throw new RestException(404, 'Shipment not found');
|
||||
}
|
||||
|
||||
if (!DolibarrApi::_checkAccessToResource('expedition', $this->shipment->id)) {
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
|
||||
$this->shipment->fetchObjectLinked();
|
||||
return $this->_cleanObjectDatas($this->shipment);
|
||||
@ -626,6 +621,47 @@ class Shipments extends DolibarrApi
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Close a shipment (Classify it as "Delivered")
|
||||
*
|
||||
* @param int $id Expedition ID
|
||||
* @param int $notrigger Disabled triggers
|
||||
*
|
||||
* @url POST {id}/close
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function close($id, $notrigger = 0)
|
||||
{
|
||||
if (!DolibarrApiAccess::$user->rights->expedition->creer) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
|
||||
$result = $this->shipment->fetch($id);
|
||||
if (!$result) {
|
||||
throw new RestException(404, 'Shipment not found');
|
||||
}
|
||||
|
||||
if (!DolibarrApi::_checkAccessToResource('expedition', $this->commande->id)) {
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
|
||||
$result = $this->shipment->setClosed();
|
||||
if ($result == 0) {
|
||||
throw new RestException(304, 'Error nothing done. May be object is already closed');
|
||||
}
|
||||
if ($result < 0) {
|
||||
throw new RestException(500, 'Error when closing Order: '.$this->commande->error);
|
||||
}
|
||||
|
||||
// Reload shipment
|
||||
$result = $this->shipment->fetch($id);
|
||||
|
||||
$this->shipment->fetchObjectLinked();
|
||||
|
||||
return $this->_cleanObjectDatas($this->shipment);
|
||||
}
|
||||
|
||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
|
||||
/**
|
||||
* Clean sensible object datas
|
||||
|
||||
Loading…
Reference in New Issue
Block a user