diff --git a/htdocs/document.php b/htdocs/document.php index 4459fede63e..b1fd01ab77e 100644 --- a/htdocs/document.php +++ b/htdocs/document.php @@ -213,14 +213,14 @@ if (!empty($hashp)) { $original_file = (($tmp[1] ? $tmp[1] . '/' : '') . $ecmfile->filename); // this is relative to module dir } - $entity = $ecmfile->entity; - if (isModEnabled('multicompany') && !empty($ecmfile->src_object_type) && $ecmfile->src_object_id > 0) { - $object = fetchObjectByElement($ecmfile->src_object_id, $ecmfile->src_object_type); - if (is_object($object) && $object->id > 0) { - $entity = $object->entity; - } - } - + $entity = $ecmfile->entity; + if (isModEnabled('multicompany') && !empty($ecmfile->src_object_type) && $ecmfile->src_object_id > 0) { + $object = fetchObjectByElement($ecmfile->src_object_id, $ecmfile->src_object_type); + if (is_object($object) && $object->id > 0) { + $entity = $object->entity; + } + } + if ($entity != $conf->entity) { $conf->entity = $entity; $conf->setValues($db);