Test: Im OrderController Sortimentsartikel auspacken
[kivitendo-erp.git] / SL / Controller / Order.pm
index a32581d..5af72f5 100644 (file)
@@ -93,7 +93,7 @@ sub action_delete {
 
   flash_later('info', $::locale->text('The order has been deleted'));
   my @redirect_params = (
-    action => 'edit',
+    action => 'add',
     type   => $self->type,
   );
 
@@ -401,6 +401,7 @@ sub action_add_item {
   return unless $form_attr->{parts_id};
 
   my $item = _new_item($self->order, $form_attr);
+
   $self->order->add_items($item);
 
   $self->_recalc();
@@ -413,7 +414,31 @@ sub action_add_item {
   );
 
   $self->js
-    ->append('#row_table_id', $row_as_html)
+    ->append('#row_table_id', $row_as_html);
+
+  if ( $item->part->is_assortment ) {
+    $form_attr->{qty_as_number} = 1 unless $form_attr->{qty_as_number};
+    foreach my $assortment_item ( @{$item->part->assortment_items} ) {
+      my $attr = { parts_id => $assortment_item->parts_id,
+                   qty      => $assortment_item->qty * $::form->parse_amount(\%::myconfig, $form_attr->{qty_as_number}), # TODO $form_attr->{unit}
+                   unit     => $assortment_item->unit,
+                   description => $assortment_item->part->description,
+                 };
+      my $item = _new_item($self->order, $attr);
+      $self->order->add_items( $item );
+      $self->_recalc();
+      my $item_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
+      my $row_as_html = $self->p->render('order/tabs/_row',
+                                         ITEM              => $item,
+                                         ID                => $item_id,
+                                         ALL_PRICE_FACTORS => $self->all_price_factors
+      );
+      $self->js
+        ->append('#row_table_id', $row_as_html);
+    };
+  };
+
+  $self->js
     ->val('.add_item_input', '')
     ->run('kivi.Order.init_row_handlers')
     ->run('kivi.Order.row_table_scroll_down')
@@ -783,6 +808,8 @@ sub _make_item {
 
   $item->assign_attributes(%$attr);
   $item->longdescription($item->part->notes) if $is_new && !defined $attr->{longdescription};
+  # item fields that currently can't be set in in row but are needed:
+  $item->lastcost($item->part->lastcost) if $is_new;
 
   return $item;
 }
@@ -891,9 +918,9 @@ sub _delete {
   my ($self) = @_;
 
   my $errors = [];
-  my $db = $self->order->db;
+  my $db     = $self->order->db;
 
-  $db->do_transaction(
+  $db->with_transaction(
     sub {
       my @spoolfiles = grep { $_ } map { $_->spoolfile } @{ SL::DB::Manager::Status->get_all(where => [ trans_id => $self->order->id ]) };
       $self->order->delete;
@@ -913,12 +940,11 @@ sub _save {
   my ($self) = @_;
 
   my $errors = [];
-  my $db = $self->order->db;
+  my $db     = $self->order->db;
 
-  $db->do_transaction(
-    sub {
-      SL::DB::OrderItem->new(id => $_)->delete for @{$self->item_ids_to_delete};
-      $self->order->save(cascade => 1);
+  $db->with_transaction(sub {
+    SL::DB::OrderItem->new(id => $_)->delete for @{$self->item_ids_to_delete};
+    $self->order->save(cascade => 1);
   }) || push(@{$errors}, $db->error);
 
   return $errors;
@@ -1204,10 +1230,6 @@ java script functions
 
 =item *
 
-C<position> is not displayed until an order is saved
-
-=item *
-
 Customer discount is not displayed as a valid discount in price source popup
 (this might be a bug in price sources)
 
@@ -1236,9 +1258,22 @@ Table header is not sticky in the scrolling area.
 
 Sorting does not include C<position>, neither does reordering.
 
+This behavior was implemented intentionally. But we can discuss, which behavior
+should be implemented.
+
 =item *
 
-C<show_smulti_items_dialog> does not use the currently inserted string for filtering.
+C<show_multi_items_dialog> does not use the currently inserted string for
+filtering.
+
+=item * Performance
+
+Rendering a 50 items order takes twice as long as the old code.
+
+90% of that is rendering the (hidden) second rows, and 50% of those again are
+checks for is_valid and C<INCLUDE> on the cvar input template.
+
+Suggestion: fetch second rows when asked for.
 
 =back