Delete from product_batch on product delete

This commit is contained in:
fappels 2016-11-15 11:29:12 +01:00
parent 59ba5ef484
commit 2e6b27f094

View File

@ -924,7 +924,23 @@ class Product extends CommonObject
if ($result < 0) { $error++; }
// End call triggers
}
// Delete from product_batch on product delete
if (! $error && $this->hasbatch())
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX.'product_batch';
$sql.= " WHERE fk_product_stock IN (";
$sql.= "SELECT rowid FROM ".MAIN_DB_PREFIX.'product_stock';
$sql.= " WHERE fk_product = ".$id.")";
dol_syslog(get_class($this).'::delete', LOG_DEBUG);
$result = $this->db->query($sql);
if (! $result)
{
$error++;
$this->errors[] = $this->db->lasterror();
}
}
// Delete all child tables
if (! $error)
{