From 049cbbfb4d67c837fb0f3258fce9cd33b7710b87 Mon Sep 17 00:00:00 2001 From: VIAL-GOUTEYRON Quentin Date: Thu, 25 Sep 2025 11:48:19 +0200 Subject: [PATCH] Fix MRP: Add hook calculateCostsBomAfter to alter BOM costs (#35465) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix doc (#35416) * fix doc * Update commonobject.class.php * Update mo.class.php * FIX missing entity filter (#35461) * Add post-processing hook `calculateCostsBomAfter` in BOM cost calculations --------- Co-authored-by: Frédéric FRANCE Co-authored-by: Regis Houssin Co-authored-by: Laurent Destailleur --- htdocs/bom/class/bom.class.php | 2 ++ htdocs/core/boxes/box_graph_invoices_permonth.php | 2 +- htdocs/core/boxes/box_graph_invoices_peryear.php | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index 35aaf18c9ae..01e327fd19b 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -1404,6 +1404,7 @@ class BOM extends CommonObject $reshook = $hookmanager->executeHooks('calculateCostsBom', $parameters, $this); // Note that $action and $object may have been modified by hook if ($reshook > 0) { + $hookmanager->executeHooks('calculateCostsBomAfter', $parameters, $this); // Note that $action and $object may have been modified by hook return $hookmanager->resPrint; } @@ -1501,6 +1502,7 @@ class BOM extends CommonObject $this->unit_cost = (float) price2num($this->total_cost * $this->qty, 'MU'); } } + $hookmanager->executeHooks('calculateCostsBomAfter', $parameters, $this); return 1; } diff --git a/htdocs/core/boxes/box_graph_invoices_permonth.php b/htdocs/core/boxes/box_graph_invoices_permonth.php index af0dcbac277..9401154cefa 100644 --- a/htdocs/core/boxes/box_graph_invoices_permonth.php +++ b/htdocs/core/boxes/box_graph_invoices_permonth.php @@ -132,7 +132,7 @@ class box_graph_invoices_permonth extends ModeleBoxes $HEIGHT = '192'; $stats = new FactureStats($this->db, $socid, $mode, 0); - $stats->where = "f.fk_statut > 0"; + $stats->where = "f.entity IN (".getEntity('invoice').") AND f.fk_statut > 0"; $px1 = null; $px2 = null; diff --git a/htdocs/core/boxes/box_graph_invoices_peryear.php b/htdocs/core/boxes/box_graph_invoices_peryear.php index fccfa5b7530..b52fb20adfd 100644 --- a/htdocs/core/boxes/box_graph_invoices_peryear.php +++ b/htdocs/core/boxes/box_graph_invoices_peryear.php @@ -126,7 +126,7 @@ class box_graph_invoices_peryear extends ModeleBoxes $HEIGHT = '192'; $stats = new FactureStats($this->db, $socid, $mode, 0); - $stats->where = "f.fk_statut > 0"; + $stats->where = "f.entity IN (".getEntity('invoice').") AND f.fk_statut > 0"; // Build graphic amount of object. $data = array(array('Lib',val1,val2,val3),...) $data2 = $stats->getAmountByYear($numberyears);