From 646ccc1354a9b5627146c170a63d2a520e32031c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 23 Jan 2020 11:46:40 +0100 Subject: [PATCH] Fix error management --- htdocs/product/stock/class/api_stockmovements.class.php | 9 ++++++--- htdocs/product/stock/class/mouvementstock.class.php | 7 ++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/htdocs/product/stock/class/api_stockmovements.class.php b/htdocs/product/stock/class/api_stockmovements.class.php index c4f6ee56b5a..b8b0d0d2301 100644 --- a/htdocs/product/stock/class/api_stockmovements.class.php +++ b/htdocs/product/stock/class/api_stockmovements.class.php @@ -191,11 +191,14 @@ class StockMovements extends DolibarrApi $type = 3; } - $eatBy = empty($dluo) ? '' : (new DateTime($dluo))->getTimestamp(); - $sellBy = empty($dlc) ? '' : (new DateTime($dlc))->getTimestamp();; + require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; + $eatBy = empty($dluo) ? '' : dol_stringtotime($dluo); + $sellBy = empty($dlc) ? '' : dol_stringtotime($dlc); if($this->stockmovement->_create(DolibarrApiAccess::$user, $product_id, $warehouse_id, $qty, $type, $price, $movementlabel, $movementcode, '', $eatBy, $sellBy, $lot) <= 0) { - throw new RestException(503, 'Error when create stock movement : '.$this->stockmovement->error); + $errormessage = $this->stockmovement->error; + if (empty($errormessage)) $errormessage = join(',', $this->stockmovement->errors); + throw new RestException(503, 'Error when create stock movement : '.$errormessage); } return $this->stockmovement->id; diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index 93c3d316be6..9e8dcc3184e 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -172,7 +172,7 @@ class MouvementStock extends CommonObject { if (empty($batch)) { - $this->errors[]=$langs->trans("ErrorTryToMakeMoveOnProductRequiringBatchData", $product->ref); + $this->errors[]=$langs->transnoentitiesnoconv("ErrorTryToMakeMoveOnProductRequiringBatchData", $product->ref); dol_syslog("Try to make a movement of a product with status_batch on without any batch data"); $this->db->rollback(); @@ -207,7 +207,8 @@ class MouvementStock extends CommonObject if ($this->db->jdate($obj->eatby) != $eatby && $this->db->jdate($obj->eatby) != $eatbywithouthour) // We test date without hours and with hours for backward compatibility { // If found and eatby/sellby defined into table and provided and differs, return error - $this->errors[]=$langs->trans("ThisSerialAlreadyExistWithDifferentDate", $batch, dol_print_date($this->db->jdate($obj->eatby), 'dayhour'), dol_print_date($eatby, 'dayhour')); + $langs->load("stocks"); + $this->errors[] = $langs->transnoentitiesnoconv("ThisSerialAlreadyExistWithDifferentDate", $batch, dol_print_date($this->db->jdate($obj->eatby), 'dayhour'), dol_print_date($eatbywithouthour, 'dayhour')); dol_syslog("ThisSerialAlreadyExistWithDifferentDate batch=".$batch.", eatby found into product_lot = ".$obj->eatby." = ".dol_print_date($this->db->jdate($obj->eatby), 'dayhourrfc')." so eatbywithouthour = ".$eatbywithouthour." = ".dol_print_date($eatbywithouthour)." - eatby provided = ".$eatby." = ".dol_print_date($eatby, 'dayhourrfc'), LOG_ERR); $this->db->rollback(); return -3; @@ -244,7 +245,7 @@ class MouvementStock extends CommonObject if ($this->db->jdate($obj->sellby) != $sellby && $this->db->jdate($obj->sellby) != $sellbywithouthour) // We test date without hours and with hours for backward compatibility { // If found and eatby/sellby defined into table and provided and differs, return error - $this->errors[]=$langs->trans("ThisSerialAlreadyExistWithDifferentDate", $batch, dol_print_date($this->db->jdate($obj->sellby)), dol_print_date($sellby)); + $this->errors[]=$langs->transnoentitiesnoconv("ThisSerialAlreadyExistWithDifferentDate", $batch, dol_print_date($this->db->jdate($obj->sellby)), dol_print_date($sellby)); dol_syslog($langs->transnoentities("ThisSerialAlreadyExistWithDifferentDate", $batch, dol_print_date($this->db->jdate($obj->sellby)), dol_print_date($sellby)), LOG_ERR); $this->db->rollback(); return -3;