Skip to content
Open

FIX #67

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.


## Release 1.5
- FIX : Fix the linked object "thirdparty" so that it appears in the file to be attached to invoices.
- FIX : DA027218 - Fixing hooks for Agefodd compatibility - *24/10/2025* - 1.5.7
- FIX DA026978 : Attachments of third party not available even when conf `ATTACHMENTS_INCLUDE_OBJECT_LINKED` was enabled - *29/08/2025* - 1.5.6
- FIX : Warning Constant INC_FROM_DOLIBARR already defined - *18/08/2025* - 1.5.5
Expand Down
2 changes: 1 addition & 1 deletion admin/attachments_setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
// Example with a yes / no select
setup_print_on_off('ATTACHMENTS_INCLUDE_PRODUCT_LINES');
setup_print_on_off('ATTACHMENTS_INCLUDE_OBJECT_LINKED');

setup_print_on_off('ATTACHMENTS_INCLUDE_PROJECT_LINKED');
if (isModEnabled('ecm'))
{
$formecm=new FormEcm($db);
Expand Down
39 changes: 34 additions & 5 deletions class/actions_attachments.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* Class ActionsAttachments
*/
require_once __DIR__.'/../backport/v19/core/class/commonhookactions.class.php';
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
class ActionsAttachments extends \attachments\RetroCompatCommonHookActions
{
/**
Expand Down Expand Up @@ -55,7 +56,8 @@ class ActionsAttachments extends \attachments\RetroCompatCommonHookActions
, 'AttachmentsTitleFactureFournisseur' => 35
, 'AttachmentsTitleFicheInter' => 40
, 'AttachmentsSociete' => 50
, 'AttachmentsTitleTask' =>60
, 'AttachmentsTitleProject' => 55
, 'AttachmentsTitleTask' => 60
, 'AttachmentsTitleEcm' => 500
);

Expand All @@ -71,6 +73,7 @@ class ActionsAttachments extends \attachments\RetroCompatCommonHookActions
, 'fichinter' => 'AttachmentsTitleFicheInter'
, 'societe' => 'AttachmentsSociete'
, 'ecm' => 'AttachmentsTitleEcm'
, 'project' => 'AttachmentsTitleProject'
, 'project_task' => 'AttachmentsTitleTask'
, 'shipping' => 'AttachmentsShipping'
);
Expand Down Expand Up @@ -127,12 +130,37 @@ function doActions($parameters, &$object, &$action, $hookmanager)

$this->current_object = $object;
if (getDolGlobalString('ATTACHMENTS_INCLUDE_OBJECT_LINKED')) {
if (getDolGlobalString('ATTACHMENTS_INCLUDE_PROJECT_LINKED') && !empty($this->current_object->fk_project)) {
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'element_element (fk_source, sourcetype, fk_target, targettype) VALUES ('.$this->current_object->id.', "'.$this->current_object->element.'", '.$this->current_object->fk_project.', "project")';
$resql = $this->db->query($sql);
$this->db->free($resql);
}
$this->current_object->fetchObjectLinked();
if(!empty($this->current_object->fk_soc)) $fk_soc = $this->current_object->fk_soc ?? 0;
else $fk_soc = $this->current_object->socid ?? 0;
$this->current_object->linkedObjects['societe'][$fk_soc] = $this->current_object->thirdparty;
if (getDolGlobalString('ATTACHMENTS_INCLUDE_PROJECT_LINKED') && !empty($this->current_object->fk_project)) {
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'element_element WHERE fk_source = '.$this->current_object->id.' AND sourcetype LIKE "'.$this->current_object->element.'" AND fk_target = '.$this->current_object->fk_project.' AND targettype LIKE "project"';
$resql = $this->db->query($sql);
$this->db->free($resql);
}
// Ajout du tiers systématiquement (pas seulement si ATTACHMENTS_INCLUDE_OBJECT_LINKED)
if(!empty($this->current_object->fk_soc)) {
$fk_soc = $this->current_object->fk_soc ?? 0;
} else {
$fk_soc = $this->current_object->socid ?? 0;
}
if ($fk_soc > 0) {
// Charger le tiers s'il n'est pas déjà chargé
if (empty($this->current_object->thirdparty)) {
$societe = new Societe($this->db);
if($societe->fetch($fk_soc) > 0) {
$this->current_object->thirdparty = $societe;
}
}
// Ajouter le tiers dans les objets liés
if (!empty($this->current_object->thirdparty)) {
$this->current_object->linkedObjects['societe'][$fk_soc] = $this->current_object->thirdparty;
}
}
}

if (empty($this->current_object->linkedObjects[$this->current_object->element])) $this->current_object->linkedObjects[$this->current_object->element] = array();
array_unshift($this->current_object->linkedObjects[$this->current_object->element], $this->current_object);

Expand Down Expand Up @@ -195,6 +223,7 @@ function doActions($parameters, &$object, &$action, $hookmanager)
$sub_element_to_use = '';
$subdir = '';
if ($element === 'fichinter') $element_to_use = 'ficheinter';
elseif ($element === 'project') $element_to_use = 'projet';
elseif ($element === 'order_supplier') { $element_to_use = 'fournisseur'; $subdir = '/commande'; }
elseif ($element === 'invoice_supplier') { $element_to_use = 'fournisseur'; $sub_element_to_use = 'facture'; /* $subdir is defined in the next loop */ }
elseif ($element === 'shipping') {$element_to_use = 'expedition'; $subdir = '/sending';}
Expand Down
2 changes: 2 additions & 0 deletions langs/en_US/attachments.lang
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ AbricotNeedUpdate = The 'Abricot' module need to be update
# SETUP
ATTACHMENTS_INCLUDE_PRODUCT_LINES = Search files related to products /services of the current document
ATTACHMENTS_INCLUDE_OBJECT_LINKED = Search files related to the linked objects of the current document
ATTACHMENTS_INCLUDE_PROJECT_LINKED = Search files related to the linked project of the current document (requires activation of previous option)
ATTACHMENTS_ECM_SCANDIR = Search files in the following folder

# FORMCONFIRM
Expand All @@ -29,6 +30,7 @@ AttachmentsTitleFicheInter = Intervention
AttachmentsSociete = Company
AttachmentsTitleEcm = Documents (EDM)
AttachmentsShipping = Shipping
AttachmentsTitleProject = Project
AttachmentsTitleTask = Task

AttachmentsFiltered = Elements corresponding to your search term
Expand Down
2 changes: 2 additions & 0 deletions langs/fr_FR/attachments.lang
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ AbricotNeedUpdate=Le module abricot doit être mis à jour
# SETUP
ATTACHMENTS_INCLUDE_PRODUCT_LINES=Activer la recherche dans les fichiers provenant des produits/services du document courant
ATTACHMENTS_INCLUDE_OBJECT_LINKED=Activer la recherche dans les fichiers provenant des éléments liés au document courant
ATTACHMENTS_INCLUDE_PROJECT_LINKED=Activer la recherche dans les fichiers provenant du projet lié au document courant (nécessite l'activation de l'option précédente)
ATTACHMENTS_ECM_SCANDIR=Activer la recherche dans le répertoire suivant

# FORMCONFIRM
Expand All @@ -27,6 +28,7 @@ AttachmentsTitleFactureFournisseur=Facture fournisseur
AttachmentsTitleFicheInter=Intervention
AttachmentsSociete=Société
AttachmentsTitleEcm=Documents (GED)
AttachmentsTitleProject=Projet
AttachmentsTitleTask=Tâches
AttachmentsShipping=Expedition

Expand Down