Revision a3e18a2a
Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt
SL/Controller/Order.pm | ||
---|---|---|
273 | 273 |
return $self->js->render(); |
274 | 274 |
} |
275 | 275 |
|
276 |
# load order from db to check if values changed |
|
277 | 276 |
my $saved_order = SL::DB::Order->new(id => $order->id)->load; |
278 | 277 |
|
279 |
my %new_attrs; |
|
280 |
# Lets assign a new number if the user hasn't changed the previous one. |
|
281 |
# If it has been changed manually then use it as-is. |
|
282 |
$new_attrs{number} = (trim($order->number) eq $saved_order->number) |
|
283 |
? '' |
|
284 |
: trim($order->number); |
|
285 |
|
|
286 |
# Clear transdate unless changed |
|
287 |
$new_attrs{transdate} = ($order->transdate == $saved_order->transdate) |
|
288 |
? DateTime->today_local |
|
289 |
: $order->transdate; |
|
290 |
|
|
291 |
# Set new reqdate unless changed if it is enabled in client config |
|
292 |
if ($order->reqdate == $saved_order->reqdate) { |
|
293 |
my $extra_days = $self->type eq sales_quotation_type() ? $::instance_conf->get_reqdate_interval : |
|
294 |
$self->type eq sales_order_type() ? $::instance_conf->get_delivery_date_interval : 1; |
|
295 |
|
|
296 |
if ( ($self->type eq sales_order_type() && !$::instance_conf->get_deliverydate_on) |
|
297 |
|| ($self->type eq sales_quotation_type() && !$::instance_conf->get_reqdate_on)) { |
|
298 |
$new_attrs{reqdate} = ''; |
|
299 |
} else { |
|
300 |
$new_attrs{reqdate} = DateTime->today_local->next_workday(extra_days => $extra_days); |
|
301 |
} |
|
302 |
} else { |
|
303 |
$new_attrs{reqdate} = $order->reqdate; |
|
304 |
} |
|
305 |
|
|
306 |
# Update employee |
|
307 |
$new_attrs{employee} = SL::DB::Manager::Employee->current; |
|
308 |
|
|
309 |
# Warn on obsolete items |
|
310 |
my @obsolete_positions = map { $_->position } grep { $_->part->obsolete } @{ $order->items_sorted }; |
|
311 |
flash_later('warning', t8('This record containts obsolete items at position #1', join ', ', @obsolete_positions)) if @obsolete_positions; |
|
312 |
|
|
313 | 278 |
# Create new record from current one |
314 |
$self->order(SL::DB::Order->new_from($order, destination_type => $order->type, attributes => \%new_attrs)); |
|
279 |
my $updated_order = SL::Model::Record->update_for_save_as_new($saved_order, $order); |
|
280 |
|
|
281 |
$self->order($updated_order); |
|
315 | 282 |
|
316 | 283 |
# no linked records on save as new |
317 | 284 |
delete $::form->{$_} for qw(converted_from_oe_id converted_from_orderitems_ids); |
318 | 285 |
|
286 |
# Warn on obsolete items |
|
287 |
my @obsolete_positions = map { $_->position } grep { $_->part->obsolete } @{ $self->order->items_sorted }; |
|
288 |
flash_later('warning', t8('This record containts obsolete items at position #1', join ', ', @obsolete_positions)) if @obsolete_positions; |
|
289 |
|
|
319 | 290 |
if (!$::form->{form_validity_token}) { |
320 | 291 |
$::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_ORDER_SAVE())->token; |
321 | 292 |
} |
Auch abrufbar als: Unified diff
Model::Record: update_for_save_as_new implementiert