Fix #2591 Margin is incorrect used with POS

if buy price not defined, define buyprice as configured in margin admin.
If 'Force buying price if null' is off, marge will be equal to suggested
default.(min supplier price or pmp)
Updated all classes reading 'Force buying price if null' setting.
This commit is contained in:
fappels
2015-10-26 20:33:42 +01:00
parent 14470feabd
commit 4d839eea60
7 changed files with 193 additions and 106 deletions

View File

@@ -1281,16 +1281,7 @@ class Commande extends CommonOrder
$this->line->date_start=$date_start;
$this->line->date_end=$date_end;
// infos marge
if (!empty($fk_product) && empty($fk_fournprice) && empty($pa_ht)) {
// by external module, take lowest buying price
include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
$productFournisseur = new ProductFournisseur($this->db);
$productFournisseur->find_min_price_product_fournisseur($fk_product);
$this->line->fk_fournprice = $productFournisseur->product_fourn_price_id;
} else {
$this->line->fk_fournprice = $fk_fournprice;
}
$this->line->fk_fournprice = $fk_fournprice;
$this->line->pa_ht = $pa_ht;
// TODO Ne plus utiliser
@@ -2509,16 +2500,7 @@ class Commande extends CommonOrder
$this->line->skip_update_total=$skip_update_total;
$this->line->fk_unit=$fk_unit;
// infos marge
if (!empty($fk_product) && empty($fk_fournprice) && empty($pa_ht)) {
//by external module, take lowest buying price
include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
$productFournisseur = new ProductFournisseur($this->db);
$productFournisseur->find_min_price_product_fournisseur($fk_product);
$this->line->fk_fournprice = $productFournisseur->product_fourn_price_id;
} else {
$this->line->fk_fournprice = $fk_fournprice;
}
$this->line->fk_fournprice = $fk_fournprice;
$this->line->pa_ht = $pa_ht;
// TODO deprecated
@@ -3550,10 +3532,17 @@ class OrderLine extends CommonOrderLine
if (empty($this->pa_ht)) $this->pa_ht=0;
// si prix d'achat non renseigne et utilise pour calcul des marges alors prix achat = prix vente
if ($this->pa_ht == 0) {
if ($this->subprice > 0 && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1))
$this->pa_ht = $this->subprice * (1 - $this->remise_percent / 100);
// if buy price not defined, define buyprice as configured in margin admin
if ($this->pa_ht == 0)
{
if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0)
{
return $result;
}
else
{
$this->pa_ht = $result;
}
}
// Check parameters
@@ -3677,10 +3666,17 @@ class OrderLine extends CommonOrderLine
if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
if (empty($this->pa_ht)) $this->pa_ht=0;
// si prix d'achat non renseigné et utilisé pour calcul des marges alors prix achat = prix vente
if ($this->pa_ht == 0) {
if ($this->subprice > 0 && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1))
$this->pa_ht = $this->subprice * (1 - $this->remise_percent / 100);
// if buy price not defined, define buyprice as configured in margin admin
if ($this->pa_ht == 0)
{
if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0)
{
return $result;
}
else
{
$this->pa_ht = $result;
}
}
$this->db->begin();