diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php
index 7280227abdca7fd957f8581d9de93f064cb1ce59..63643f75502b0cf9dae72af04fcf5e1525a668c4 100644
--- a/htdocs/commande/class/commande.class.php
+++ b/htdocs/commande/class/commande.class.php
@@ -551,23 +551,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 -1;
+				}
 			}
 			else
 			{
diff --git a/test/CommandeTest.php b/test/CommandeTest.php
index c43d550ce74b8889d47ef664cea94474b751d97a..4c0b6a48577fee42d52faa21ee06824402c88f9c 100644
--- a/test/CommandeTest.php
+++ b/test/CommandeTest.php
@@ -183,13 +183,32 @@ class CommandeTest extends PHPUnit_Framework_TestCase
 
     	print __METHOD__." id=".$localobject->id." result=".$result."\n";
     	$this->assertLessThan($result, 0);
-    	return $localobject->id;
+    	return $localobject;
     }
 
     /**
      * @depends	testCommandeValid
      * The depends says test is run only if previous is ok
      */
+    public function testCommandeCancel($localobject)
+    {
+    	global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+    	$result=$localobject->cancel($user);
+
+    	print __METHOD__." id=".$localobject->id." result=".$result."\n";
+    	$this->assertLessThan($result, 0);
+    	return $localobject->id;
+    }
+
+    /**
+     * @depends	testCommandeCancel
+     * The depends says test is run only if previous is ok
+     */
     public function testCommandeDelete($id)
     {
     	global $conf,$user,$langs,$db;