Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 91f4c662

Von Tamino Steinert vor etwa 1 Jahr hinzugefügt

  • ID 91f4c6629f354bafaa20fba5dd634b72bc2fddf6
  • Vorgänger 73b236a9
  • Nachfolger 49dd3021

Model::Record: update_for_save_as_new implementiert

Unterschiede anzeigen:

SL/Controller/Order.pm
287 287
    return $self->js->render();
288 288
  }
289 289

  
290
  # load order from db to check if values changed
291 290
  my $saved_order = SL::DB::Order->new(id => $order->id)->load;
292 291

  
293
  my %new_attrs;
294
  # Lets assign a new number if the user hasn't changed the previous one.
295
  # If it has been changed manually then use it as-is.
296
  $new_attrs{number}    = (trim($order->number) eq $saved_order->number)
297
                        ? ''
298
                        : trim($order->number);
299

  
300
  # Clear transdate unless changed
301
  $new_attrs{transdate} = ($order->transdate == $saved_order->transdate)
302
                        ? DateTime->today_local
303
                        : $order->transdate;
304

  
305
  # Set new reqdate unless changed if it is enabled in client config
306
  if ($order->reqdate == $saved_order->reqdate) {
307
    my $extra_days = $self->type eq sales_quotation_type()    ? $::instance_conf->get_reqdate_interval       :
308
                     $self->type eq sales_order_type()        ? $::instance_conf->get_delivery_date_interval :
309
                     $self->type eq sales_order_intake_type() ? $::instance_conf->get_delivery_date_interval : 1;
310

  
311
    if (   ($self->type eq sales_order_intake_type() &&  !$::instance_conf->get_deliverydate_on)
312
        || ($self->type eq sales_order_type()        &&  !$::instance_conf->get_deliverydate_on)
313
        || ($self->type eq sales_quotation_type()    &&  !$::instance_conf->get_reqdate_on)) {
314
      $new_attrs{reqdate} = '';
315
    } else {
316
      $new_attrs{reqdate} = DateTime->today_local->next_workday(extra_days => $extra_days);
317
    }
318
  } else {
319
    $new_attrs{reqdate} = $order->reqdate;
320
  }
321

  
322
  # Update employee
323
  $new_attrs{employee}  = SL::DB::Manager::Employee->current;
324

  
325
  # Warn on obsolete items
326
  my @obsolete_positions = map { $_->position } grep { $_->part->obsolete } @{ $order->items_sorted };
327
  flash_later('warning', t8('This record containts obsolete items at position #1', join ', ', @obsolete_positions)) if @obsolete_positions;
328

  
329 292
  # Create new record from current one
330
  $self->order(SL::DB::Order->new_from($order, destination_type => $order->type, attributes => \%new_attrs));
293
  my $updated_order = SL::Model::Record->update_for_save_as_new($saved_order, $order);
294

  
295
  $self->order($updated_order);
331 296

  
332 297
  # no linked records on save as new
333 298
  delete $::form->{$_} for qw(converted_from_oe_id converted_from_orderitems_ids);
334 299

  
300
  # Warn on obsolete items
301
  my @obsolete_positions = map { $_->position } grep { $_->part->obsolete } @{ $self->order->items_sorted };
302
  flash_later('warning', t8('This record containts obsolete items at position #1', join ', ', @obsolete_positions)) if @obsolete_positions;
303

  
335 304
  if (!$::form->{form_validity_token}) {
336 305
    $::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_ORDER_SAVE())->token;
337 306
  }

Auch abrufbar als: Unified diff