Skip to content
Open
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [UNRELEASED]

### Fixed

- Fix `Take item delivery` and `Cancel reception` action for `Software License`

## [2.12.7] - 2026-06-03

### Fixed
Expand Down
93 changes: 87 additions & 6 deletions inc/link.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,10 @@ public static function processMassiveActionsForOneItemtype(
case 'generation':
$newIDs = $link->generateNewItem($ma->POST);
foreach ($ma->getItems()[self::class] as $key => $val) {
if (isset($newIDs[$key]) && $newIDs[$key]) {
$itemtype = $ma->POST['add_items'][$key]['itemtype'] ?? '';
if (in_array($itemtype, self::getTypesThanCannotBeGenerated())) {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
} elseif (isset($newIDs[$key]) && $newIDs[$key]) {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
Expand Down Expand Up @@ -676,14 +679,14 @@ public static function processMassiveActionsForOneItemtype(
case 'cancelReceipt':
foreach ($ma->getItems()[self::class] as $key => $val) {
$order_item = new PluginOrderOrder_Item();
$order_item->getFromDB($val);
$order_item->getFromDB($key);
if ($order_item->fields["items_id"] != 0) {
$ma->addMessage(__s("Unable to cancel reception when items are already linked, please unlink them before trying again.", "order"));
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
} elseif (!$link->cancelReception($key)) {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
} else {
$ma->itemDone($item->getType(), $val, MassiveAction::ACTION_OK);
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
}
}

Expand All @@ -698,10 +701,34 @@ public function cancelReception($id)
$order_item = new PluginOrderOrder_Item();
$order_item->getFromDB($id);

if ($order_item->fields['itemtype'] === 'SoftwareLicense') {
$iterator = $order_item->queryRef(
$order_item->fields['plugin_order_orders_id'],
$order_item->fields['plugin_order_references_id'],
$order_item->fields['price_taxfree'],
$order_item->fields['discount'],
PluginOrderOrder::ORDER_DEVICE_DELIVRED,
);
$success = true;
foreach ($iterator as $data) {
$success = $order_item->update([
'id' => $data['id'],
'states_id' => PluginOrderOrder::ORDER_DEVICE_NOT_DELIVRED,
'delivery_date' => null,
'delivery_number' => '',
'plugin_order_deliverystates_id' => 0,
]) && $success;
}

return $success;
}

return $order_item->update([
'id' => $id,
'states_id' => PluginOrderOrder::ORDER_DEVICE_NOT_DELIVRED,
'delivery_date' => null,
'id' => $id,
'states_id' => PluginOrderOrder::ORDER_DEVICE_NOT_DELIVRED,
'delivery_date' => null,
'delivery_number' => '',
'plugin_order_deliverystates_id' => 0,
]);
}

Expand Down Expand Up @@ -1129,6 +1156,10 @@ public function generateNewItem($params)
{
$newIDs = [];

if (empty($params["id"])) {
return $newIDs;
}

// Retrieve plugin configuration
$config = new PluginOrderConfig();
$reference = new PluginOrderReference();
Expand All @@ -1149,6 +1180,56 @@ public function generateNewItem($params)

//If itemtype cannot be generated, go to the new occurence
if (in_array($add_item['itemtype'], self::getTypesThanCannotBeGenerated())) {
if ($add_item['itemtype'] === 'SoftwareLicense') {
$entity = $values["entities_id"];
$templateID = $reference->checkIfTemplateExistsInEntity(
$values["id"],
'SoftwareLicense',
$entity,
);
$order = new PluginOrderOrder();
$order->getFromDB($params["plugin_order_orders_id"]);
$reference->getFromDB($add_item["plugin_order_references_id"]);

$lic = new SoftwareLicense();
$input = [];
if ($templateID) {
$lic->getFromDB($templateID);
foreach ($lic->fields as $field_name => $field_val) {
if ($field_val !== '') {
$input[$field_name] = $field_val;
}
}
unset($input['id'], $input['is_template'], $input['template_name'], $input['date_mod'], $input['date_creation']);
$input['name'] = $lic->fields['name']
? autoName($lic->fields['name'], 'name', $templateID, 'SoftwareLicense', $entity)
: $values['name'];
} else {
$input['name'] = $values['name'];
}
$input['entities_id'] = $entity;
$input['number'] = 0;

$newID = $lic->add($input);
if ($newID) {
$newIDs[$values["id"]] = $newID;
$this->createLinkWithItem(
$values["id"],
$newID,
'SoftwareLicense',
$params["plugin_order_orders_id"],
$entity,
$templateID,
false,
false,
);
$new_value = __s("Item generated by using order", "order") . ' : ' . $order->fields["name"];
$order->addHistory('SoftwareLicense', '', $new_value, $newID);
$new_value = __s("Item generated by using order", "order") . ' : '
. $lic->getTypeName() . ' -> ' . $lic->getField("name");
$order->addHistory('PluginOrderOrder', '', $new_value, $params["plugin_order_orders_id"]);
}
}
continue;
}

Expand Down
3 changes: 3 additions & 0 deletions inc/reception.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,9 @@ public function updateReceptionStatus($params)
$params2['POST']["plugin_order_deliverystates_id"],
);
$plugin_order_orders_id = $params2['POST']["plugin_order_orders_id"];
if ($ma !== false) {
$ma->itemDone(self::class, $key, MassiveAction::ACTION_OK);
}
} elseif ($detail->getFromDB($key)) {
if (!$plugin_order_orders_id) {
$plugin_order_orders_id = $detail->fields["plugin_order_orders_id"];
Expand Down
Loading