From f38bf5a7d211ff016eaa589c06ecba5656be0e54 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 3 Apr 2015 11:00:52 +0200 Subject: [PATCH] Fix extrafields were not saved when creating a supplier order Fix removed hooks where we must use trigger --- htdocs/commande/class/commande.class.php | 41 ++++++++----------- .../class/fournisseur.commande.class.php | 6 +++ htdocs/fourn/commande/card.php | 14 +++---- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 259a3bc5d6a..edf380b2e36 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -790,7 +790,7 @@ class Commande extends CommonOrder $this->lines[$i]->fk_fournprice, $this->lines[$i]->pa_ht, $this->lines[$i]->label, - $this->lines[$i]->array_options + $this->lines[$i]->array_options ); if ($result < 0) { @@ -862,28 +862,25 @@ class Commande extends CommonOrder if (! $error) { - $action='create'; + //$action='create'; // Actions on extra fields (by external module or standard code) // FIXME le hook fait double emploi avec le trigger !! - $hookmanager->initHooks(array('orderdao')); + /*$hookmanager->initHooks(array('orderdao')); $parameters=array('socid'=>$this->id); $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks if (empty($reshook)) { if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used - { + {*/ $result=$this->insertExtraFields(); - if ($result < 0) - { - $error++; - } - } + if ($result < 0) $error++; + /* } } - else if ($reshook < 0) $error++; + else if ($reshook < 0) $error++;*/ } - if (! $notrigger) + if (! $error && ! $notrigger) { // Call trigger $result=$this->call_trigger('ORDER_CREATE',$user); @@ -891,29 +888,27 @@ class Commande extends CommonOrder // End call triggers } - if (!$error) { + if (! $error) + { $this->db->commit(); return $this->id; } - - foreach($this->errors as $errmsg) - { - dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); - } - $this->db->rollback(); - return -1*$error; - + else + { + $this->db->rollback(); + return -1*$error; + } } else - { + { + $this->error=$this->db->lasterror(); $this->db->rollback(); return -1; } } } else - { + { dol_print_error($this->db); $this->db->rollback(); return -1; diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 3cd07d7fc53..f0abed84cbb 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -1066,6 +1066,12 @@ class CommandeFournisseur extends CommonOrder } } + if (! $error) + { + $result=$this->insertExtraFields(); + if ($result < 0) $error++; + } + if (! $error && ! $notrigger) { // Call trigger diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index cbbeaa99499..995c493df51 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -918,22 +918,20 @@ if (empty($reshook)) } $object_id = $object->create($user); - if ($object_id > 0) { dol_include_once('/' . $element . '/class/' . $subelement . '.class.php'); $classname = ucfirst($subelement); $srcobject = new $classname($db); - $srcobject->fetch($object->origin_id); - - $object->set_date_livraison($user, $srcobject->date_livraison); - $object->set_id_projet($user, $srcobject->fk_project); dol_syslog("Try to find source object origin=" . $object->origin . " originid=" . $object->origin_id . " to add lines"); $result = $srcobject->fetch($object->origin_id); if ($result > 0) { + $object->set_date_livraison($user, $srcobject->date_livraison); + $object->set_id_projet($user, $srcobject->fk_project); + $lines = $srcobject->lines; if (empty($lines) && method_exists($srcobject, 'fetch_lines')) { @@ -1010,11 +1008,11 @@ if (empty($reshook)) if ($reshook < 0) $error ++; } else { - setEventMessage($srcobject->error, 'errors'); + setEventMessages($srcobject->error, $srcobject->errors, 'errors'); $error ++; } } else { - setEventMessage($object->error, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); $error ++; } } @@ -1024,7 +1022,7 @@ if (empty($reshook)) if ($id < 0) { $error++; - setEventMessage($langs->trans($object->error), 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } }