From b4fbb8654824da0c3c50c22233f43b269c22c313 Mon Sep 17 00:00:00 2001 From: Marc Guenneugues Date: Thu, 23 Apr 2020 19:22:25 +0200 Subject: [PATCH 1/2] Clean line extrafields when deleting reception --- .../class/fournisseur.commande.dispatch.class.php | 12 ++++++++++++ htdocs/reception/class/reception.class.php | 13 +++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.commande.dispatch.class.php b/htdocs/fourn/class/fournisseur.commande.dispatch.class.php index b453653c681..bd71918d92d 100644 --- a/htdocs/fourn/class/fournisseur.commande.dispatch.class.php +++ b/htdocs/fourn/class/fournisseur.commande.dispatch.class.php @@ -303,6 +303,7 @@ class CommandeFournisseurDispatch extends CommonObject $this->batch = $obj->batch; $this->eatby = $this->db->jdate($obj->eatby); $this->sellby = $this->db->jdate($obj->sellby); + $this->fetch_optionals(); } $this->db->free($resql); @@ -439,6 +440,16 @@ class CommandeFournisseurDispatch extends CommonObject } } + // Remove extrafields + if (!$error) { + $result = $this->deleteExtraFields(); + if ($result < 0) + { + $error++; + dol_syslog(get_class($this)."::delete error deleteExtraFields ".$this->error, LOG_ERR); + } + } + if (! $error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; @@ -689,6 +700,7 @@ class CommandeFournisseurDispatch extends CommonObject $line->batch = $obj->batch; $line->eatby = $this->db->jdate($obj->eatby); $line->sellby = $this->db->jdate($obj->sellby); + $line->fetch_optionals(); $this->lines[$line->id] = $line; } diff --git a/htdocs/reception/class/reception.class.php b/htdocs/reception/class/reception.class.php index 5552d45380e..17e9ea9c1ec 100644 --- a/htdocs/reception/class/reception.class.php +++ b/htdocs/reception/class/reception.class.php @@ -763,8 +763,13 @@ class Reception extends CommonObject } // extrafields + $line->array_options = $supplierorderline->array_options; if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) // For avoid conflicts if trigger used - $line->array_options = $array_options; + { + foreach ($array_options as $key => $value) { + $line->array_options[$key] = $value; + } + } $line->fk_product = $fk_product; $line->fk_commande = $supplierorderline->fk_commande; @@ -938,10 +943,14 @@ class Reception extends CommonObject if (!$error) { + $main = MAIN_DB_PREFIX . 'commande_fournisseur_dispatch'; + $ef = $main . "_extrafields"; + $sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_reception = " . $this->id . ")"; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch"; $sql .= " WHERE fk_reception = ".$this->id; - if ($this->db->query($sql)) + if ($this->db->query($sqlef) && $this->db->query($sql)) { // Delete linked object $res = $this->deleteObjectLinked(); From ababad540a311339e1b5266b586097cdad9b22c1 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 23 Apr 2020 17:29:52 +0000 Subject: [PATCH 2/2] Fixing style errors. --- .../fournisseur.commande.dispatch.class.php | 16 ++++++++-------- htdocs/reception/class/reception.class.php | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.commande.dispatch.class.php b/htdocs/fourn/class/fournisseur.commande.dispatch.class.php index bd71918d92d..cec23c590b2 100644 --- a/htdocs/fourn/class/fournisseur.commande.dispatch.class.php +++ b/htdocs/fourn/class/fournisseur.commande.dispatch.class.php @@ -441,14 +441,14 @@ class CommandeFournisseurDispatch extends CommonObject } // Remove extrafields - if (!$error) { - $result = $this->deleteExtraFields(); - if ($result < 0) - { - $error++; - dol_syslog(get_class($this)."::delete error deleteExtraFields ".$this->error, LOG_ERR); - } - } + if (!$error) { + $result = $this->deleteExtraFields(); + if ($result < 0) + { + $error++; + dol_syslog(get_class($this)."::delete error deleteExtraFields ".$this->error, LOG_ERR); + } + } if (! $error) { diff --git a/htdocs/reception/class/reception.class.php b/htdocs/reception/class/reception.class.php index 17e9ea9c1ec..ce718fda964 100644 --- a/htdocs/reception/class/reception.class.php +++ b/htdocs/reception/class/reception.class.php @@ -766,10 +766,10 @@ class Reception extends CommonObject $line->array_options = $supplierorderline->array_options; if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) // For avoid conflicts if trigger used { - foreach ($array_options as $key => $value) { - $line->array_options[$key] = $value; - } - } + foreach ($array_options as $key => $value) { + $line->array_options[$key] = $value; + } + } $line->fk_product = $fk_product; $line->fk_commande = $supplierorderline->fk_commande;