diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php
index 6968b58dae1..9e828d2c0f6 100644
--- a/htdocs/fourn/commande/card.php
+++ b/htdocs/fourn/commande/card.php
@@ -1838,12 +1838,14 @@ if ($action == 'create') {
$langs->load('projects');
print '
| '.$langs->trans('Project').' | ';
- if ($socid > 0) { // external user
- $projSocFilter = $socid;
- } elseif ((int) $societe->id == 0 || getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS')) {
+ if (!empty($user->socid)) { // external user: restrict to their own third party
+ $projSocFilter = $user->socid;
+ } elseif (getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') || $socid == 0) {
+ // Give priority to the constant (as on supplier invoice), so a supplier document created from a
+ // customer project keeps that project selected after the supplier is chosen.
$projSocFilter = -1;
} else {
- $projSocFilter = $societe->id;
+ $projSocFilter = $socid;
}
print img_picto('', 'project', 'class="pictofixedwidth"').$formproject->select_projects($projSocFilter, $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500');
print ' id) ? '&socid='.$societe->id : "")).'">';
diff --git a/htdocs/supplier_proposal/card.php b/htdocs/supplier_proposal/card.php
index 87ef8242cd5..c0229678110 100644
--- a/htdocs/supplier_proposal/card.php
+++ b/htdocs/supplier_proposal/card.php
@@ -1439,12 +1439,14 @@ if ($action == 'create') {
print ' |
';
print '| '.$langs->trans("Project").' | ';
- if ($socid > 0) { // external user
- $projSocFilter = $socid;
- } elseif ((int) $soc->id == 0 || getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS')) {
+ if (!empty($user->socid)) { // external user: restrict to their own third party
+ $projSocFilter = $user->socid;
+ } elseif (getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') || $socid == 0) {
+ // Give priority to the constant (as on supplier invoice), so a supplier document created from a
+ // customer project keeps that project selected after the supplier is chosen.
$projSocFilter = -1;
} else {
- $projSocFilter = $soc->id;
+ $projSocFilter = $socid;
}
print img_picto('', 'project', 'class="pictofixedwidth"').$formproject->select_projects($projSocFilter, $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500');
print ' id).'">';
|