Merge pull request #7804 from Oeris/develop-api

NEW Update in the order REST API
This commit is contained in:
Laurent Destailleur 2017-11-14 01:24:18 +01:00 committed by GitHub
commit 765a2097bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 79 additions and 11 deletions

View File

@ -119,6 +119,20 @@ class Documents extends DolibarrApi
throw new RestException(500, 'Error generating document');
}
}
if ($module_part == 'commande' || $module_part == 'order')
{
require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
$this->order = new Commande($this->db);
$result = $this->order->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
if( ! $result ) {
throw new RestException(404, 'Order not found');
}
$result = $this->order->generateDocument($this->order->modelpdf, $langs, $hidedetails, $hidedesc, $hideref);
if( $result <= 0 ) {
throw new RestException(500, 'Error generating document');
}
}
}
$filename = basename($original_file);

View File

@ -396,16 +396,16 @@ class Orders extends DolibarrApi
* @return int
*/
function put($id, $request_data = NULL) {
if(! DolibarrApiAccess::$user->rights->commande->creer) {
if (! DolibarrApiAccess::$user->rights->commande->creer) {
throw new RestException(401);
}
$result = $this->commande->fetch($id);
if( ! $result ) {
if (! $result) {
throw new RestException(404, 'Order not found');
}
if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
if (! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
foreach($request_data as $field => $value) {
@ -413,7 +413,13 @@ class Orders extends DolibarrApi
$this->commande->$field = $value;
}
if($this->commande->update($id, DolibarrApiAccess::$user, 1, '', '', 'update'))
// Update availability
if (!empty($this->commande->availability_id)) {
if ($this->commande->availability($this->commande->availability_id) < 0)
throw new RestException(400, 'Error while updating availability');
}
if ($this->commande->update($id, DolibarrApiAccess::$user, 1, '', '', 'update'))
return $this->get($id);
return false;
@ -487,18 +493,22 @@ class Orders extends DolibarrApi
$result = $this->commande->valid(DolibarrApiAccess::$user, $idwarehouse, $notrigger);
if ($result == 0) {
throw new RestException(500, 'Error nothing done. May be object is already validated');
throw new RestException(304, 'Error nothing done. May be object is already validated');
}
if ($result < 0) {
throw new RestException(500, 'Error when validating Order: '.$this->commande->error);
}
$result = $this->commande->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Order not found');
}
return array(
'success' => array(
'code' => 200,
'message' => 'Order validated (Ref='.$this->commande->ref.')'
)
);
if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$this->commande->fetchObjectLinked();
return $this->_cleanObjectDatas($this->commande);
}
/**
@ -541,6 +551,50 @@ class Orders extends DolibarrApi
);
}
/**
* Set an order to draft
*
* @param int $id Order ID
*
* @url POST {id}/settodraft
*
* @return array
*/
function settodraft($id)
{
if(! DolibarrApiAccess::$user->rights->commande->creer) {
throw new RestException(401);
}
$result = $this->commande->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Order not found');
}
if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$result = $this->commande->set_draft(DolibarrApiAccess::$user);
if ($result == 0) {
throw new RestException(304, 'Nothing done. May be object is already closed');
}
if ($result < 0) {
throw new RestException(500, 'Error when closing Order: '.$this->commande->error);
}
$result = $this->commande->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Order not found');
}
if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$this->commande->fetchObjectLinked();
return $this->_cleanObjectDatas($this->commande);
}
/**
* Clean sensible object datas