From: Bernd Bleßmann Date: Tue, 3 Apr 2018 12:05:46 +0000 (+0200) Subject: Auftrags-Controller: bei als neu speichern auch ein neues Objekt erzeugen X-Git-Tag: release-3.5.4~438 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=89a2d4f109e72abfd5d9423e2cb4d61e5193ad08;p=kivitendo-erp.git Auftrags-Controller: bei als neu speichern auch ein neues Objekt erzeugen Behebt #351 (redmine). --- diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index b3477b2e3..36896ee11 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -137,32 +137,44 @@ sub action_save { sub action_save_as_new { my ($self) = @_; - if (!$self->order->id) { + my $order = $self->order; + + if (!$order->id) { $self->js->flash('error', t8('This object has not been saved yet.')); return $self->js->render(); } - delete $::form->{$_} for qw(closed delivered converted_from_oe_id converted_from_orderitems_ids); - - my $src_order = SL::DB::Order->new(id => $self->order->id)->load; + # load order from db to check if values changed + my $saved_order = SL::DB::Order->new(id => $order->id)->load; + my %new_attrs; # Lets assign a new number if the user hasn't changed the previous one. # If it has been changed manually then use it as-is. - if (trim($self->order->number) eq $src_order->number) { - $self->order->number(''); - } + $new_attrs{number} = (trim($order->number) eq $saved_order->number) + ? '' + : trim($order->number); - # Clear reqdate and transdate unless changed - if ($self->order->transdate == $src_order->transdate) { - $self->order->transdate(DateTime->today_local) - } - if ($self->order->reqdate == $src_order->reqdate) { + # Clear transdate unless changed + $new_attrs{transdate} = ($order->transdate == $saved_order->transdate) + ? DateTime->today_local + : $order->transdate; + + # Set new reqdate unless changed + if ($order->reqdate == $saved_order->reqdate) { my $extra_days = $self->type eq _sales_quotation_type() ? $::instance_conf->get_reqdate_interval : 1; - $self->order->reqdate(DateTime->today_local->next_workday(extra_days => $extra_days)); + $new_attrs{reqdate} = DateTime->today_local->next_workday(extra_days => $extra_days); + } else { + $new_attrs{reqdate} = $order->reqdate; } # Update employee - $self->order->employee(SL::DB::Manager::Employee->current); + $new_attrs{employee} = SL::DB::Manager::Employee->current; + + # Create new record from current one + $self->order(SL::DB::Order->new_from($order, destination_type => $order->type, attributes => \%new_attrs)); + + # no linked records on save as new + delete $::form->{$_} for qw(converted_from_oe_id converted_from_orderitems_ids); # save $self->action_save();