Revision 89a2d4f1
Von Bernd Bleßmann vor mehr als 6 Jahren hinzugefügt
SL/Controller/Order.pm | ||
---|---|---|
137 | 137 |
sub action_save_as_new { |
138 | 138 |
my ($self) = @_; |
139 | 139 |
|
140 |
if (!$self->order->id) { |
|
140 |
my $order = $self->order; |
|
141 |
|
|
142 |
if (!$order->id) { |
|
141 | 143 |
$self->js->flash('error', t8('This object has not been saved yet.')); |
142 | 144 |
return $self->js->render(); |
143 | 145 |
} |
144 | 146 |
|
145 |
delete $::form->{$_} for qw(closed delivered converted_from_oe_id converted_from_orderitems_ids); |
|
146 |
|
|
147 |
my $src_order = SL::DB::Order->new(id => $self->order->id)->load; |
|
147 |
# load order from db to check if values changed |
|
148 |
my $saved_order = SL::DB::Order->new(id => $order->id)->load; |
|
148 | 149 |
|
150 |
my %new_attrs; |
|
149 | 151 |
# Lets assign a new number if the user hasn't changed the previous one. |
150 | 152 |
# If it has been changed manually then use it as-is. |
151 |
if (trim($self->order->number) eq $src_order->number) {
|
|
152 |
$self->order->number('');
|
|
153 |
}
|
|
153 |
$new_attrs{number} = (trim($order->number) eq $saved_order->number)
|
|
154 |
? ''
|
|
155 |
: trim($order->number);
|
|
154 | 156 |
|
155 |
# Clear reqdate and transdate unless changed |
|
156 |
if ($self->order->transdate == $src_order->transdate) { |
|
157 |
$self->order->transdate(DateTime->today_local) |
|
158 |
} |
|
159 |
if ($self->order->reqdate == $src_order->reqdate) { |
|
157 |
# Clear transdate unless changed |
|
158 |
$new_attrs{transdate} = ($order->transdate == $saved_order->transdate) |
|
159 |
? DateTime->today_local |
|
160 |
: $order->transdate; |
|
161 |
|
|
162 |
# Set new reqdate unless changed |
|
163 |
if ($order->reqdate == $saved_order->reqdate) { |
|
160 | 164 |
my $extra_days = $self->type eq _sales_quotation_type() ? $::instance_conf->get_reqdate_interval : 1; |
161 |
$self->order->reqdate(DateTime->today_local->next_workday(extra_days => $extra_days)); |
|
165 |
$new_attrs{reqdate} = DateTime->today_local->next_workday(extra_days => $extra_days); |
|
166 |
} else { |
|
167 |
$new_attrs{reqdate} = $order->reqdate; |
|
162 | 168 |
} |
163 | 169 |
|
164 | 170 |
# Update employee |
165 |
$self->order->employee(SL::DB::Manager::Employee->current); |
|
171 |
$new_attrs{employee} = SL::DB::Manager::Employee->current; |
|
172 |
|
|
173 |
# Create new record from current one |
|
174 |
$self->order(SL::DB::Order->new_from($order, destination_type => $order->type, attributes => \%new_attrs)); |
|
175 |
|
|
176 |
# no linked records on save as new |
|
177 |
delete $::form->{$_} for qw(converted_from_oe_id converted_from_orderitems_ids); |
|
166 | 178 |
|
167 | 179 |
# save |
168 | 180 |
$self->action_save(); |
Auch abrufbar als: Unified diff
Auftrags-Controller: bei als neu speichern auch ein neues Objekt erzeugen
Behebt #351 (redmine).