From e86fed02fc288f7dc87bf06f8197e5c389dfb08f Mon Sep 17 00:00:00 2001
From: Regis Houssin <regis@dolibarr.fr>
Date: Thu, 15 Mar 2012 07:23:49 +0100
Subject: [PATCH] Fix: missing linked objects

---
 htdocs/comm/propal.php                        |  3 ++-
 htdocs/commande/class/commande.class.php      | 19 +++++++++++++++----
 htdocs/compta/facture/class/facture.class.php | 11 +++++++++--
 3 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index c5c6571c351..5289521295b 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -2004,6 +2004,7 @@ else
 }
 
 
-$db->close();
+// End of page
 llxFooter();
+$db->close();
 ?>
diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php
index d11ab2b1ceb..2a188fa044e 100644
--- a/htdocs/commande/class/commande.class.php
+++ b/htdocs/commande/class/commande.class.php
@@ -868,6 +868,7 @@ class Commande extends CommonObject
     function createFromProposal($object)
     {
         global $conf,$user,$langs;
+        global $hookmanager;
 
         $error=0;
 
@@ -915,16 +916,26 @@ class Commande extends CommonObject
             $this->note                 = $object->note;
             $this->note_public          = $object->note_public;
 
-            $this->origin      = $object->element;
-            $this->origin_id   = $object->id;
+            $this->origin				= $object->element;
+            $this->origin_id			= $object->id;
+            
+            // Possibility to add external linked objects with hooks
+            $this->linked_objects[$this->origin] = $this->origin_id;
+            if (is_array($object->other_linked_objects) && ! empty($object->other_linked_objects))
+            {
+            	$this->linked_objects = array_merge($this->linked_objects, $object->other_linked_objects);
+            }
 
             $ret = $this->create($user);
 
             if ($ret > 0)
             {
                 // Actions hooked (by external module)
-                include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
-                $hookmanager=new HookManager($this->db);
+                if (! is_object($hookmanager))
+                {
+                	include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
+                	$hookmanager=new HookManager($this->db);
+                }
                 $hookmanager->initHooks(array('orderdao'));
 
                 $parameters=array('objFrom'=>$object);
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index dad4757f61d..f0af7b909b9 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -669,8 +669,15 @@ class Facture extends CommonObject
         $this->note                 = $object->note;
         $this->note_public          = $object->note_public;
 
-        $this->origin      = $object->element;
-        $this->origin_id   = $object->id;
+        $this->origin				= $object->element;
+        $this->origin_id			= $object->id;
+        
+        // Possibility to add external linked objects with hooks
+        $this->linked_objects[$this->origin] = $this->origin_id;
+        if (is_array($object->other_linked_objects) && ! empty($object->other_linked_objects))
+        {
+        	$this->linked_objects = array_merge($this->linked_objects, $object->other_linked_objects);
+        }
 
         $ret = $this->create($user);
 
-- 
GitLab