New : rest api POST orders shipment
This commit is contained in:
parent
f482be84bf
commit
c70813d718
@ -966,6 +966,7 @@ class Orders extends DolibarrApi
|
|||||||
|
|
||||||
return $this->_cleanObjectDatas($this->commande);
|
return $this->_cleanObjectDatas($this->commande);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the shipments of an order
|
* Get the shipments of an order
|
||||||
*
|
*
|
||||||
@ -1016,6 +1017,47 @@ class Orders extends DolibarrApi
|
|||||||
return $obj_ret;
|
return $obj_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the shipments of an order
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param int $id Id of the order
|
||||||
|
* @param int $warehouse_id Id of a warehouse
|
||||||
|
*
|
||||||
|
* @url POST {id}/shipment/{warehouse_id}
|
||||||
|
*
|
||||||
|
* @throws RestException 401
|
||||||
|
* @throws RestException 404
|
||||||
|
* @throws RestException 500
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function createOrderShipement($id, $warehouse_id)
|
||||||
|
{
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
|
||||||
|
if (!DolibarrApiAccess::$user->rights->expedition->creer) {
|
||||||
|
throw new RestException(401);
|
||||||
|
}
|
||||||
|
$result = $this->commande->fetch($id);
|
||||||
|
if (!$result) {
|
||||||
|
throw new RestException(404, 'Order not found');
|
||||||
|
}
|
||||||
|
$shipment = new Expedition($this->db);
|
||||||
|
$shipment->socid = $this->commande->socid;
|
||||||
|
$result = $shipment->create(DolibarrApiAccess::$user);
|
||||||
|
if ($result <= 0) {
|
||||||
|
throw new RestException(500, 'Error on creating expedition :'.$this->db->lasterror());
|
||||||
|
}
|
||||||
|
foreach ($this->commande->lines as $line) {
|
||||||
|
$result = $shipment->create_line($warehouse_id, $line->id, $line->qty);
|
||||||
|
if ($result <= 0) {
|
||||||
|
throw new RestException(500, 'Error on creating expedition lines:'.$this->db->lasterror());
|
||||||
|
}
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
return $shipment->id;
|
||||||
|
}
|
||||||
|
|
||||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
|
||||||
/**
|
/**
|
||||||
* Clean sensible object datas
|
* Clean sensible object datas
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user