Merge pull request #13721 from simicar29/11.0

Clean line extrafields when deleting invoice
This commit is contained in:
Laurent Destailleur 2020-04-23 18:12:28 +02:00 committed by GitHub
commit c8a93437ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 3 deletions

View File

@ -664,9 +664,13 @@ class FactureRec extends CommonInvoice
$error = 0;
$this->db->begin();
$main = MAIN_DB_PREFIX . 'facturedet_rec';
$ef = $main . "_extrafields";
$sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_facture = $rowid)";
dol_syslog($sqlef);
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE fk_facture = ".$rowid;
dol_syslog($sql);
if ($this->db->query($sql))
if ($this->db->query($sqlef) && $this->db->query($sql))
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_rec WHERE rowid = ".$rowid;
dol_syslog($sql);
@ -675,6 +679,9 @@ class FactureRec extends CommonInvoice
// Delete linked object
$res = $this->deleteObjectLinked();
if ($res < 0) $error = -3;
// Delete extrafields
$res = $this->deleteExtraFields();
if ($res < 0) $error = -4;
}
else
{
@ -1882,6 +1889,14 @@ class FactureLigneRec extends CommonInvoiceLine
}
}
if (!$error)
{
$result = $this->deleteExtraFields();
if ($result < 0) {
$error++;
}
}
if (!$error)
{
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.$this->id;

View File

@ -2166,13 +2166,16 @@ class Facture extends CommonInvoice
}
}
// Invoice line extrafileds
$main = MAIN_DB_PREFIX . 'facturedet';
$ef = $main . "_extrafields";
$sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_facture = $rowid)";
// Delete invoice line
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facturedet WHERE fk_facture = '.$rowid;
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
if ($this->db->query($sql) && $this->delete_linked_contact())
if ($this->db->query($sqlef) && $this->db->query($sql) && $this->delete_linked_contact())
{
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture WHERE rowid = '.$rowid;
@ -5312,6 +5315,13 @@ class FactureLigne extends CommonInvoiceLine
}
// End call triggers
// extrafields
$result = $this->deleteExtraFields();
if ($result < 0)
{
$this->db->rollback();
return -1;
}
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = ".$this->rowid;
dol_syslog(get_class($this)."::delete", LOG_DEBUG);