From 6c82b1d0e1bd57e65e4f2c4e426c566ba10df51d Mon Sep 17 00:00:00 2001 From: Indelog Date: Tue, 5 Oct 2021 11:18:42 +0200 Subject: [PATCH] Fix creataing invoice originating for custom module This fix the invoice create form when we provide `origin` element in url. The actual create form overide the value for origin field with `$objectsrc->element`. This make creation of invoice originating from a custom module module impossible because we need the module part to instantiate the class for the custom module object. This also modify Common Object::fetch Object Linked() to append the module part for `$sourcetype` and `$targettype` if it not set and object have module property and it not in core module. --- htdocs/compta/facture/card.php | 6 ++++-- htdocs/core/class/commonobject.class.php | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 6ea03d8bd23..1e2eb0bd8bb 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -3730,8 +3730,10 @@ if ($action == 'create') { print ''."\n"; print ''."\n"; print ''."\n"; - print ''; - print ''; + // The lines below override the parameters set by GET or POST for origin value and also be present in $origin and $originid variables (it make creation of invoice originating from an external module object impossible because for get an external module class we also need to know the name of the module in addition of the name of the element). + // This input fields already printed above at the
begin. + //print ''; + //print ''; switch (get_class($objectsrc)) { case 'Propal': diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index ab258d736ff..c4564ddcd6d 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3708,10 +3708,23 @@ abstract class CommonObject } } + // Elements of the core modules which have `$module` property but may to which we don't want to prefix module part to the element name for finding the linked object in llx_element_element. + // It's because an entry for this element may be exist in llx_element_element before this modification (version <=14.2) and ave named only with their element name in fk_source or fk_target. + $coremodule = array('knowledgemanagement', 'partnership', 'workstation', 'ticket', 'recruitment', 'eventorganization'); + $sourceid = (!empty($sourceid) ? $sourceid : $this->id); $targetid = (!empty($targetid) ? $targetid : $this->id); - $sourcetype = (!empty($sourcetype) ? $sourcetype : $this->element); - $targettype = (!empty($targettype) ? $targettype : $this->element); + // For module whit + if (empty($sourcetype)) { + // If empty $sourcetype and no core module, add module part for searching element in llx_element_element (needed for external module). + if (!empty($this->module) && ! in_array($this->module, $coremodule)) $sourcetype = $this->module.'_'.$this->element; + else $sourcetype = $this->element; + } + if (empty($targettype)) { + // If empty $targettype and no core module, add module part for searching element in llx_element_element (needed for external module). + if (!empty($this->module) && ! in_array($this->module, $coremodule)) $targettype = $this->module.'_'.$this->element; + else $targettype = $this->element; + } /*if (empty($sourceid) && empty($targetid)) {