Fix error when upgating price

This commit is contained in:
Laurent Destailleur 2015-04-02 19:41:19 +02:00
parent e480177d9c
commit 9921eb8496
3 changed files with 25 additions and 10 deletions

View File

@ -54,6 +54,10 @@ if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
$select_pricing_rules['PRODUIT_CUSTOMER_PRICES_BY_QTY&PRODUIT_MULTIPRICES'] = $langs->trans('MultiPricesAbility') . '+' . $langs->trans('PriceByQuantity');
}
// Clean param
if (! empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_MULTIPRICES_LIMIT)) $conf->global->PRODUIT_MULTIPRICES_LIMIT = 5;
/*
* Actions

View File

@ -1146,6 +1146,9 @@ class Product extends CommonObject
$now=dol_now();
// Clean parameters
if (empty($this->price_by_qty)) $this->price_by_qty=0;
// Add new price
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_price(price_level,date_price,fk_product,fk_user_author,price,price_ttc,price_base_type,tosell,tva_tx,recuperableonly,";
$sql.= " localtax1_tx, localtax2_tx, price_min,price_min_ttc,price_by_qty,entity,fk_price_expression) ";
@ -1153,7 +1156,7 @@ class Product extends CommonObject
$sql.= " ".$this->localtax1_tx.",".$this->localtax2_tx.",".$this->price_min.",".$this->price_min_ttc.",".$this->price_by_qty.",".$conf->entity.",".($this->fk_price_expression > 0?$this->fk_price_expression:'null');
$sql.= ")";
dol_syslog(get_class($this)."_log_price", LOG_DEBUG);
dol_syslog(get_class($this)."::_log_price", LOG_DEBUG);
$resql=$this->db->query($sql);
if(! $resql)
{
@ -1180,7 +1183,7 @@ class Product extends CommonObject
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price";
$sql.= " WHERE rowid=".$rowid;
dol_syslog(get_class($this)."log_price_delete", LOG_DEBUG);
dol_syslog(get_class($this)."::log_price_delete", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
@ -1315,7 +1318,7 @@ class Product extends CommonObject
$id=$this->id;
dol_syslog(get_class($this)."update_price id=".$id." newprice=".$newprice." newpricebase=".$newpricebase." newminprice=".$newminprice." level=".$level." npr=".$newnpr);
dol_syslog(get_class($this)."::update_price id=".$id." newprice=".$newprice." newpricebase=".$newpricebase." newminprice=".$newminprice." level=".$level." npr=".$newnpr);
// Clean parameters
if (empty($this->tva_tx)) $this->tva_tx=0;
@ -1393,7 +1396,7 @@ class Product extends CommonObject
$sql.= " recuperableonly='".$newnpr."'";
$sql.= " WHERE rowid = ".$id;
dol_syslog(get_class($this)."update_price", LOG_DEBUG);
dol_syslog(get_class($this)."::update_price", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{

View File

@ -51,12 +51,14 @@ $eid = GETPOST('eid', 'int');
// Security check
$fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
$fieldtype = (! empty($ref) ? 'ref' : 'rowid');
if ($user->societe_id)
$socid = $user->societe_id;
if ($user->societe_id) $socid = $user->societe_id;
$result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
$object = new Product($db);
// Clean param
if (! empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_MULTIPRICES_LIMIT)) $conf->global->PRODUIT_MULTIPRICES_LIMIT = 5;
$error=0;
@ -119,7 +121,8 @@ if ($action == 'update_price' && ! GETPOST("cancel") && ($user->rights->produit-
$newprice = $newprice_min; //Set price same as min, the user will not see the
}
if ($object->updatePrice($newprice, $newpricebase, $user, $newvat, $newprice_min, $level, $newnpr, $newpsq) > 0) {
if ($object->updatePrice($newprice, $newpricebase, $user, $newvat, $newprice_min, $level, $newnpr, $newpsq) > 0)
{
if ($object->fk_price_expression != 0) {
//Check the expression validity by parsing it
$priceparser = new PriceParser($db);
@ -130,7 +133,8 @@ if ($action == 'update_price' && ! GETPOST("cancel") && ($user->rights->produit-
setEventMessage($priceparser->translatedError(), 'errors');
}
}
if (empty($error) && ! empty($conf->dynamicprices->enabled)) {
if (empty($error) && ! empty($conf->dynamicprices->enabled))
{
$ret=$object->setPriceExpression($object->fk_price_expression);
if ($ret < 0)
{
@ -139,7 +143,8 @@ if ($action == 'update_price' && ! GETPOST("cancel") && ($user->rights->produit-
setEventMessage($object->error, 'errors');
}
}
if (empty($error)) {
if (empty($error))
{
$action = '';
setEventMessage($langs->trans("RecordSaved"));
}
@ -147,7 +152,10 @@ if ($action == 'update_price' && ! GETPOST("cancel") && ($user->rights->produit-
$action = 'edit_price';
setEventMessage($object->error, 'errors');
}
} else if ($action == 'delete' && $user->rights->produit->supprimer) {
}
if ($action == 'delete' && $user->rights->produit->supprimer)
{
$result = $object->log_price_delete($user, $_GET ["lineid"]);
if ($result < 0) {
setEventMessage($object->error, 'errors');