From 5ac0f77d0e0acae668eade5d9efe03be1d73c0b3 Mon Sep 17 00:00:00 2001 From: BENKE Charlene Date: Wed, 2 May 2018 17:29:31 +0200 Subject: [PATCH 1/5] Add trigger for virtual stock Allow to add/sustract some qty for GPAO OF running --- htdocs/product/class/product.class.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 2f36fd59035..2fa802a532c 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3925,7 +3925,7 @@ class Product extends CommonObject */ function load_virtual_stock() { - global $conf; + global $conf, $user, $langs; $stock_commande_client=0; $stock_commande_fournisseur=0; @@ -3975,6 +3975,16 @@ class Product extends CommonObject if (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL)) { $this->stock_theorique+=$stock_commande_fournisseur-$stock_reception_fournisseur; } + + // Call triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('LOAD_VIRTUAL_STOCK', $this, $user, $langs, $conf); + if ($result < 0) { + $this->errors=$interface->errors; + return -1; + } + } From 70c9ed960d67f1ff14023d32dcec069dec1fd6bb Mon Sep 17 00:00:00 2001 From: BENKE Charlene Date: Sun, 6 May 2018 22:11:24 +0200 Subject: [PATCH 2/5] let's play with hook --- htdocs/product/class/product.class.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 2fa802a532c..9bdb286db25 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3976,14 +3976,15 @@ class Product extends CommonObject $this->stock_theorique+=$stock_commande_fournisseur-$stock_reception_fournisseur; } - // Call triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('LOAD_VIRTUAL_STOCK', $this, $user, $langs, $conf); - if ($result < 0) { - $this->errors=$interface->errors; - return -1; + if (! is_object($hookmanager)) { + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; + $hookmanager=new HookManager($this->db); } + $hookmanager->initHooks(array('productdao')); + $parameters=array('id'=>$this->id); + // Note that $action and $object may have been modified by some hooks + $reshook=$hookmanager->executeHooks('loadvirtualstock', $parameters, $this, $action); + if ($reshook > 0) $this->stock_theorique+= $hookmanager->resPrint; } From 8ed3b3e49c9e230592c43283b74cbf03e20e3a7b Mon Sep 17 00:00:00 2001 From: BENKE Charlene Date: Sun, 6 May 2018 22:12:43 +0200 Subject: [PATCH 3/5] Update product.class.php --- htdocs/product/class/product.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 9bdb286db25..06ff0bd3ee6 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3925,7 +3925,7 @@ class Product extends CommonObject */ function load_virtual_stock() { - global $conf, $user, $langs; + global $conf, $action; $stock_commande_client=0; $stock_commande_fournisseur=0; From 5654492ba88ca74ea46559f2f26ff2c702c67f75 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Oct 2018 16:45:45 +0200 Subject: [PATCH 4/5] Update product.class.php --- htdocs/product/class/product.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index cdef8e18db7..3ed33ef5235 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -4085,7 +4085,7 @@ class Product extends CommonObject function load_virtual_stock() { // phpcs:enable - global $conf, $action; + global $conf, $hookmanager, $action; $stock_commande_client=0; $stock_commande_fournisseur=0; From 7e68d8df1b7ad8a8ed4e2ea9326820e4431db376 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Oct 2018 16:47:30 +0200 Subject: [PATCH 5/5] Update product.class.php --- htdocs/product/class/product.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 3ed33ef5235..5bf2f45d31c 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -4144,7 +4144,7 @@ class Product extends CommonObject $parameters=array('id'=>$this->id); // Note that $action and $object may have been modified by some hooks $reshook=$hookmanager->executeHooks('loadvirtualstock', $parameters, $this, $action); - if ($reshook > 0) $this->stock_theorique+= $hookmanager->resPrint; + if ($reshook > 0) $this->stock_theorique = $hookmanager->resArray['stock_theorique']; }