diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index d84ee5b5151..552b047f50c 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -476,7 +476,7 @@ class Commande extends CommonObject if ($this->db->query($sql) ) { // If stock is decremented on validate order, we must reincrement it - if($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1) + if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1) { require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php"); @@ -488,23 +488,20 @@ class Commande extends CommonObject $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; - } - else - { - $this->error=$mouvP->error; - $this->db->rollback(); - return $result; - } } - $this->db->commit(); - return 1; + if (! $error) + { + $this->statut=-1; + $this->db->commit(); + return 1; + } + else + { + $this->error=$mouvP->error; + $this->db->rollback(); + return -2; + } } else { diff --git a/htdocs/product/stock/mouvementstock.class.php b/htdocs/product/stock/mouvementstock.class.php index a492ac089c3..0a4ca4e227e 100644 --- a/htdocs/product/stock/mouvementstock.class.php +++ b/htdocs/product/stock/mouvementstock.class.php @@ -77,7 +77,7 @@ class MouvementStock dol_syslog("MouvementStock::_create sql=".$sql, LOG_DEBUG); if ($resql = $this->db->query($sql)) { - $mvid = $this->db->last_insert_id($resql); + $mvid = $this->db->last_insert_id(MAIN_DB_PREFIX."stock_mouvement"); } else {