From 5687d26f955156a0d54586ca9d169c0725120f73 Mon Sep 17 00:00:00 2001 From: Laurent De Coninck Date: Fri, 17 Jan 2020 17:21:14 +0100 Subject: [PATCH 1/2] fixes the creation of a stock movement This fixes the creation of a stock movement by supporting the DLC and DLUO. [see: #12883] --- htdocs/product/stock/class/api_stockmovements.class.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/product/stock/class/api_stockmovements.class.php b/htdocs/product/stock/class/api_stockmovements.class.php index cfa901bce30..c199bfdf676 100644 --- a/htdocs/product/stock/class/api_stockmovements.class.php +++ b/htdocs/product/stock/class/api_stockmovements.class.php @@ -192,13 +192,15 @@ class StockMovements extends DolibarrApi if ($field == 'movementcode') $movementcode = $value; if ($field == 'movementlabel') $movementlabel = $value; if ($field == 'price') $price = $value; + if ($field == 'dlc') $dlc = $value; + if ($field == 'dluo') $dluo = $value; } // Type increase or decrease if ($qty >= 0) $type = 3; else $type = 2; - if($this->stockmovement->_create(DolibarrApiAccess::$user, $product_id, $warehouse_id, $qty, $type, $price, $movementlabel, $movementcode, '', '', '', $lot) <= 0) { + if($this->stockmovement->_create(DolibarrApiAccess::$user, $product_id, $warehouse_id, $qty, $type, $price, $movementlabel, $movementcode, '', $dlc, $dluo, $lot) <= 0) { throw new RestException(503, 'Error when create stock movement : '.$this->stockmovement->error); } From d2e4b9346ba747085a5d3bab2724756f7ae13940 Mon Sep 17 00:00:00 2001 From: Laurent De Coninck Date: Fri, 17 Jan 2020 17:49:50 +0100 Subject: [PATCH 2/2] enhance the doc --- .../stock/class/api_stockmovements.class.php | 45 +++++-------------- 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/htdocs/product/stock/class/api_stockmovements.class.php b/htdocs/product/stock/class/api_stockmovements.class.php index c199bfdf676..8e6621085b7 100644 --- a/htdocs/product/stock/class/api_stockmovements.class.php +++ b/htdocs/product/stock/class/api_stockmovements.class.php @@ -154,48 +154,27 @@ class StockMovements extends DolibarrApi return $obj_ret; } - /* - * @param int $product_id Id product id {@min 1} - * @param int $warehouse_id Id warehouse {@min 1} - * @param float $qty Qty to add (Use negative value for a stock decrease) {@min 0} {@message qty must be higher than 0} - * @param string $lot Lot - * @param string $movementcode Movement code {@example INV123} - * @param string $movementlabel Movement label {@example Inventory number 123} - * @param string $price To update AWP (Average Weighted Price) when you make a stock increase (qty must be higher then 0). - */ - - /** * 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 } + * @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} + * @param string $lot Lot {@from body} + * @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 array $request_data Request data * @return int ID of stock movement + * @throws RestException */ - //function post($product_id, $warehouse_id, $qty, $lot='', $movementcode='', $movementlabel='', $price=0) - public function post($request_data = null) + public function post($product_id, $warehouse_id, $qty, $lot = '', $movementcode = '', $movementlabel = '', $price = '', $dlc = '', $dluo = '') { if(! DolibarrApiAccess::$user->rights->stock->creer) { throw new RestException(401); } - // Check mandatory fields - //$result = $this->_validate($request_data); - - foreach($request_data as $field => $value) { - //$this->stockmovement->$field = $value; - if ($field == 'product_id') $product_id = $value; - if ($field == 'warehouse_id') $warehouse_id = $value; - if ($field == 'qty') $qty = $value; - if ($field == 'lot') $lot = $value; - if ($field == 'movementcode') $movementcode = $value; - if ($field == 'movementlabel') $movementlabel = $value; - if ($field == 'price') $price = $value; - if ($field == 'dlc') $dlc = $value; - if ($field == 'dluo') $dluo = $value; - } - // Type increase or decrease if ($qty >= 0) $type = 3; else $type = 2; @@ -344,7 +323,7 @@ class StockMovements extends DolibarrApi private function _validate($data) { $stockmovement = array(); - foreach (Warehouses::$FIELDS as $field) { + foreach (self::$FIELDS as $field) { if (!isset($data[$field])) throw new RestException(400, "$field field missing"); $stockmovement[$field] = $data[$field];