Fix error management of warehouse->delete

This commit is contained in:
Laurent Destailleur 2019-06-20 18:15:14 +02:00
parent d47cf87c00
commit e28bf71964

View File

@ -262,6 +262,10 @@ class Entrepot extends CommonObject
*/ */
public function delete($user, $notrigger = 0) public function delete($user, $notrigger = 0)
{ {
$error = 0;
dol_syslog(get_class($this)."::delete id=".$this->id, LOG_DEBUG);
$this->db->begin(); $this->db->begin();
if (! $error && empty($notrigger)) if (! $error && empty($notrigger))
@ -279,7 +283,7 @@ class Entrepot extends CommonObject
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX.$table; $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table;
$sql.= " WHERE fk_entrepot = " . $this->id; $sql.= " WHERE fk_entrepot = " . $this->id;
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$result=$this->db->query($sql); $result=$this->db->query($sql);
if (! $result) if (! $result)
{ {
@ -294,16 +298,28 @@ class Entrepot extends CommonObject
$sql = "DELETE FROM ".MAIN_DB_PREFIX."entrepot"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."entrepot";
$sql.= " WHERE rowid = " . $this->id; $sql.= " WHERE rowid = " . $this->id;
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql1=$this->db->query($sql); $resql1=$this->db->query($sql);
if (! $resql1)
{
$error++;
$this->errors[] = $this->db->lasterror();
}
}
if (! $error)
{
// Update denormalized fields because we change content of produt_stock. Warning: Do not use "SET p.stock", does not works with pgsql // Update denormalized fields because we change content of produt_stock. Warning: Do not use "SET p.stock", does not works with pgsql
$sql = "UPDATE ".MAIN_DB_PREFIX."product as p SET stock = (SELECT SUM(ps.reel) FROM ".MAIN_DB_PREFIX."product_stock as ps WHERE ps.fk_product = p.rowid)"; $sql = "UPDATE ".MAIN_DB_PREFIX."product as p SET stock = (SELECT SUM(ps.reel) FROM ".MAIN_DB_PREFIX."product_stock as ps WHERE ps.fk_product = p.rowid)";
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql2=$this->db->query($sql); $resql2=$this->db->query($sql);
if (! $resql2)
{
$error++;
$this->errors[] = $this->db->lasterror();
}
}
if ($resql1 && $resql2) if (! $error)
{ {
$this->db->commit(); $this->db->commit();
return 1; return 1;
@ -311,14 +327,6 @@ class Entrepot extends CommonObject
else else
{ {
$this->db->rollback(); $this->db->rollback();
$this->error=$this->db->lasterror();
return -2;
}
}
else
{
$this->db->rollback();
$this->error=$this->db->lasterror();
return -1; return -1;
} }
} }