Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 89ea5dd6

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

  • ID 89ea5dd69dcc263f6400216298949f447a1a2a12
  • Vorgänger d88e956e
  • Nachfolger a3e18a2a

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

Unterschiede anzeigen:

SL/Controller/Order.pm
18 18
use SL::DB::AuthUser;
19 19
use SL::DB::History;
20 20
use SL::DB::Order;
21
use SL::DB::OrderItem;
21 22
use SL::DB::Default;
22 23
use SL::DB::Unit;
23 24
use SL::DB::Part;
......
217 218
sub action_save {
218 219
  my ($self) = @_;
219 220

  
220
  my $errors = $self->save();
221

  
222
  if (scalar @{ $errors }) {
223
    $self->js->flash('error', $_) foreach @{ $errors };
224
    return $self->js->render();
225
  }
221
  $self->save();
226 222

  
227 223
  my $text = $self->type eq sales_order_type()       ? $::locale->text('The order has been saved')
228 224
           : $self->type eq purchase_order_type()    ? $::locale->text('The order has been saved')
......
255 251
  SL::DB->client->with_transaction(
256 252
    sub {
257 253
      SL::Model::Record->increment_subversion($self->order);
258

  
259
      # Todo: Call SL::Model::Record->save when implemented
260
      # SL::Model::Record->save($self->order);
261
      my $errors = $self->save();
262
      die join "\n", @{ $errors } if scalar @{ $errors };
263

  
254
      $self->save();
264 255
      1;
265 256
    }
266 257
  );
......
341 332
sub action_print {
342 333
  my ($self) = @_;
343 334

  
344
  my $errors = $self->save();
345

  
346
  if (scalar @{ $errors }) {
347
    $self->js->flash('error', $_) foreach @{ $errors };
348
    return $self->js->render();
349
  }
335
  $self->save();
350 336

  
351 337
  $self->js_reset_order_and_item_ids_after_save;
352 338

  
......
430 416
sub action_preview_pdf {
431 417
  my ($self) = @_;
432 418

  
433
  my $errors = $self->save();
434
  if (scalar @{ $errors }) {
435
    $self->js->flash('error', $_) foreach @{ $errors };
436
    return $self->js->render();
437
  }
419
  $self->save();
438 420

  
439 421
  $self->js_reset_order_and_item_ids_after_save;
440 422

  
......
489 471
  my ($self) = @_;
490 472

  
491 473
  if (!$self->is_final_version) {
492
    my $errors = $self->save();
493

  
494
    if (scalar @{ $errors }) {
495
      $self->js->flash('error', $_) foreach @{ $errors };
496
      return $self->js->render();
497
    }
474
    $self->save();
498 475

  
499 476
    $self->js_reset_order_and_item_ids_after_save;
500 477
  }
......
559 536
  my ($self) = @_;
560 537

  
561 538
  if (!$self->is_final_version) {
562
    my $errors = $self->save();
563

  
564
    if (scalar @{ $errors }) {
539
    eval {
540
      $self->save();
541
      1;
542
    } or do {
565 543
      $self->js->run('kivi.Order.close_email_dialog');
566
      $self->js->flash('error', $_) foreach @{ $errors };
567
      return $self->js->render();
568
    }
544
      die $EVAL_ERROR;
545
    };
569 546

  
570 547
    $self->js_reset_order_and_item_ids_after_save;
571 548
  }
......
840 817
sub action_save_and_reclamation {
841 818
  my ($self) = @_;
842 819

  
843
  # cann't use save_and_redirect_to, because id is set!
844
  my $errors = $self->save();
845
  if (scalar @{ $errors }) {
846
    $self->js->flash('error', $_) foreach @{ $errors };
847
    return $self->js->render();
848
  }
820
  # can't use save_and_redirect_to, because id is set!
821
  $self->save();
849 822

  
850 823
  my $to_type = $self->order->is_sales ? 'sales_reclamation'
851 824
                                       : 'purchase_reclamation';
......
2101 2074
sub save {
2102 2075
  my ($self) = @_;
2103 2076

  
2104
  $self->recalc();
2105
  $self->get_unalterable_data();
2106

  
2107
  my $errors = [];
2108
  my $db     = $self->order->db;
2109

  
2110 2077
  # check for new or updated phone note
2111 2078
  if ($::form->{phone_note}->{subject} || $::form->{phone_note}->{body}) {
2112 2079
    if (!$::form->{phone_note}->{subject} || !$::form->{phone_note}->{body}) {
......
2130 2097
    $self->order->add_phone_notes($phone_note) if $is_new;
2131 2098
  }
2132 2099

  
2100
  # create first version if none exists
2101
  $self->order->add_order_version(SL::DB::OrderVersion->new(version => 1)) if !$self->order->order_version;
2102

  
2133 2103
  my @converted_from_oe_ids;
2134 2104
  if ($::form->{converted_from_oe_id}) {
2135 2105
    @converted_from_oe_ids = split ' ', $::form->{converted_from_oe_id};
......
2148 2118
    );
2149 2119
  }
2150 2120

  
2151
  $db->with_transaction(sub {
2152
    my $validity_token;
2153
    if (!$self->order->id) {
2154
      $validity_token = SL::DB::Manager::ValidityToken->fetch_valid_token(
2155
        scope => SL::DB::ValidityToken::SCOPE_ORDER_SAVE(),
2156
        token => $::form->{form_validity_token},
2157
      );
2158

  
2159
      die $::locale->text('The form is not valid anymore.') if !$validity_token;
2160
    }
2161

  
2162
    # delete custom shipto if it is to be deleted or if it is empty
2163
    if ($self->order->custom_shipto && ($self->is_custom_shipto_to_delete || $self->order->custom_shipto->is_empty)) {
2164
      $self->order->custom_shipto->delete if $self->order->custom_shipto->shipto_id;
2165
      $self->order->custom_shipto(undef);
2166
    }
2167

  
2168
    SL::DB::OrderItem->new(id => $_)->delete for @{$self->item_ids_to_delete || []};
2169
    $self->order->save(cascade => 1);
2170
    # create first version if none exists
2171
    SL::DB::OrderVersion->new(oe_id => $self->order->id, version => 1)->save unless scalar @{ $self->order->order_version };
2121
  my $items_to_delete = scalar @{ $self->item_ids_to_delete || [] }
2122
                      ? SL::DB::Manager::OrderItem->get_all(where => [id => $self->item_ids_to_delete])
2123
                      : undef;
2172 2124

  
2173
    # link records
2174
    if (@converted_from_oe_ids) {
2175
      $self->link_requirement_specs_linking_to_created_from_objects(@converted_from_oe_ids);
2176
    }
2177

  
2178
    $self->set_project_in_linked_requirement_specs if $self->order->globalproject_id;
2179

  
2180
    $self->save_history('SAVED');
2181

  
2182
    $validity_token->delete if $validity_token;
2183
    delete $::form->{form_validity_token};
2184

  
2185
    1;
2186
  }) || push(@{$errors}, $db->error);
2125
  SL::Model::Record->save($self->order,
2126
                          with_validity_token  => { scope => SL::DB::ValidityToken::SCOPE_ORDER_SAVE(), token => $::form->{form_validity_token} },
2127
                          delete_custom_shipto => $self->is_custom_shipto_to_delete || $self->order->custom_shipto->is_empty,
2128
                          items_to_delete      => $items_to_delete,
2129
                          history              => { snumbers => $self->get_history_snumbers() },
2130
  );
2187 2131

  
2188
  return $errors;
2132
  delete $::form->{form_validity_token};
2189 2133
}
2190 2134

  
2191 2135
sub pre_render {
......
2770 2714
sub save_and_redirect_to {
2771 2715
  my ($self, %params) = @_;
2772 2716

  
2773
  my $errors = $self->save();
2774

  
2775
  if (scalar @{ $errors }) {
2776
    $self->js->flash('error', $_) foreach @{ $errors };
2777
    return $self->js->render();
2778
  }
2717
  $self->save();
2779 2718

  
2780 2719
  my $text = $self->type eq sales_order_type()       ? $::locale->text('The order has been saved')
2781 2720
           : $self->type eq purchase_order_type()    ? $::locale->text('The order has been saved')

Auch abrufbar als: Unified diff