From 371819820f1d20a1145570801e304f5fead79421 Mon Sep 17 00:00:00 2001 From: Norbert Penel Date: Wed, 10 Feb 2021 11:16:11 +0100 Subject: [PATCH 1/2] Add Hook in stockmouvement --- .../stock/class/mouvementstock.class.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index 4e1c8a4e57f..1e879e68656 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -159,6 +159,40 @@ class MouvementStock extends CommonObject $error = 0; dol_syslog(get_class($this)."::_create start userid=$user->id, fk_product=$fk_product, warehouse_id=$entrepot_id, qty=$qty, type=$type, price=$price, label=$label, inventorycode=$inventorycode, datem=".$datem.", eatby=".$eatby.", sellby=".$sellby.", batch=".$batch.", skip_batch=".$skip_batch); + // start hook at beginning + global $action, $hookmanager; + $hookmanager->initHooks(array('mouvementstock')); + // Hook of thirdparty module + if (is_object($hookmanager)) { + $parameters = array( + 'currentcontext' => 'mouvementstock', + 'user' => &$user, + 'fk_product' => &$fk_product, + 'entrepot_id' => &$entrepot_id, + 'qty' => &$qty, + 'type' => &$type, + 'price' => &$price, + 'label' => &$label, + 'inventorycode' => &$inventorycode, + 'datem' => &$datem, + 'eatby' => &$eatby, + 'sellby' => &$sellby, + 'batch' => &$batch, + 'skip_batch' => &$skip_batch, + 'id_product_batch' => &$id_product_batch + ); + $reshook = $hookmanager->executeHooks('_create', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks + + if ($reshook < 0) { + if (!empty($hookmanager->resPrint)) + dol_print_error('', $hookmanager->resPrint); + return $reshook; + } elseif ($reshook > 0) { + return $hookmanager->resPrint; + } + } + // end hook at beginning + // Clean parameters $price = price2num($price, 'MU'); // Clean value for the casse we receive a float zero value, to have it a real zero value. if (empty($price)) $price = 0; From cd79e3985e797784d951564ed351a5fbf6ecf1af Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 11 Feb 2021 18:36:17 +0100 Subject: [PATCH 2/2] Update mouvementstock.class.php --- htdocs/product/stock/class/mouvementstock.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index 1e879e68656..639816f842d 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -181,7 +181,7 @@ class MouvementStock extends CommonObject 'skip_batch' => &$skip_batch, 'id_product_batch' => &$id_product_batch ); - $reshook = $hookmanager->executeHooks('_create', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks + $reshook = $hookmanager->executeHooks('stockMovementCreate', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) { if (!empty($hookmanager->resPrint))