From 08bb3c1a842f3af34ad6020b45a6836ad7b333df Mon Sep 17 00:00:00 2001 From: tnegre Date: Thu, 21 Sep 2023 14:16:00 +0200 Subject: [PATCH] FIX : could not delete a fourn commande row if a commande ligne is linked --- htdocs/fourn/class/fournisseur.commande.class.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 112708a92b7..49948ebba06 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -3892,10 +3892,17 @@ class CommandeFournisseurLigne extends CommonOrderLine return -1; } - $sql = 'DELETE FROM '.MAIN_DB_PREFIX."commande_fournisseurdet WHERE rowid=".((int) $this->id); + $sql1 = 'UPDATE '.MAIN_DB_PREFIX."commandedet SET fk_commandefourndet = NULL WHERE rowid=".((int) $this->id); + $resql = $this->db->query($sql1); + if (!$resql) { + $this->db->rollback(); + return -1; + } + + $sql2 = 'DELETE FROM '.MAIN_DB_PREFIX."commande_fournisseurdet WHERE rowid=".((int) $this->id); dol_syslog(__METHOD__, LOG_DEBUG); - $resql = $this->db->query($sql); + $resql = $this->db->query($sql2); if ($resql) { if (!$notrigger) { // Call trigger