Add API close to close an order

This commit is contained in:
Laurent Destailleur 2017-10-18 15:34:03 +02:00
parent 8e4cb2ea79
commit 99239cbb38
6 changed files with 76 additions and 6 deletions

View File

@ -134,8 +134,11 @@ class DolibarrApi
unset($object->fk_element); unset($object->fk_element);
unset($object->table_element); unset($object->table_element);
unset($object->table_element_line); unset($object->table_element_line);
unset($object->class_element_line);
unset($object->picto); unset($object->picto);
unset($object->facturee); // Replace with billed
unset($object->skip_update_total); unset($object->skip_update_total);
unset($object->context); unset($object->context);

View File

@ -387,7 +387,7 @@ class Orders extends DolibarrApi
/** /**
* Update order general fields (won't touch lines of order) * Update order general fields (won't touch lines of order)
* *
* @param int $id Id of commande to update * @param int $id Id of order to update
* @param array $request_data Datas * @param array $request_data Datas
* *
* @return int * @return int
@ -498,6 +498,53 @@ class Orders extends DolibarrApi
); );
} }
/**
* Close an order (Classify it as "Delivered")
*
* @param int $id Order ID
* @param int $notrigger Disabled triggers
*
* @url POST {id}/close
*
* @return array
* FIXME An error 403 is returned if the request has an empty body.
* Error message: "Forbidden: Content type `text/plain` is not supported."
* Workaround: send this in the body
* {
* "notrigger": 0
* }
*/
function close($id, $notrigger=0)
{
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->cloture(DolibarrApiAccess::$user, $notrigger);
if ($result == 0) {
throw new RestException(500, 'Error nothing done. May be object is already closed');
}
if ($result < 0) {
throw new RestException(500, 'Error when closing Order: '.$this->commande->error);
}
return array(
'success' => array(
'code' => 200,
'message' => 'Order closed (Ref='.$this->commande->ref.')'
)
);
}
/** /**
* Clean sensible object datas * Clean sensible object datas
* *
@ -509,6 +556,10 @@ class Orders extends DolibarrApi
$object = parent::_cleanObjectDatas($object); $object = parent::_cleanObjectDatas($object);
unset($object->address); unset($object->address);
unset($object->barcode_type);
unset($object->barcode_type_code);
unset($object->barcode_type_label);
unset($object->barcode_type_coder);
return $object; return $object;
} }

View File

@ -557,9 +557,10 @@ class Commande extends CommonOrder
* Close order * Close order
* *
* @param User $user Objet user that close * @param User $user Objet user that close
* @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function cloture($user) function cloture($user, $notrigger=0)
{ {
global $conf; global $conf;
@ -580,10 +581,13 @@ class Commande extends CommonOrder
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
// Call trigger if (! $notrigger)
$result=$this->call_trigger('ORDER_CLOSE',$user); {
if ($result < 0) $error++; // Call trigger
// End call triggers $result=$this->call_trigger('ORDER_CLOSE',$user);
if ($result < 0) $error++;
// End call triggers
}
if (! $error) if (! $error)
{ {

View File

@ -600,6 +600,10 @@ class Invoices extends DolibarrApi
$object = parent::_cleanObjectDatas($object); $object = parent::_cleanObjectDatas($object);
unset($object->address); unset($object->address);
unset($object->barcode_type);
unset($object->barcode_type_code);
unset($object->barcode_type_label);
unset($object->barcode_type_coder);
return $object; return $object;
} }

View File

@ -336,6 +336,10 @@ class SupplierInvoices extends DolibarrApi
$object = parent::_cleanObjectDatas($object); $object = parent::_cleanObjectDatas($object);
unset($object->rowid); unset($object->rowid);
unset($object->barcode_type);
unset($object->barcode_type_code);
unset($object->barcode_type_label);
unset($object->barcode_type_coder);
return $object; return $object;
} }

View File

@ -340,6 +340,10 @@ class SupplierOrders extends DolibarrApi
$object = parent::_cleanObjectDatas($object); $object = parent::_cleanObjectDatas($object);
unset($object->rowid); unset($object->rowid);
unset($object->barcode_type);
unset($object->barcode_type_code);
unset($object->barcode_type_label);
unset($object->barcode_type_coder);
return $object; return $object;
} }