fix bug #18592. Please test, the bugreport is still open.

Extensive tests already done, but will continue.
This commit is contained in:
liedekef 2007-01-05 16:13:37 +00:00
parent dacb60c176
commit 92224fa7d7
2 changed files with 33 additions and 0 deletions

View File

@ -313,6 +313,8 @@ class Commande extends CommonObject
if ($this->db->query($sql) ) if ($this->db->query($sql) )
{ {
/*
* CODE SOUSPRODUITS
if($conf->stock->enabled && $conf->global->PRODUIT_SOUSPRODUITS == 1) if($conf->stock->enabled && $conf->global->PRODUIT_SOUSPRODUITS == 1)
{ {
require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php");
@ -337,6 +339,9 @@ class Commande extends CommonObject
} }
} }
* CODE SOUSPRODUITS
*/
return 1; return 1;
} }
else else
@ -354,15 +359,26 @@ class Commande extends CommonObject
{ {
if ($user->rights->commande->valider) if ($user->rights->commande->valider)
{ {
$this->db->begin();
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET fk_statut = -1'; $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET fk_statut = -1';
$sql .= " WHERE rowid = $this->id AND fk_statut = 1 ;"; $sql .= " WHERE rowid = $this->id AND fk_statut = 1 ;";
if ($this->db->query($sql) ) if ($this->db->query($sql) )
{ {
// delete all product items from reserved stock
if ($conf->stock->enabled) {
foreach($this->lignes as $ligne) {
$product = new Product($this->db);
$product->id = $ligne->fk_product;
$product->ajust_stock_commande($ligne->qty, 1);
}
}
$this->db->commit();
return 1; return 1;
} }
else else
{ {
$this->db->rollback();
dolibarr_print_error($this->db); dolibarr_print_error($this->db);
} }
} }
@ -1813,6 +1829,16 @@ class Commande extends CommonObject
$interface=new Interfaces($this->db); $interface=new Interfaces($this->db);
$result=$interface->run_triggers('ORDER_DELETE',$this,$user,$langs,$conf); $result=$interface->run_triggers('ORDER_DELETE',$this,$user,$langs,$conf);
// Fin appel triggers // Fin appel triggers
// delete all product items from reserved stock
if ($conf->stock->enabled) {
foreach($this->lignes as $ligne) {
$product = new Product($this->db);
$product->id = $ligne->fk_product;
$product->ajust_stock_commande($ligne->qty, 1);
}
}
$this->db->commit();
$this->db->commit(); $this->db->commit();
return 1; return 1;

View File

@ -355,6 +355,13 @@ class Expedition extends CommonObject
dolibarr_syslog("expedition.class.php::valid ".$this->error); dolibarr_syslog("expedition.class.php::valid ".$this->error);
return -3; return -3;
} }
// correct the stock, since otherwise the available
// stock will decrement again, since:
// available = real stock - # commanded items for prod
$product = new Product($this->db);
$product->id = $obj->fk_product;
$product->ajust_stock_commande($obj->qty, 1);
$i++; $i++;
} }