Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 0f4eba94

Von Kivitendo Admin vor fast 8 Jahren hinzugefügt

  • ID 0f4eba94fd6bed67f55c9f019a7aa08166974b1f
  • Vorgänger 78740728
  • Nachfolger ad872b5a

CSV Auftragsimport - Auftrag als fehlerhaft markieren

wenn es fehlerhafte Positionen gibt.

Unterschiede anzeigen:

SL/Controller/CsvImport/Order.pm
279 279
  $self->handle_prices_and_taxes();
280 280

  
281 281

  
282
  # If order has errors set error for orderitems as well
283
  # If one of the orderitems has an error, set an error for the order
284
  # This algorithm only works for one order per csv file!
285
  my $order_entry;
282
  # If the order has errors set an error for the orderitems as well.
283
  # If one of the orderitems has an error, set an error for the order.
284
  # Now only orders without errors are imported, but if there are several
285
  # orders, some with errors, some without, then only those without errors are
286
  # imported. Maybe it would be better to block the whole CSV file?
287

  
288
  my $last_order_entry;
286 289
  my $item_column_errors;
287 290
  foreach my $entry (@{ $self->controller->data }) {
288 291
    # Search first order
289 292
    if ($entry->{raw_data}->{datatype} eq $self->_order_column) {
290
      $order_entry = $entry;
291
    } elsif ( defined $order_entry
293
      if ( $item_column_errors && $last_order_entry ) {
294
        push @{ $last_order_entry->{errors} }, $::locale->text('Error: there are errors with #1 items', $item_column_errors);
295
      };
296
      $item_column_errors = 0; # reset for each order if there are several orders in csv file
297
      $last_order_entry = $entry;
298
    } elsif ( defined $last_order_entry
292 299
              && $entry->{raw_data}->{datatype} eq $self->_item_column
293
              && scalar @{ $order_entry->{errors} } > 0 ) {
300
              && scalar @{ $last_order_entry->{errors} } > 0 ) {
294 301
      push @{ $entry->{errors} }, $::locale->text('Error: Invalid order for this order item');
295 302
      $item_column_errors++;
296
    } elsif ( defined $order_entry
303
    } elsif ( defined $last_order_entry
297 304
              && $entry->{raw_data}->{datatype} eq $self->_item_column
298 305
              && scalar @{ $entry->{errors} } > 0 ) {
299 306
      $item_column_errors++;
300 307
    };
301 308
  }
309
  # when loop ends, run error check for the final order (or the first, if there is only one)
302 310
  if ( $item_column_errors ) {
303
    push @{ $order_entry->{errors} }, $::locale->text('Error: there are errors with #1 items', $item_column_errors);
311
    push @{ $last_order_entry->{errors} }, $::locale->text('Error: there are errors with #1 items', $item_column_errors);
304 312
  };
305 313
}
306 314

  

Auch abrufbar als: Unified diff