Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision d0082be1

Von Tamino Steinert vor etwa 1 Monat hinzugefügt

  • ID d0082be1ceb2be20a6020431f862f68e1182d7c9
  • Vorgänger 53a98e07
  • Nachfolger 44f8c46b

FIX: S:C:Reclamation: Daten über Workflows vollständig und korrekt laden

Helferfunktion für Neuinitialisierung nach Änderung des
Reklamations-Objektes angepasst und überall eingesetzt

Unterschiede anzeigen:

SL/Controller/Reclamation.pm
91 91
sub action_add {
92 92
  my ($self) = @_;
93 93

  
94
  $self->reclamation(SL::Model::Record->update_after_new($self->reclamation));
95

  
96 94
  $self->pre_render();
97 95

  
98 96
  if (!$::form->{form_validity_token}) {
......
126 124
  my $record = SL::Model::Record->get_record($from_type, $from_id);
127 125
  my $reclamation = SL::Model::Record->new_from_workflow($record, $self->type, %flags);
128 126
  $self->reclamation($reclamation);
127
  $self->reinit_after_new_reclamation();
129 128

  
130 129
  if ($record->type eq SALES_RECLAMATION_TYPE()) { # check for direct delivery
131 130
    # copy shipto in custom shipto (custom shipto will be copied by new_from() in case)
......
138 137
    }
139 138
  }
140 139

  
141
  $self->reinit_after_new_reclamation();
142

  
143
  if (!$::form->{form_validity_token}) {
144
    $::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE())->token;
145
  }
146

  
147
  $self->render(
148
    'reclamation/form',
149
    title => $self->type_data->text('add'),
150
    %{$self->{template_args}},
151
  );
140
  $self->action_add;
152 141
}
153 142

  
154 143
sub action_add_from_email_journal {
......
171 160
# edit an existing reclamation
172 161
sub action_edit {
173 162
  my ($self) = @_;
163
  die "No 'id' was given." unless $::form->{id};
174 164

  
175
  unless ($::form->{id}) {
176
    $self->js->flash('error', t8("Can't edit unsaved reclamation. No 'id' was given."));
177
    return $self->js->render();
178
  }
165
  $self->load_reclamation();
179 166

  
180
  $self->load_reclamation;
181

  
182
  $self->recalc();
183 167
  $self->pre_render();
184

  
185 168
  $self->render(
186 169
    'reclamation/form',
187 170
    title => $self->type_data->text('edit'),
......
934 917
sub action_return_from_create_part {
935 918
  my ($self) = @_;
936 919

  
937
  $self->{created_part} = SL::DB::Part->new(id => delete $::form->{new_parts_id})->load if $::form->{new_parts_id};
920
  $self->{created_part} = SL::DB::Part->new(
921
    id => delete $::form->{new_parts_id}
922
  )->load if $::form->{new_parts_id};
938 923

  
939 924
  $::auth->restore_form_from_session(delete $::form->{previousform});
925
  $self->reclamation($self->init_reclamation);
926
  $self->reinit_after_new_reclamation();
940 927

  
941
  # set item ids to new fake id, to identify them as new items
942
  foreach my $item (@{$self->reclamation->items_sorted}) {
943
    $item->{new_fake_id} = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
928
  if ($self->reclamation->id) {
929
    $self->action_edit;
930
  } else {
931
    $self->action_add;
944 932
  }
945

  
946
  $self->recalc();
947
  $self->get_unalterable_data();
948
  $self->pre_render();
949

  
950
  # trigger rendering values for second row/longdescription as hidden, because
951
  # they are loaded only on demand. So we need to keep the values from the
952
  # source.
953
  $_->{render_second_row}      = 1 for @{ $self->reclamation->items_sorted };
954
  $_->{render_longdescription} = 1 for @{ $self->reclamation->items_sorted };
955

  
956
  $self->render(
957
    'reclamation/form',
958
    title => $self->type_data->text('edit'),
959
    %{$self->{template_args}}
960
  );
961 933
}
962 934

  
963 935
# load the second row for one or more items
......
1349 1321
  $self->js->render;
1350 1322
}
1351 1323

  
1352
sub load_reclamation {
1353
  my ($self) = @_;
1354

  
1355
  return if !$::form->{id};
1356

  
1357
  $self->reclamation(SL::DB::Reclamation->new(id => $::form->{id})->load);
1358

  
1359
  # Add an empty custom shipto to the reclamation, so that the dialog can render
1360
  # the cvar inputs. You need a custom shipto object to call cvars_by_config to
1361
  # get the cvars.
1362
  if (!$self->reclamation->custom_shipto) {
1363
    $self->reclamation->custom_shipto(SL::DB::Shipto->new(module => 'RC', custom_variables => []));
1364
  }
1365

  
1366
  return $self->reclamation;
1367
}
1368

  
1369 1324
# load or create a new reclamation object
1370 1325
#
1371 1326
# And assign changes from the form to this object.
......
1387 1342
                     reclamation_items  => [],
1388 1343
                     currency_id => $::instance_conf->get_currency_id(),
1389 1344
                   );
1345
    $reclamation = SL::Model::Record->update_after_new($reclamation)
1390 1346
  }
1391 1347

  
1392 1348
  my $cv_id_method = $reclamation->type_data->properties('customervendor'). '_id';
......
1454 1410
  return $item;
1455 1411
}
1456 1412

  
1413
sub load_reclamation {
1414
  my ($self) = @_;
1415

  
1416
  return if !$::form->{id};
1417

  
1418
  $self->reclamation(SL::DB::Reclamation->new(id => $::form->{id})->load);
1419

  
1420
  $self->reinit_after_new_reclamation();
1421

  
1422
  return $self->reclamation;
1423
}
1424

  
1457 1425
# create a new item
1458 1426
#
1459 1427
# This is used to add one item
......
1602 1570
  my ($self) = @_;
1603 1571

  
1604 1572
  # change form type
1605
  $::form->{type} = $self->reclamation->type if $self->reclamation->type;
1573
  $::form->{type} = $self->reclamation->type;
1606 1574
  $self->type($self->init_type);
1607
  $self->cv  ($self->init_cv);
1575
  $self->type_data($self->init_type_data);
1576
  $self->cv($self->init_cv);
1608 1577
  $self->check_auth;
1609 1578

  
1610
  $self->recalc();
1611
  $self->get_unalterable_data();
1612
  $self->pre_render();
1579
  $self->setup_custom_shipto_from_form($self->reclamation, $::form);
1580

  
1581
  foreach my $item (@{$self->reclamation->items_sorted}) {
1582
    # set item ids to new fake id, to identify them as new items
1583
    $item->{new_fake_id} = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
1613 1584

  
1614
  # trigger rendering values for second row as hidden, because they
1615
  # are loaded only on demand. So we need to keep the values from the
1616
  # source.
1617
  $_->{render_second_row} = 1 for @{ $self->reclamation->items_sorted };
1585
    # trigger rendering values for second row as hidden, because they
1586
    # are loaded only on demand. So we need to keep the values from the
1587
    # source.
1588
    $item->{render_second_row} = 1;
1589
  }
1590

  
1591
  $self->get_unalterable_data();
1592
  $self->recalc();
1618 1593
}
1619 1594

  
1620 1595
sub pre_render {

Auch abrufbar als: Unified diff