Fix : sendings and reception stock calculation must be on the same status than order and oreder supplier calculation

This commit is contained in:
Maxime Kohlhaas 2014-07-03 12:31:55 +02:00
parent b115e9b943
commit 830cc30f80

View File

@ -1680,17 +1680,19 @@ class Product extends CommonObject
$sql.= " COUNT(ed.rowid) as nb_rows, SUM(ed.qty) as qty";
$sql.= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed";
$sql.= ", ".MAIN_DB_PREFIX."commandedet as cd";
$sql.= ", ".MAIN_DB_PREFIX."commande as c";
$sql.= ", ".MAIN_DB_PREFIX."expedition as e";
$sql.= ", ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE e.rowid = ed.fk_expedition";
$sql.= " AND c.rowid = cd.fk_commande";
$sql.= " AND e.fk_soc = s.rowid";
$sql.= " AND e.entity = ".$conf->entity;
$sql.= " AND ed.fk_origin_line = cd.rowid";
$sql.= " AND cd.fk_product = ".$this->id;
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND e.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid > 0) $sql.= " AND e.fk_soc = ".$socid;
if ($filtrestatut <> '') $sql.= " AND e.fk_statut in (".$filtrestatut.")";
if ($filtrestatut <> '') $sql.= " AND c.fk_statut in (".$filtrestatut.")";
$result = $this->db->query($sql);
if ( $result )
@ -2946,7 +2948,7 @@ class Product extends CommonObject
}
if (! empty($conf->expedition->enabled))
{
$result=$this->load_stats_sending(0,'');
$result=$this->load_stats_sending(0,'1,2');
if ($result < 0) dol_print_error($db,$this->error);
$stock_sending_client=$this->stats_expedition['qty'];
}
@ -2956,12 +2958,13 @@ class Product extends CommonObject
if ($result < 0) dol_print_error($db,$this->error);
$stock_commande_fournisseur=$this->stats_commande_fournisseur['qty'];
$result=$this->load_stats_reception(0,'');
$result=$this->load_stats_reception(0,'3');
if ($result < 0) dol_print_error($db,$this->error);
$stock_reception_fournisseur=$this->stats_reception['qty'];
}
$this->stock_theorique=$this->stock_reel-($stock_commande_client-$stock_sending_client)+($stock_commande_fournisseur-$stock_reception_fournisseur);
//echo $this->stock_theorique.' = '.$this->stock_reel.' - ('.$stock_commande_client.' - '.$stock_sending_client.') + ('.$stock_commande_fournisseur.' - '.$stock_reception_fournisseur.')';
}
}