commit 5b1b4713203066a12db13731db6eebabcc85df13
Author: Tamino Steinert <tamino.steinert@tamino.st>
Date:   Thu Sep 28 16:21:47 2023 +0200

    Model::Record: FIX: Workflow mit ausgewählten Positionen

diff --git a/SL/Controller/DeliveryOrder.pm b/SL/Controller/DeliveryOrder.pm
index 5a17de9ea..ceaeb44b5 100644
--- a/SL/Controller/DeliveryOrder.pm
+++ b/SL/Controller/DeliveryOrder.pm
@@ -123,7 +123,7 @@ sub action_add_from_record {
     my %use_item = map { $_ => 1 } @{$::form->{from_item_ids}};
     $flags{item_filter} = sub {
       my ($item) = @_;
-      return %use_item{$item->id};
+      return %use_item{$item->{RECORD_ITEM_ID()}};
     }
   }
 
@@ -533,13 +533,15 @@ sub action_save_and_new_record {
   my $to_type = $::form->{to_type};
   my $to_controller = get_object_name_from_type($to_type);
 
+  $self->save();
+
   my %additional_params = ();
-  if ($::form->{only_selected_items}) {
-    my $from_item_ids = $::form->{selected_items} || [];
-    $additional_params{from_item_ids} = $from_item_ids;
+  if ($::form->{only_selected_item_positions}) { # ids can be unset before save
+    my $item_positions = $::form->{selected_item_positions} || [];
+    my @from_item_ids = map { $self->order->items_sorted->[$_]->id } @$item_positions;
+    $additional_params{from_item_ids} = \@from_item_ids;
   }
 
-  $self->save();
   flash_later('info', $self->type_data->text('saved'));
 
   $self->redirect_to(
diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm
index 1b98aea3f..68b11a608 100644
--- a/SL/Controller/Order.pm
+++ b/SL/Controller/Order.pm
@@ -111,7 +111,7 @@ sub action_add_from_record {
     my %use_item = map { $_ => 1 } @{$::form->{from_item_ids}};
     $flags{item_filter} = sub {
       my ($item) = @_;
-      return %use_item{$item->id};
+      return %use_item{$item->{RECORD_ITEM_ID()}};
     }
   }
 
@@ -786,9 +786,10 @@ sub action_save_and_new_record {
   flash_later('info', $self->type_data->text('saved'));
 
   my %additional_params = ();
-  if ($::form->{only_selected_items}) {
-    my $from_item_ids = $::form->{selected_items} || [];
-    $additional_params{from_item_ids} = $from_item_ids;
+  if ($::form->{only_selected_item_positions}) { # ids can be unset before save
+    my $item_positions = $::form->{selected_item_positions} || [];
+    my @from_item_ids = map { $self->order->items_sorted->[$_]->id } @$item_positions;
+    $additional_params{from_item_ids} = \@from_item_ids;
   }
 
   $self->redirect_to(
diff --git a/SL/Controller/Reclamation.pm b/SL/Controller/Reclamation.pm
index 85a774bfb..1f7d5ad84 100644
--- a/SL/Controller/Reclamation.pm
+++ b/SL/Controller/Reclamation.pm
@@ -125,7 +125,7 @@ sub action_add_from_record {
     my %use_item = map { $_ => 1 } @{$::form->{from_item_ids}};
     $flags{item_filter} = sub {
       my ($item) = @_;
-      return %use_item{$item->id};
+      return %use_item{$item->{RECORD_ITEM_ID()}};
     }
   }
 
@@ -513,15 +513,16 @@ sub action_save_and_new_record {
   my $to_type = $::form->{to_type};
   my $to_controller = get_object_name_from_type($to_type);
 
-  my %additional_params = ();
-  if ($::form->{only_selected_items}) {
-    my $from_item_ids = $::form->{selected_items} || [];
-    $additional_params{from_item_ids} = $from_item_ids;
-  }
-
   $self->save();
   flash_later('info', t8('The reclamation has been saved'));
 
+  my %additional_params = ();
+  if ($::form->{only_selected_item_positions}) { # ids can be unset before save
+    my $item_positions = $::form->{selected_item_positions} || [];
+    my @from_item_ids = map { $self->order->items_sorted->[$_]->id } @$item_positions;
+    $additional_params{from_item_ids} = \@from_item_ids;
+  }
+
   $self->redirect_to(
     controller => $to_controller,
     action     => 'add_from_record',
diff --git a/js/kivi.Order.js b/js/kivi.Order.js
index 70aec8fe8..91b39a8ac 100644
--- a/js/kivi.Order.js
+++ b/js/kivi.Order.js
@@ -970,25 +970,25 @@ namespace('kivi.Order', function(ns) {
     data.push({ name: 'action', value: 'Order/show_conversion_to_purchase_delivery_order_item_selection' });
 
     kivi.popup_dialog({
-      id:     "convert_to_purchase_delivery_order_item_selection",
+      id:     "convert_to_purchase_delivery_order_item_position_selection",
       url:    "controller.pl",
       data:   data,
       type:   "POST",
       dialog: { title: kivi.t8("Select items for delivery order") },
       load:   function() {
-        $("body").data("convert_to_purchase_delivery_order_item_selection_params", params);
+        $("body").data("convert_to_purchase_delivery_order_item_position_selection_params", params);
       }
     });
   };
 
   ns.convert_to_purchase_delivery_order_item_selection = function() {
-    let params = $("body").data("convert_to_purchase_delivery_order_item_selection_params");
+    let params = $("body").data("convert_to_purchase_delivery_order_item_position_selection_params");
 
-    let $dialog = $("#convert_to_purchase_delivery_order_item_selection");
-    let selected_items = $dialog.find("tbody input.item_selection_checkall").serializeArray();
+    let $dialog = $("#convert_to_purchase_delivery_order_item_position_selection");
+    let selected_items = $dialog.find("tbody input.item_position_selection_checkall").serializeArray();
     params.data = selected_items;
 
-    additional_param = { name: 'only_selected_items', value: 1 };
+    additional_param = { name: 'only_selected_item_positions', value: 1 };
     if (params.form_params) {
       if (Array.isArray(params.form_params)) {
         params.form_params.push(additional_param);
diff --git a/templates/design40_webpages/order/tabs/_purchase_delivery_order_item_selection.html b/templates/design40_webpages/order/tabs/_purchase_delivery_order_item_selection.html
index 5d3e710aa..1a3897df6 100644
--- a/templates/design40_webpages/order/tabs/_purchase_delivery_order_item_selection.html
+++ b/templates/design40_webpages/order/tabs/_purchase_delivery_order_item_selection.html
@@ -7,7 +7,7 @@
   <table class="tbl-list">
     <thead>
       <tr class="listheading">
-        <th>[% L.checkbox_tag("item_selection_checkall", checkall="input.item_selection_checkall") %]</th>
+        <th>[% L.checkbox_tag("item_position_selection_checkall", checkall="input.item_position_selection_checkall") %]</th>
         <th>[% LxERP.t8("Position") %]</th>
         <th>[% LxERP.t8("Partnumber") %]</th>
         <th>[% LxERP.t8("Vendor Part Number") %]</th>
@@ -17,10 +17,10 @@
       </tr>
     </thead>
 
-    <tbody id="item_selection" class="row_entry listrow">
+    <tbody id="item_position_selection" class="row_entry listrow">
       [% FOREACH item = ITEMS %]
         <tr class="listrow">
-          <td>[% L.checkbox_tag("selected_items[+]", class="item_selection_checkall", value=item.id, checked="checked") %]</td>
+          <td>[% L.checkbox_tag("selected_item_positions[+]", class="item_position_selection_checkall", value=loop.count, checked="checked") %]</td>
           <td class="numeric">[% loop.count %]</td>
           <td>[% HTML.escape(item.partnumber) %]</td>
           <td>[% HTML.escape(item.vendor_partnumber) %]</td>
diff --git a/templates/webpages/order/tabs/_purchase_delivery_order_item_selection.html b/templates/webpages/order/tabs/_purchase_delivery_order_item_selection.html
index 6eea23638..1ec9a99ec 100644
--- a/templates/webpages/order/tabs/_purchase_delivery_order_item_selection.html
+++ b/templates/webpages/order/tabs/_purchase_delivery_order_item_selection.html
@@ -7,7 +7,7 @@
   <table>
     <thead>
       <tr class="listheading">
-        <th>[% L.checkbox_tag("item_selection_checkall", checkall="input.item_selection_checkall") %]</th>
+        <th>[% L.checkbox_tag("item_position_selection_checkall", checkall="input.item_position_selection_checkall") %]</th>
         <th>[% LxERP.t8("Position") %]</th>
         <th>[% LxERP.t8("Partnumber") %]</th>
         <th>[% LxERP.t8("Vendor Part Number") %]</th>
@@ -17,10 +17,10 @@
       </tr>
     </thead>
 
-    <tbody id="item_selection" class="row_entry listrow">
+    <tbody id="item_position_selection" class="row_entry listrow">
       [% FOREACH item = ITEMS %]
         <tr class="listrow">
-          <td>[% L.checkbox_tag("selected_items[+]", class="item_selection_checkall", value=item.id, checked="checked") %]</td>
+          <td>[% L.checkbox_tag("selected_item_positions[+]", class="item_position_selection_checkall", value=loop.count, checked="checked") %]</td>
           <td align="right">[% loop.count %]</td>
           <td>[% HTML.escape(item.partnumber) %]</td>
           <td>[% HTML.escape(item.vendor_partnumber) %]</td>
