From 7c772b7608ef0f18c9286960612e4ecdf8ec95c1 Mon Sep 17 00:00:00 2001 From: fappels Date: Wed, 7 Sep 2016 14:07:29 +0200 Subject: [PATCH] Fix insert expeditiondet_batch with extrafield Line id of extraflied was used iso expeditiondet --- htdocs/expedition/class/expedition.class.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index bb8cb9bcdda..93768dce5b1 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -365,12 +365,13 @@ class Expedition extends CommonObject * @param int $origin_line_id Id of source line * @param int $qty Quantity * @param array $array_options extrafields array - * @return int <0 if KO, >0 if OK + * @return int <0 if KO, line_id if OK */ function create_line($entrepot_id, $origin_line_id, $qty,$array_options=0) { global $conf; $error = 0; + $line_id = 0; $sql = "INSERT INTO ".MAIN_DB_PREFIX."expeditiondet ("; $sql.= "fk_expedition"; @@ -390,6 +391,8 @@ class Expedition extends CommonObject $error++; } + if (! $error) $line_id = $this->db->last_insert_id(MAIN_DB_PREFIX."expeditiondet"); + if (!$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used { $expeditionline = new ExpeditionLigne($this->db); @@ -403,7 +406,7 @@ class Expedition extends CommonObject } } - if (! $error) return 1; + if (! $error) return $line_id; else return -1; } @@ -432,14 +435,13 @@ class Expedition extends CommonObject // create shipment lines foreach ($stockLocationQty as $stockLocation => $qty) { - if ($this->create_line($stockLocation,$line_ext->origin_line_id,$qty,$array_options) < 0) + if (($line_id = $this->create_line($stockLocation,$line_ext->origin_line_id,$qty,$array_options)) < 0) { $error++; } else { // create shipment batch lines for stockLocation - $line_id= $this->db->last_insert_id(MAIN_DB_PREFIX."expeditiondet"); foreach ($tab as $detbatch) { if ($detbatch->entrepot_id == $stockLocation){