Revision d2fdb900
Von Tamino Steinert vor etwa 1 Jahr hinzugefügt
SL/Controller/DeliveryOrder.pm | ||
---|---|---|
13 | 13 |
use SL::Webdav; |
14 | 14 |
use SL::File; |
15 | 15 |
use SL::MIME; |
16 |
use SL::Util qw(trim); |
|
17 | 16 |
use SL::YAML; |
18 | 17 |
use SL::DB::History; |
19 | 18 |
use SL::DB::Order; |
... | ... | |
240 | 239 |
return $self->js->render(); |
241 | 240 |
} |
242 | 241 |
|
243 |
# load order from db to check if values changed |
|
244 | 242 |
my $saved_order = SL::DB::DeliveryOrder->new(id => $order->id)->load; |
245 | 243 |
|
246 |
my %new_attrs; |
|
247 |
# Lets assign a new number if the user hasn't changed the previous one. |
|
248 |
# If it has been changed manually then use it as-is. |
|
249 |
$new_attrs{number} = (trim($order->number) eq $saved_order->number) |
|
250 |
? '' |
|
251 |
: trim($order->number); |
|
252 |
|
|
253 |
# Clear transdate unless changed |
|
254 |
$new_attrs{transdate} = ($order->transdate == $saved_order->transdate) |
|
255 |
? DateTime->today_local |
|
256 |
: $order->transdate; |
|
257 |
|
|
258 |
# Set new reqdate unless changed if it is enabled in client config |
|
259 |
$new_attrs{reqdate} = $self->type_data->get_reqdate_by_type($order->reqdate, $saved_order->reqdate); |
|
260 |
|
|
261 |
# Update employee |
|
262 |
$new_attrs{employee} = SL::DB::Manager::Employee->current; |
|
263 |
|
|
264 | 244 |
# Create new record from current one |
265 |
$self->order(SL::DB::DeliveryOrder->new_from($order, destination_type => $order->type, attributes => \%new_attrs)); |
|
245 |
my $updated_order = SL::Model::Record->update_for_save_as_new($saved_order, $order); |
|
246 |
|
|
247 |
$self->order($updated_order); |
|
266 | 248 |
|
267 | 249 |
# no linked records on save as new |
268 | 250 |
delete $::form->{$_} for qw(converted_from_oe_id converted_from_orderitems_ids); |
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 |
} |
SL/Controller/Reclamation.pm | ||
---|---|---|
14 | 14 |
use SL::Webdav; |
15 | 15 |
use SL::File; |
16 | 16 |
use SL::MIME; |
17 |
use SL::Util qw(trim); |
|
18 | 17 |
use SL::YAML; |
19 | 18 |
use SL::DB::History; |
20 | 19 |
use SL::DB::Reclamation; |
... | ... | |
311 | 310 |
return $self->js->render(); |
312 | 311 |
} |
313 | 312 |
|
314 |
# load reclamation from db to check if values changed |
|
315 | 313 |
my $saved_reclamation = SL::DB::Reclamation->new(id => $reclamation->id)->load; |
316 | 314 |
|
317 |
my %new_attrs; |
|
318 |
# If it has been changed manually then use it as-is, otherwise change. |
|
319 |
$new_attrs{record_number} = (trim($reclamation->record_number) eq $saved_reclamation->record_number) |
|
320 |
? '' |
|
321 |
: trim($reclamation->record_number); |
|
322 |
$new_attrs{transdate} = ($reclamation->transdate == $saved_reclamation->transdate) |
|
323 |
? DateTime->today_local |
|
324 |
: $reclamation->transdate; |
|
325 |
if ($reclamation->reqdate == $saved_reclamation->reqdate) { |
|
326 |
$new_attrs{reqdate} = ''; |
|
327 |
} else { |
|
328 |
$new_attrs{reqdate} = $reclamation->reqdate; |
|
329 |
} |
|
330 |
|
|
331 |
# Update employee |
|
332 |
$new_attrs{employee} = SL::DB::Manager::Employee->current; |
|
333 |
|
|
334 | 315 |
# Create new record from current one |
335 |
$self->reclamation( |
|
336 |
SL::DB::Reclamation->new_from( |
|
337 |
$reclamation, |
|
338 |
destination_type => $reclamation->type, |
|
339 |
attributes => \%new_attrs, |
|
340 |
no_linked_records => 1, |
|
341 |
) |
|
342 |
); |
|
316 |
my $new_reclamation = SL::Model::Record->update_for_save_as_new($saved_reclamation, $reclamation); |
|
317 |
$self->reclamation($new_reclamation); |
|
343 | 318 |
|
344 | 319 |
if (!$::form->{form_validity_token}) { |
345 | 320 |
$::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE())->token; |
SL/DB/Reclamation.pm | ||
---|---|---|
281 | 281 |
closed => 0, |
282 | 282 |
delivered => 0, |
283 | 283 |
transdate => DateTime->today_local, |
284 |
reqdate => DateTime->today_local->next_workday(), |
|
285 | 284 |
); |
286 | 285 |
if ( $is_abbr_any->(qw(srsr prpr srpr prsr)) ) { #Reclamation |
287 | 286 |
map { $record_args{$_} = $source->$_ } # {{{ for vim folds |
... | ... | |
301 | 300 |
netamount |
302 | 301 |
notes |
303 | 302 |
payment_id |
303 |
reqdate |
|
304 | 304 |
salesman_id |
305 | 305 |
shippingpoint |
306 | 306 |
shipvia |
SL/Model/Record.pm | ||
---|---|---|
12 | 12 |
use SL::DB::Status; |
13 | 13 |
use SL::DB::ValidityToken; |
14 | 14 |
|
15 |
use SL::Util qw(trim); |
|
15 | 16 |
use SL::Locale::String qw(t8); |
16 | 17 |
|
17 | 18 |
sub new { |
... | ... | |
240 | 241 |
} |
241 | 242 |
|
242 | 243 |
sub update_for_save_as_new { |
243 |
my ($class, $record, %params) = @_; |
|
244 |
my ($class, $saved_record, $changed_record, %params) = @_;
|
|
244 | 245 |
|
245 | 246 |
# der übergebene beleg wurde mit new_from erstellt und muss nachbearbeitet werden: |
246 | 247 |
# - transadte, reqdate müssen überschrieben werden |
247 | 248 |
# - number muss überschrieben werden |
248 | 249 |
# - employee auf aktuellen setzen |
249 | 250 |
|
251 |
my $type_info = { |
|
252 |
# order |
|
253 |
sales_quotation => { |
|
254 |
get_new_reqdate => sub { |
|
255 |
if ($::instance_conf->get_reqdate_on) { |
|
256 |
return ''; |
|
257 |
} else { |
|
258 |
return DateTime->today_local->next_workday( |
|
259 |
extra_days => $::instance_conf->get_reqdate_interval()); |
|
260 |
} |
|
261 |
}, |
|
262 |
}, |
|
263 |
sales_order => { |
|
264 |
get_new_reqdate => sub { |
|
265 |
if ($::instance_conf->get_deliverydate_on) { |
|
266 |
return ''; |
|
267 |
} else { |
|
268 |
return DateTime->today_local->next_workday( |
|
269 |
extra_days => $::instance_conf->get_delivery_date_interval()); |
|
270 |
} |
|
271 |
}, |
|
272 |
}, |
|
273 |
request_quotation => { |
|
274 |
get_new_reqdate => sub { DateTime->today_local->next_workday(extra_days => 1); }, |
|
275 |
}, |
|
276 |
purchase_order => { |
|
277 |
get_new_reqdate => sub { DateTime->today_local->next_workday(extra_days => 1); }, |
|
278 |
}, |
|
279 |
# delivery_order |
|
280 |
rma_delivery_order => { |
|
281 |
get_new_reqdate => sub { |
|
282 |
DateTime->today_local->next_workday(extra_days => 1); |
|
283 |
}, |
|
284 |
}, |
|
285 |
sales_delivery_order => { |
|
286 |
get_new_reqdate => sub { |
|
287 |
DateTime->today_local->next_workday(extra_days => 1); |
|
288 |
}, |
|
289 |
}, |
|
290 |
supplier_delivery_order => { |
|
291 |
get_new_reqdate => sub { |
|
292 |
DateTime->today_local->next_workday(extra_days => 1); |
|
293 |
}, |
|
294 |
}, |
|
295 |
purchase_delivery_order => { |
|
296 |
get_new_reqdate => sub { |
|
297 |
DateTime->today_local->next_workday(extra_days => 1); |
|
298 |
}, |
|
299 |
}, |
|
300 |
# reclamation |
|
301 |
sales_reclamation => { |
|
302 |
get_new_reqdate => sub { |
|
303 |
''; |
|
304 |
}, |
|
305 |
}, |
|
306 |
purchase_reclamation => { |
|
307 |
get_new_reqdate => sub { |
|
308 |
''; |
|
309 |
}, |
|
310 |
}, |
|
311 |
}; |
|
312 |
|
|
313 |
# changed_record |
|
314 |
my %new_attrs; |
|
315 |
# Lets assign a new number if the user hasn't changed the previous one. |
|
316 |
# If it has been changed manually then use it as-is. |
|
317 |
$new_attrs{number} = (trim($changed_record->number) eq $saved_record->number) |
|
318 |
? '' |
|
319 |
: trim($changed_record->number); |
|
320 |
|
|
321 |
# Clear transdate unless changed |
|
322 |
$new_attrs{transdate} = ($changed_record->transdate == $saved_record->transdate) |
|
323 |
? DateTime->today_local |
|
324 |
: $changed_record->transdate; |
|
325 |
|
|
326 |
# Set new reqdate unless changed if it is enabled in client config |
|
327 |
if ($changed_record->reqdate == $saved_record->reqdate) { |
|
328 |
$new_attrs{reqdate} = $type_info->{$saved_record->type}->{get_new_reqdate}->(); |
|
329 |
} |
|
330 |
|
|
331 |
# Update employee |
|
332 |
$new_attrs{employee} = SL::DB::Manager::Employee->current; |
|
333 |
|
|
334 |
|
|
335 |
my $new_record = SL::Model::Record->new_from_workflow($changed_record, $saved_record->type, no_linked_records => 1, attributes => \%new_attrs); |
|
336 |
|
|
250 | 337 |
# return: nichts |
251 | 338 |
# fehler: exception |
339 |
return $new_record; |
|
252 | 340 |
} |
253 | 341 |
|
254 | 342 |
|
... | ... | |
292 | 380 |
=head1 AUTHORS |
293 | 381 |
|
294 | 382 |
Bernd Bleßmann E<lt>bernd@kivitendo-premium.deE<gt> |
383 |
Tamino Steinert E<lt>tamino.steinert@tamino.stE<gt> |
|
295 | 384 |
... |
296 | 385 |
|
297 | 386 |
=cut |
Auch abrufbar als: Unified diff
Model::Record: update_for_save_as_new implementiert