Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision ce46ead5

Von Bernd Bleßmann vor etwa 1 Jahr hinzugefügt

  • ID ce46ead573609064a2ace7285506731ec1a72652
  • Vorgänger c1a6f892
  • Nachfolger b5b93806

DeliveryOrder-Controller: Model::Record->save verwenden

Unterschiede anzeigen:

SL/Controller/DeliveryOrder.pm
35 35
use SL::DB::Helper::TypeDataProxy;
36 36
use SL::DB::DeliveryOrder;
37 37
use SL::DB::DeliveryOrder::TypeData qw(:types);
38
use SL::DB::Manager::DeliveryOrderItem;
38 39
use SL::DB::DeliveryOrderItemsStock;
39 40
use SL::Model::Record;
40 41

  
......
208 209
sub action_save {
209 210
  my ($self) = @_;
210 211

  
211
  my $errors = $self->save();
212

  
213
  if (scalar @{ $errors }) {
214
    $self->js->flash('error', $_) foreach @{ $errors };
215
    return $self->js->render();
216
  }
212
  $self->save();
217 213

  
218 214
  flash_later('info', $self->type_data->text("saved"));
219 215

  
......
263 259
  my ($self) = @_;
264 260

  
265 261
  if ( !$self->order->delivered ) {
266
    my $errors = $self->save();
267

  
268
    if (scalar @{ $errors }) {
269
      $self->js->flash('error', $_) foreach @{ $errors };
270
      return $self->js->render();
271
    }
272

  
262
    $self->save();
273 263
    $self->js_reset_order_and_item_ids_after_save;
274 264
  }
275 265

  
......
346 336
  my ($self) = @_;
347 337

  
348 338
  if ( !$self->order->delivered ) {
349
    my $errors = $self->save();
350
    if (scalar @{ $errors }) {
351
      $self->js->flash('error', $_) foreach @{ $errors };
352
      return $self->js->render();
353
    }
354

  
339
    $self->save();
355 340
    $self->js_reset_order_and_item_ids_after_save;
356 341
  }
357 342

  
......
393 378
  my ($self) = @_;
394 379

  
395 380
  if ( !$self->order->delivered ) {
396
    my $errors = $self->save();
397

  
398
    if (scalar @{ $errors }) {
399
      $self->js->flash('error', $_) foreach @{ $errors };
400
      return $self->js->render();
401
    }
381
    $self->save();
402 382
  }
403 383

  
404 384
  my $cv_method = $self->cv;
......
453 433
  my ($self) = @_;
454 434

  
455 435
  if ( !$self->order->delivered ) {
456
    my $errors = $self->save();
457

  
458
    if (scalar @{ $errors }) {
459
      $self->js->run('kivi.DeliveryOrder.close_email_dialog');
460
      $self->js->flash('error', $_) foreach @{ $errors };
461
      return $self->js->render();
462
    }
436
    $self->save();
463 437
    $self->js_reset_order_and_item_ids_after_save;
464 438
  }
465 439

  
466

  
467 440
  my $email_form  = delete $::form->{email_form};
468 441
  my %field_names = (to => 'email');
469 442

  
......
1618 1591
sub save {
1619 1592
  my ($self) = @_;
1620 1593

  
1621
  my $errors = [];
1622
  my $db     = $self->order->db;
1623

  
1624 1594
  if (scalar @{$self->order->items} == 0 && !grep { $self->type eq $_ } @{$::instance_conf->get_allowed_documents_with_no_positions() || []}) {
1625 1595
    return [t8('The action you\'ve chosen has not been executed because the document does not contain any item yet.')];
1626 1596
  }
......
1643 1613
    );
1644 1614
  }
1645 1615

  
1646
  $db->with_transaction(sub {
1647
    my $validity_token;
1648
    if (!$self->order->id) {
1649
      $validity_token = SL::DB::Manager::ValidityToken->fetch_valid_token(
1650
        scope => SL::DB::ValidityToken::SCOPE_DELIVERY_ORDER_SAVE(),
1651
        token => $::form->{form_validity_token},
1652
      );
1653

  
1654
      die $::locale->text('The form is not valid anymore.') if !$validity_token;
1655
    }
1656

  
1657
    # delete custom shipto if it is to be deleted or if it is empty
1658
    if ($self->order->custom_shipto && ($self->is_custom_shipto_to_delete || $self->order->custom_shipto->is_empty)) {
1659
      $self->order->custom_shipto->delete if $self->order->custom_shipto->shipto_id;
1660
      $self->order->custom_shipto(undef);
1661
    }
1662

  
1663
    SL::DB::DeliveryOrderItem->new(id => $_)->delete for @{$self->item_ids_to_delete || []};
1664
    $self->order->save(cascade => 1);
1616
  my $items_to_delete  = scalar @{ $self->item_ids_to_delete || [] }
1617
                       ? SL::DB::Manager::DeliveryOrderItem->get_all(where => [id => $self->item_ids_to_delete])
1618
                       : undef;
1665 1619

  
1666
    $self->save_history('SAVED');
1667

  
1668
    $validity_token->delete if $validity_token;
1669
    delete $::form->{form_validity_token};
1670

  
1671
    1;
1672
  }) || push(@{$errors}, $db->error);
1620
  SL::Model::Record->save($self->order,
1621
                          with_validity_token        => { scope => SL::DB::ValidityToken::SCOPE_DELIVERY_ORDER_SAVE(), token => $::form->{form_validity_token} },
1622
                          delete_custom_shipto       => $self->is_custom_shipto_to_delete || $self->order->custom_shipto->is_empty,
1623
                          items_to_delete            => $items_to_delete,
1624
  );
1673 1625

  
1674
  return $errors;
1626
  delete $::form->{form_validity_token};
1675 1627
}
1676 1628

  
1677 1629
sub workflow_sales_or_request_for_quotation {
1678 1630
  my ($self) = @_;
1679 1631

  
1680 1632
  # always save
1681
  my $errors = $self->save();
1682

  
1683
  if (scalar @{ $errors }) {
1684
    $self->js->flash('error', $_) for @{ $errors };
1685
    return $self->js->render();
1686
  }
1633
  $self->save();
1687 1634

  
1688 1635
  my $destination_type = $self->type_data->workflow("to_quotation_type");
1689 1636

  
......
1721 1668
  my ($self) = @_;
1722 1669

  
1723 1670
  # always save
1724
  my $errors = $self->save();
1725

  
1726
  if (scalar @{ $errors }) {
1727
    $self->js->flash('error', $_) foreach @{ $errors };
1728
    return $self->js->render();
1729
  }
1671
  $self->save();
1730 1672

  
1731 1673
  my $destination_type = $self->type_data->workflow("to_order_type");
1732 1674

  
......
2180 2122
sub save_and_redirect_to {
2181 2123
  my ($self, %params) = @_;
2182 2124

  
2183
  my $errors = $self->save();
2184

  
2185
  if (scalar @{ $errors }) {
2186
    $self->js->flash('error', $_) foreach @{ $errors };
2187
    return $self->js->render();
2188
  }
2125
  $self->save();
2189 2126

  
2190 2127
  flash_later('info', $self->type_data->text("saved"));
2191 2128

  

Auch abrufbar als: Unified diff