Merge remote-tracking branch 'origin/3.4' into develop

Conflicts:
	htdocs/product/class/product.class.php
This commit is contained in:
Laurent Destailleur 2013-08-27 09:36:54 +02:00
commit 1f6d0ab3ef
4 changed files with 88 additions and 92 deletions

View File

@ -114,6 +114,7 @@ Fix: [ bug #1037 ] Consumption> Supplier invoices related
Fix: User group name do not display in card (view or edit mode) Fix: User group name do not display in card (view or edit mode)
Fix: Link "Show all supplier invoice" on suplier card not working Fix: Link "Show all supplier invoice" on suplier card not working
Fix: [ bug #1039 ] Pre-defined invoices conversion Fix: [ bug #1039 ] Pre-defined invoices conversion
Fix: If only service module is activated, it's impossible to delete service
***** ChangeLog for 3.4 compared to 3.3.* ***** ***** ChangeLog for 3.4 compared to 3.3.* *****
For users: For users:

View File

@ -181,6 +181,7 @@ class ProductFournisseur extends Product
{ {
$sql = "UPDATE ".MAIN_DB_PREFIX."product_fournisseur_price"; $sql = "UPDATE ".MAIN_DB_PREFIX."product_fournisseur_price";
$sql.= " SET fk_user = " . $user->id." ,"; $sql.= " SET fk_user = " . $user->id." ,";
$sql.= " ref_fourn = \"" . $this->db->escape($ref_fourn) . "\",";
$sql.= " price = ".price2num($buyprice).","; $sql.= " price = ".price2num($buyprice).",";
$sql.= " quantity = ".$qty.","; $sql.= " quantity = ".$qty.",";
$sql.= " remise_percent = ".$remise_percent.","; $sql.= " remise_percent = ".$remise_percent.",";

View File

@ -597,121 +597,115 @@ class Product extends CommonObject
$error=0; $error=0;
if (($this->type==0 && !$user->rights->produit->supprimer) || ($this->type==1 && !$user->rights->service->supprimer)) if (($this->type == 0 && empty($user->rights->produit->supprimer)) || ($this->type == 1 && empty($user->rights->service->supprimer)))
{ {
$this->error = "ErrorForbidden"; $this->error = "ErrorForbidden";
return 0; return 0;
} }
$objectisused = $this->isObjectUsed($id); $objectisused = $this->isObjectUsed($id);
if (empty($objectisused)) if (empty($objectisused))
{
$this->db->begin();
if (! $error)
{ {
$this->db->begin(); // Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
if (! $error) $interface=new Interfaces($this->db);
{ $result=$interface->run_triggers('PRODUCT_DELETE',$this,$user,$langs,$conf);
// Appel des triggers if ($result < 0) {
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $error++; $this->errors=$interface->errors;
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('PRODUCT_DELETE',$this,$user,$langs,$conf);
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
}
// Delete all child tables
$elements = array('product_fournisseur_price','product_price','product_lang','categorie_product');
foreach($elements as $table)
{
if (! $error)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX.$table;
$sql.= " WHERE fk_product = ".$id;
dol_syslog(get_class($this).'::delete sql='.$sql, LOG_DEBUG);
$result = $this->db->query($sql);
if (! $result)
{
$error++;
$this->error = $this->db->lasterror();
dol_syslog(get_class($this).'::delete error '.$this->error, LOG_ERR);
}
}
} }
// Fin appel triggers
}
// Removed extrafields // Delete all child tables
if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used $elements = array('product_fournisseur_price','product_price','product_lang','categorie_product');
foreach($elements as $table)
{
if (! $error)
{ {
$result=$this->deleteExtraFields(); $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table;
if ($result < 0) $sql.= " WHERE fk_product = ".$id;
dol_syslog(get_class($this).'::delete sql='.$sql, LOG_DEBUG);
$result = $this->db->query($sql);
if (! $result)
{ {
$error++; $error++;
$this->errors[] = $this->db->lasterror();
dol_syslog(get_class($this).'::delete error '.$this->error, LOG_ERR); dol_syslog(get_class($this).'::delete error '.$this->error, LOG_ERR);
} }
} }
}
// Delete product // Delete product
if (! $error) if (! $error)
{ {
$sqlz = "DELETE FROM ".MAIN_DB_PREFIX."product"; $sqlz = "DELETE FROM ".MAIN_DB_PREFIX."product";
$sqlz.= " WHERE rowid = ".$id; $sqlz.= " WHERE rowid = ".$id;
dol_syslog(get_class($this).'::delete sql='.$sql, LOG_DEBUG); dol_syslog(get_class($this).'::delete sql='.$sql, LOG_DEBUG);
$resultz = $this->db->query($sqlz); $resultz = $this->db->query($sqlz);
if ( ! $resultz ) if ( ! $resultz )
{
$error++;
$this->error = $this->db->lasterror();
dol_syslog(get_class($this).'::delete error '.$this->error, LOG_ERR);
}
}
if (! $error)
{
// We remove directory
$ref = dol_sanitizeFileName($this->ref);
if ($conf->product->dir_output)
{
$dir = $conf->product->dir_output . "/" . $ref;
if (file_exists($dir))
{
$res=@dol_delete_dir_recursive($dir);
if (! $res)
{
$this->error='ErrorFailToDeleteDir';
$error++;
}
}
}
}
// Remove extrafields
if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
{
$result=$this->deleteExtraFields();
if ($result < 0)
{
$error++;
dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR);
}
}
if (! $error)
{ {
$this->db->commit(); $error++;
return 1; $this->errors[] = $this->db->lasterror();
dol_syslog(get_class($this).'::delete error '.$this->error, LOG_ERR);
} }
else }
if (! $error)
{
// We remove directory
$ref = dol_sanitizeFileName($this->ref);
if ($conf->product->dir_output)
{ {
$this->db->rollback(); $dir = $conf->product->dir_output . "/" . $ref;
return -$error; if (file_exists($dir))
{
$res=@dol_delete_dir_recursive($dir);
if (! $res)
{
$this->errors[] = 'ErrorFailToDeleteDir';
$error++;
}
}
} }
} }
// Remove extrafields
if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
{
$result=$this->deleteExtraFields();
if ($result < 0)
{
$error++;
dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR);
}
}
if (! $error)
{
$this->db->commit();
return 1;
}
else else
{ {
$this->error = "ErrorRecordHasChildren"; foreach($this->errors as $errmsg)
return 0; {
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
$this->error.=($this->error?', '.$errmsg:$errmsg);
}
$this->db->rollback();
return -$error;
} }
} }
else
{
$this->error = "ErrorRecordHasChildren";
return 0;
}
}
/** /**
* Update ou cree les traductions des infos produits * Update ou cree les traductions des infos produits