Skip to content

Commit 33d87cc

Browse files
authored
Fix(Order): handle multigroup assign (#545)
* Fix(Order): handle multigroup assign * fix * adapt changelog
1 parent f1b6643 commit 33d87cc

4 files changed

Lines changed: 49 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
## [UNRELEASED]
99

1010
- Fix SQL query error when displaying deliveries
11+
- Fix error during generate associated material action
1112

1213
## [2.12.5] - 2026-01-08
1314

ajax/linkactions.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,22 @@
9595
break;
9696

9797
case "show_group_by_entity":
98+
99+
if (isset($_POST['multiple']) && $_POST['multiple']) {
100+
if (isset($_POST['value']) && !is_array($_POST['value'])) {
101+
$_POST['value'] = [$_POST['value']];
102+
}
103+
104+
if (!isset($_POST['value'])) {
105+
$_POST['value'] = [];
106+
}
107+
}
108+
98109
Group::dropdown(['name' => "id[" . $_POST['id'] . "][groups_id]",
99110
'entity' => $_POST['entities'],
100111
'value' => $_POST['value'] ?? 0,
101-
'condition' => ['is_assign' => 1],
112+
'condition' => ['is_itemgroup' => 1],
113+
'multiple' => $_POST['multiple'] ?? false,
102114
]);
103115

104116
if (isset($_POST['massaction'])) {

inc/link.class.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*/
3030

3131
use Glpi\Application\View\TemplateRenderer;
32+
use Glpi\Features\AssignableItem;
3233

3334
class PluginOrderLink extends CommonDBChild
3435
{
@@ -95,6 +96,7 @@ public function showItemGenerationForm($params)
9596
$i = 0;
9697
$item_rows = [];
9798
$found = false;
99+
$itemtype = '';
98100
$order_web_dir = $CFG_GLPI['root_doc'] . '/plugins/order';
99101

100102
foreach ($params["items"][self::class] as $key => $val) {
@@ -122,6 +124,7 @@ public function showItemGenerationForm($params)
122124
: $order->fields["entities_id"],
123125
'condition' => self::getCondition($itemtype),
124126
'itemtype' => $itemtype,
127+
'assignableitem' => false,
125128
];
126129

127130
if ($templateID) {
@@ -132,15 +135,20 @@ public function showItemGenerationForm($params)
132135
$row['otherserial'] = $item->fields["otherserial"] ?? "";
133136
$row['states_id'] = $item->fields["states_id"] ?? "";
134137
$row['locations_id'] = $item->fields["locations_id"] ?? "";
135-
$row['groups_id'] = $item->fields["groups_id"] ?? "";
138+
$row['groups_id'] = $item->fields["groups_id"] ?? [];
136139
$row['immo_number'] = $item->fields["immo_number"] ?? "";
137140
$row['template_name'] = $reference->getTemplateName($itemtype, $templateID);
141+
142+
if (Toolbox::hasTrait($itemtype, AssignableItem::class)) {
143+
$row['assignableitem'] = true;
144+
}
145+
138146
} else {
139147
$row['name'] = false;
140148
$row['otherserial'] = false;
141149
$row['states_id'] = false;
142150
$row['locations_id'] = false;
143-
$row['groups_id'] = false;
151+
$row['groups_id'] = [];
144152
$row['immo_number'] = false;
145153
$row['template_name'] = "";
146154
}
@@ -164,6 +172,7 @@ public function showItemGenerationForm($params)
164172
'active_entities' => $_SESSION['glpiactiveentities'] ?? [],
165173
'item_rows' => $item_rows,
166174
'order_web_dir' => $order_web_dir,
175+
'assignableitem' => Toolbox::hasTrait($itemtype, AssignableItem::class),
167176
]);
168177
return null;
169178
}

templates/generate_item.html.twig

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,20 @@
9999
</td>
100100
<td>
101101
<span id='show_group_by_entity_id_mass'>
102+
102103
{{ fields.dropdownField(
103104
'Group',
104-
"mass[groups_id]",
105-
0,
105+
"mass[groups_id]",
106+
assignableitem ? [] : 0,
106107
"",
107-
fields_option|merge({'on_change': 'plugin_order_setAllGroups(this.value)'})
108+
fields_option|merge({
109+
'entity': -1,
110+
'condition': {'is_itemgroup': 1},
111+
'multiple': assignableitem ? true : false,
112+
'on_change': 'plugin_order_setAllGroups(this)'
113+
})
108114
) }}
115+
109116
</span>
110117
</td>
111118
<td>
@@ -233,7 +240,11 @@
233240
"id[" ~ item.i ~ "][groups_id]",
234241
item.groups_id,
235242
"",
236-
fields_option
243+
fields_option|merge({
244+
'entity': -1,
245+
'condition': {'is_itemgroup': 1},
246+
'multiple': item.assignableitem ? true : false
247+
})
237248
) }}
238249
</span>
239250
</td>
@@ -279,6 +290,7 @@
279290
data: {
280291
'entities': value,
281292
'action': 'show_group_by_entity',
293+
'multiple': {{ assignableitem ? 'true' : 'false' }},
282294
'id': id
283295
},
284296
success: function(response) {
@@ -344,7 +356,12 @@
344356
}
345357
}
346358
347-
function plugin_order_setAllGroups(value) {
359+
function plugin_order_setAllGroups(dom_select) {
360+
361+
const values = Array.from(dom_select.selectedOptions).map(
362+
option => option.value
363+
);
364+
348365
var elements = document.querySelectorAll('[id^="show_group_by"]');
349366
for (var i = 0; i < elements.length; i++) {
350367
(function(index) {
@@ -355,7 +372,8 @@
355372
'entities': 0,
356373
'action': 'show_group_by_entity',
357374
'id': index,
358-
'value': value
375+
'value': values,
376+
'multiple': {{ assignableitem ? 'true' : 'false' }}
359377
},
360378
success: function(response) {
361379
$('#show_group_by_entity_id_' + index).html(response);

0 commit comments

Comments
 (0)