Fix error management in API
This commit is contained in:
parent
a1b03e094c
commit
45f322cce8
@ -156,6 +156,12 @@ class StockMovements extends DolibarrApi
|
||||
|
||||
/**
|
||||
* Create stock movement object.
|
||||
* You can use the following message to test this RES API:
|
||||
* { "product_id": 1, "warehouse_id": 1, "qty": 1, "lot": "", "movementcode": "INV123", "movementlabel": "Inventory 123", "price": 0 }
|
||||
* $price Can be set to update AWP (Average Weighted Price) when you make a stock increase
|
||||
* $dlc Eat-by date. Will be used if lot does not exists yet and will be created.
|
||||
* $dluo Sell-by date. Will be used if lot does not exists yet and will be created.
|
||||
*
|
||||
* @param int $product_id Id product id {@min 1} {@from body} {@required true}
|
||||
* @param int $warehouse_id Id warehouse {@min 1} {@from body} {@required true}
|
||||
* @param float $qty Qty to add (Use negative value for a stock decrease) {@min 0} {@message qty must be higher than 0} {@from body} {@required true}
|
||||
@ -163,8 +169,8 @@ class StockMovements extends DolibarrApi
|
||||
* @param string $movementcode Movement code {@example INV123} {@from body}
|
||||
* @param string $movementlabel Movement label {@example Inventory number 123} {@from body}
|
||||
* @param string $price To update AWP (Average Weighted Price) when you make a stock increase (qty must be higher then 0). {@from body}
|
||||
* @param string $dlc {@from body} {@type date}
|
||||
* @param string $dluo {@from body} {@type date}
|
||||
* @param string $dlc Eat-by date. {@from body} {@type date}
|
||||
* @param string $dluo Sell-by date. {@from body} {@type date}
|
||||
*
|
||||
* @return int ID of stock movement
|
||||
* @throws RestException
|
||||
@ -175,6 +181,10 @@ class StockMovements extends DolibarrApi
|
||||
throw new RestException(401);
|
||||
}
|
||||
|
||||
if ($qty == 0) {
|
||||
throw new RestException(503, "Making a stock movement with a quentity of 0 is not possible");
|
||||
}
|
||||
|
||||
// Type increase or decrease
|
||||
if ($qty >= 0) $type = 3;
|
||||
else $type = 2;
|
||||
|
||||
@ -157,6 +157,8 @@ class MouvementStock extends CommonObject
|
||||
$result=$product->fetch($fk_product);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error = $product->error;
|
||||
$this->errors = $product->errors;
|
||||
dol_print_error('', "Failed to fetch product");
|
||||
return -1;
|
||||
}
|
||||
@ -352,7 +354,7 @@ class MouvementStock extends CommonObject
|
||||
if(!empty($this->origin)) { // This is set by caller for tracking reason
|
||||
$origintype = $this->origin->element;
|
||||
$fk_origin = $this->origin->id;
|
||||
if($origintype == 'project') $fk_project = $fk_origin;
|
||||
if ($origintype == 'project') $fk_project = $fk_origin;
|
||||
else
|
||||
{
|
||||
$res = $this->origin->fetch($fk_origin);
|
||||
@ -398,7 +400,8 @@ class MouvementStock extends CommonObject
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errors[]=$this->db->lasterror();
|
||||
$this->error = $this->db->lasterror();
|
||||
$this->errors[] = $this->error;
|
||||
$error = -1;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user