From 22979523dbad10ba9843bbaef1b8f3eb7bbb6274 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 20 Oct 2015 02:34:53 +0200 Subject: [PATCH] Try a fix for #3742 --- htdocs/compta/facture.php | 4 +-- htdocs/core/class/commonobject.class.php | 43 +++++++++++++++++------- htdocs/fourn/facture/card.php | 4 +-- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 5105f8196d1..a178abae47c 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -2347,8 +2347,8 @@ if ($action == 'create') } print '' . $langs->trans($newclassname) . '' . $objectsrc->getNomUrl(1); - //We check if Origin document has already an invoice attached to it - $objectsrc->fetchObjectLinked($originid,'','','facture'); + // We check if Origin document (id and type is known) has already at least one invoice attached to it + $objectsrc->fetchObjectLinked($originid,$origin,'','facture'); $cntinvoice=count($objectsrc->linkedObjects['facture']); if ($cntinvoice>=1) { diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index d20d5d82bde..1094b549fab 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2231,13 +2231,18 @@ abstract class CommonObject /** * Fetch array of objects linked to current object. Links are loaded into this->linkedObjects array and this->linkedObjectsIds - * - * @param int $sourceid Object source id - * @param string $sourcetype Object source type - * @param int $targetid Object target id - * @param string $targettype Object target type + * Possible usage for parameters: + * - all parameters empty -> we look all link to current object (current object can be source or target) + * - one couple id+type is provided -> this will set $justsource or $justtarget + * - one couple id+type is provided and other type is provided -> this will set $justsource or $justtarget + criteria on other type + * + * + * @param int $sourceid Object source id (if not defined, id of object) + * @param string $sourcetype Object source type (if not defined, element name of object) + * @param int $targetid Object target id (if not defined, id of object) + * @param string $targettype Object target type (if not defined, elemennt name of object) * @param string $clause 'OR' or 'AND' clause used when both source id and target id are provided - * @param int $alsosametype 0=Return only links to different object than source. 1=Include also link to objects of same type. + * @param int $alsosametype 0=Return only links to object that differs from source. 1=Include also link to objects of same type. * @return void * @see add_object_linked, updateObjectLinked, deleteObjectLinked */ @@ -2255,12 +2260,12 @@ abstract class CommonObject if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid)) { - $justsource=true; + $justsource=true; // the source (id and type) is a search criteria if (! empty($targettype)) $withtargettype=true; } if (! empty($targetid) && ! empty($targettype) && empty($sourceid)) { - $justtarget=true; + $justtarget=true; // the target (id and type) is a search criteria if (! empty($sourcetype)) $withsourcetype=true; } @@ -2309,13 +2314,27 @@ abstract class CommonObject while ($i < $num) { $obj = $this->db->fetch_object($resql); - if ($obj->fk_source == $sourceid) + if ($justsource || $justtarget) { - $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; + if ($justsource) + { + $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; + } + else if ($justtarget) + { + $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; + } } - if ($obj->fk_target == $targetid) + else { - $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; + if ($obj->fk_source == $sourceid && $obj->sourcetype == $sourcetype) + { + $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; + } + if ($obj->fk_target == $targetid && $obj->targettype == $targettype) + { + $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; + } } $i++; } diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index a8d84c7cd36..f3f9dc6afa3 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -1515,8 +1515,8 @@ if ($action == 'create') $txt=$langs->trans("SupplierOrder"); } print ''.$txt.''.$objectsrc->getNomUrl(1); - //We check if Origin document has already an invoice attached to it - $objectsrc->fetchObjectLinked($originid,'','','invoice_supplier'); + // We check if Origin document (id and type is known) has already at least one invoice attached to it + $objectsrc->fetchObjectLinked($originid,$origin,'','invoice_supplier'); $cntinvoice=count($objectsrc->linkedObjects['invoice_supplier']); if ($cntinvoice>=1) {