Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 376cac9b

Von Bernd Bleßmann vor mehr als 1 Jahr hinzugefügt

  • ID 376cac9b5dc18aed8d814570771ba23b5248812d
  • Vorgänger 5835a85f
  • Nachfolger 41cff96b

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
  # link records
1625 1595
  if ($::form->{converted_from_oe_id}) {
1626 1596
    my @converted_from_oe_ids = split ' ', $::form->{converted_from_oe_id};
......
1639 1609
    );
1640 1610
  }
1641 1611

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

  
1650
      die $::locale->text('The form is not valid anymore.') if !$validity_token;
1651
    }
1652

  
1653
    # delete custom shipto if it is to be deleted or if it is empty
1654
    if ($self->order->custom_shipto && ($self->is_custom_shipto_to_delete || $self->order->custom_shipto->is_empty)) {
1655
      $self->order->custom_shipto->delete if $self->order->custom_shipto->shipto_id;
1656
      $self->order->custom_shipto(undef);
1657
    }
1658

  
1659
    SL::DB::DeliveryOrderItem->new(id => $_)->delete for @{$self->item_ids_to_delete || []};
1660
    $self->order->save(cascade => 1);
1612
  my $items_to_delete  = scalar @{ $self->item_ids_to_delete || [] }
1613
                       ? SL::DB::Manager::DeliveryOrderItem->get_all(where => [id => $self->item_ids_to_delete])
1614
                       : undef;
1661 1615

  
1662
    $self->save_history('SAVED');
1663

  
1664
    $validity_token->delete if $validity_token;
1665
    delete $::form->{form_validity_token};
1666

  
1667
    1;
1668
  }) || push(@{$errors}, $db->error);
1616
  SL::Model::Record->save($self->order,
1617
                          with_validity_token        => { scope => SL::DB::ValidityToken::SCOPE_DELIVERY_ORDER_SAVE(), token => $::form->{form_validity_token} },
1618
                          delete_custom_shipto       => $self->is_custom_shipto_to_delete || $self->order->custom_shipto->is_empty,
1619
                          items_to_delete            => $items_to_delete,
1620
  );
1669 1621

  
1670
  return $errors;
1622
  delete $::form->{form_validity_token};
1671 1623
}
1672 1624

  
1673 1625
sub workflow_sales_or_request_for_quotation {
1674 1626
  my ($self) = @_;
1675 1627

  
1676 1628
  # always save
1677
  my $errors = $self->save();
1678

  
1679
  if (scalar @{ $errors }) {
1680
    $self->js->flash('error', $_) for @{ $errors };
1681
    return $self->js->render();
1682
  }
1629
  $self->save();
1683 1630

  
1684 1631
  my $destination_type = $self->type_data->workflow("to_quotation_type");
1685 1632

  
......
1717 1664
  my ($self) = @_;
1718 1665

  
1719 1666
  # always save
1720
  my $errors = $self->save();
1721

  
1722
  if (scalar @{ $errors }) {
1723
    $self->js->flash('error', $_) foreach @{ $errors };
1724
    return $self->js->render();
1725
  }
1667
  $self->save();
1726 1668

  
1727 1669
  my $destination_type = $self->type_data->workflow("to_order_type");
1728 1670

  
......
2176 2118
sub save_and_redirect_to {
2177 2119
  my ($self, %params) = @_;
2178 2120

  
2179
  my $errors = $self->save();
2180

  
2181
  if (scalar @{ $errors }) {
2182
    $self->js->flash('error', $_) foreach @{ $errors };
2183
    return $self->js->render();
2184
  }
2121
  $self->save();
2185 2122

  
2186 2123
  flash_later('info', $self->type_data->text("saved"));
2187 2124

  

Auch abrufbar als: Unified diff