From 6793bfae3a1f0740cf5449c89f3ea5740a0e5161 Mon Sep 17 00:00:00 2001 From: jean Date: Sat, 10 Mar 2018 14:17:52 +0100 Subject: [PATCH 1/2] FIX #8289 add a cofoiguration for correct stopck calculation --- htdocs/product/class/product.class.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index e6439031146..8d6042907ca 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -2271,6 +2271,29 @@ class Product extends CommonObject } } } + + if (! empty($conf->global->STOCK_CALCULATE_ON_BILL) && ! empty($conf->global->DECREASE_ONLY_UNINVOICEDPRODUCTS)) + { + $adeduire = 0; + $sql = "SELECT sum(fd.qty) as count FROM ".MAIN_DB_PREFIX."facturedet fd "; + $sql .= " JOIN ".MAIN_DB_PREFIX."facture f ON fd.fk_facture = f.rowid "; + $sql .= " JOIN ".MAIN_DB_PREFIX."element_element el ON el.fk_target = f.rowid and el.targettype = 'facture' and sourcetype = 'commande'"; + $sql .= " JOIN ".MAIN_DB_PREFIX."commande c ON el.fk_source = c.rowid "; + $sql .= " WHERE c.fk_statut IN (".$filtrestatut.") AND c.facture = 0 AND fd.fk_product = ".$this->id; + dol_syslog(__METHOD__.":: sql $sql", LOG_NOTICE); + + $resql = $this->db->query($sql); + if ( $resql ) + { + if ($this->db->num_rows($resql) > 0) + { + $obj = $this->db->fetch_object($resql); + $adeduire += $obj->count; + } + } + + $this->stats_commande['qty'] -= $adeduire ; + } return 1; } From 6fcc271790c9b2dc3c9e2114415aa19f7260f4b0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 10 Mar 2018 18:57:55 +0100 Subject: [PATCH 2/2] Update product.class.php --- htdocs/product/class/product.class.php | 42 +++++++++++++++----------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 8d6042907ca..7f1387261b4 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -2272,27 +2272,33 @@ class Product extends CommonObject } } - if (! empty($conf->global->STOCK_CALCULATE_ON_BILL) && ! empty($conf->global->DECREASE_ONLY_UNINVOICEDPRODUCTS)) + // If stock decrease is on invoice validation, the theorical stock continue to + // count the orders to ship in theorical stock when some are already removed b invoice validation. + // If option DECREASE_ONLY_UNINVOICEDPRODUCTS is on, we make a compensation. + if (! empty($conf->global->STOCK_CALCULATE_ON_BILL)) { - $adeduire = 0; - $sql = "SELECT sum(fd.qty) as count FROM ".MAIN_DB_PREFIX."facturedet fd "; - $sql .= " JOIN ".MAIN_DB_PREFIX."facture f ON fd.fk_facture = f.rowid "; - $sql .= " JOIN ".MAIN_DB_PREFIX."element_element el ON el.fk_target = f.rowid and el.targettype = 'facture' and sourcetype = 'commande'"; - $sql .= " JOIN ".MAIN_DB_PREFIX."commande c ON el.fk_source = c.rowid "; - $sql .= " WHERE c.fk_statut IN (".$filtrestatut.") AND c.facture = 0 AND fd.fk_product = ".$this->id; - dol_syslog(__METHOD__.":: sql $sql", LOG_NOTICE); - - $resql = $this->db->query($sql); - if ( $resql ) + if (! empty($conf->global->DECREASE_ONLY_UNINVOICEDPRODUCTS)) { - if ($this->db->num_rows($resql) > 0) - { - $obj = $this->db->fetch_object($resql); - $adeduire += $obj->count; - } - } + $adeduire = 0; + $sql = "SELECT sum(fd.qty) as count FROM ".MAIN_DB_PREFIX."facturedet fd "; + $sql .= " JOIN ".MAIN_DB_PREFIX."facture f ON fd.fk_facture = f.rowid "; + $sql .= " JOIN ".MAIN_DB_PREFIX."element_element el ON el.fk_target = f.rowid and el.targettype = 'facture' and sourcetype = 'commande'"; + $sql .= " JOIN ".MAIN_DB_PREFIX."commande c ON el.fk_source = c.rowid "; + $sql .= " WHERE c.fk_statut IN (".$filtrestatut.") AND c.facture = 0 AND fd.fk_product = ".$this->id; + dol_syslog(__METHOD__.":: sql $sql", LOG_NOTICE); - $this->stats_commande['qty'] -= $adeduire ; + $resql = $this->db->query($sql); + if ( $resql ) + { + if ($this->db->num_rows($resql) > 0) + { + $obj = $this->db->fetch_object($resql); + $adeduire += $obj->count; + } + } + + $this->stats_commande['qty'] -= $adeduire; + } } return 1;