Fix insert expeditiondet_batch with extrafield

Line id of extraflied was used iso expeditiondet
This commit is contained in:
fappels 2016-09-07 14:07:29 +02:00
parent 6574ebcbff
commit 7c772b7608

View File

@ -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){