diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index 34895cfc323..d84ee5b5151 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -461,6 +461,8 @@ class Commande extends CommonObject { global $conf; + $error=0; + if ($user->rights->commande->valider) { $this->db->begin(); @@ -470,6 +472,7 @@ class Commande extends CommonObject $sql.= " WHERE rowid = ".$this->id; $sql.= " AND fk_statut = 1"; + dol_syslog("Commande::cancel sql=".$sql, LOG_DEBUG); if ($this->db->query($sql) ) { // If stock is decremented on validate order, we must reincrement it @@ -477,13 +480,18 @@ class Commande extends CommonObject { require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php"); - $mouvP = new MouvementStock($this->db); - // We increment stock of product (and sub-products) - $entrepot_id = "1"; //Todo: ajouter possibilite de choisir l'entrepot - $result=$mouvP->reception($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty, $this->lignes[$i]->subprice); - - if ($result > 0) + if ($this->lignes[$i]->fk_product > 0 && $this->lignes[$i]->product_type == 0) { + $mouvP = new MouvementStock($this->db); + // We increment stock of product (and sub-products) + $entrepot_id = "1"; //Todo: ajouter possibilite de choisir l'entrepot + $result=$mouvP->reception($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty, $this->lignes[$i]->subprice); + if ($result < 0) { $error++; } + } + + if (! $error) + { + $this->statut=-1; $this->db->commit(); return $result; }