Revision e86dee01
Von Tamino Steinert vor mehr als 2 Jahren hinzugefügt
SL/DB/Order.pm | ||
---|---|---|
315 | 315 |
return $delivery_order; |
316 | 316 |
} |
317 | 317 |
|
318 |
sub convert_to_reclamation { |
|
319 |
my ($self, %params) = @_; |
|
320 |
$params{destination_type} = $self->is_sales ? 'sales_reclamation' |
|
321 |
: 'purchase_reclamation'; |
|
322 |
|
|
323 |
require SL::DB::Reclamation; |
|
324 |
my $reclamation = SL::DB::Reclamation->new_from($self, %params); |
|
325 |
|
|
326 |
return $reclamation; |
|
327 |
} |
|
328 |
|
|
318 | 329 |
sub _clone_orderitem_cvar { |
319 | 330 |
my ($cvar) = @_; |
320 | 331 |
|
... | ... | |
327 | 338 |
sub new_from { |
328 | 339 |
my ($class, $source, %params) = @_; |
329 | 340 |
|
330 |
croak("Unsupported source object type '" . ref($source) . "'") unless ref($source) eq 'SL::DB::Order'; |
|
341 |
unless (any {ref($source) eq $_} qw( |
|
342 |
SL::DB::Order |
|
343 |
SL::DB::Reclamation |
|
344 |
)) { |
|
345 |
croak("Unsupported source object type '" . ref($source) . "'"); |
|
346 |
} |
|
331 | 347 |
croak("A destination type must be given as parameter") unless $params{destination_type}; |
332 | 348 |
|
333 | 349 |
my $destination_type = delete $params{destination_type}; |
... | ... | |
347 | 363 |
{ from => 'request_quotation', to => 'sales_order', abbr => 'rqso' }, |
348 | 364 |
{ from => 'sales_quotation', to => 'request_quotation', abbr => 'sqrq' }, |
349 | 365 |
{ from => 'sales_order', to => 'request_quotation', abbr => 'sorq' }, |
366 |
{ from => 'sales_reclamation', to => 'sales_order', abbr => 'srso' }, |
|
367 |
{ from => 'purchase_reclamation', to => 'purchase_order', abbr => 'prpo' }, |
|
350 | 368 |
); |
351 | 369 |
my $from_to = (grep { $_->{from} eq $source->type && $_->{to} eq $destination_type} @from_tos)[0]; |
352 | 370 |
croak("Cannot convert from '" . $source->type . "' to '" . $destination_type . "'") if !$from_to; |
... | ... | |
360 | 378 |
if (ref($source) eq 'SL::DB::Order') { |
361 | 379 |
$item_parent_id_column = 'trans_id'; |
362 | 380 |
$item_parent_column = 'order'; |
381 |
} elsif ( ref($source) eq 'SL::DB::Reclamation') { |
|
382 |
$item_parent_id_column = 'reclamation_id'; |
|
383 |
$item_parent_column = 'reclamation'; |
|
363 | 384 |
} |
364 | 385 |
|
365 |
my %args = ( map({ ( $_ => $source->$_ ) } qw(amount cp_id currency_id cusordnumber customer_id delivery_customer_id delivery_term_id delivery_vendor_id |
|
366 |
department_id exchangerate globalproject_id intnotes marge_percent marge_total language_id netamount notes |
|
367 |
ordnumber payment_id quonumber reqdate salesman_id shippingpoint shipvia taxincluded tax_point taxzone_id |
|
368 |
transaction_description vendor_id billing_address_id |
|
369 |
)), |
|
370 |
quotation => !!($destination_type =~ m{quotation$}), |
|
371 |
closed => 0, |
|
372 |
delivered => 0, |
|
373 |
transdate => DateTime->today_local, |
|
374 |
employee => SL::DB::Manager::Employee->current, |
|
375 |
); |
|
386 |
my %args; |
|
387 |
if (ref($source) eq 'SL::DB::Order') { |
|
388 |
%args = ( map({ ( $_ => $source->$_ ) } qw(amount cp_id currency_id cusordnumber customer_id delivery_customer_id delivery_term_id delivery_vendor_id |
|
389 |
department_id exchangerate globalproject_id intnotes marge_percent marge_total language_id netamount notes |
|
390 |
ordnumber payment_id quonumber reqdate salesman_id shippingpoint shipvia taxincluded tax_point taxzone_id |
|
391 |
transaction_description vendor_id billing_address_id |
|
392 |
)), |
|
393 |
quotation => !!($destination_type =~ m{quotation$}), |
|
394 |
closed => 0, |
|
395 |
delivered => 0, |
|
396 |
transdate => DateTime->today_local, |
|
397 |
employee => SL::DB::Manager::Employee->current, |
|
398 |
); |
|
399 |
} elsif ( ref($source) eq 'SL::DB::Reclamation') { |
|
400 |
#TODO(Tamino): add billing_address_id to reclamation |
|
401 |
%args = ( map({ ( $_ => $source->$_ ) } qw( |
|
402 |
amount currency_id customer_id delivery_term_id department_id |
|
403 |
exchangerate globalproject_id intnotes language_id netamount |
|
404 |
notes payment_id reqdate salesman_id shippingpoint shipvia taxincluded |
|
405 |
tax_point taxzone_id transaction_description vendor_id |
|
406 |
)), |
|
407 |
cp_id => $source->{contact_id}, |
|
408 |
closed => 0, |
|
409 |
delivered => 0, |
|
410 |
transdate => DateTime->today_local, |
|
411 |
employee => SL::DB::Manager::Employee->current, |
|
412 |
); |
|
413 |
} |
|
376 | 414 |
|
377 | 415 |
if ( $is_abbr_any->(qw(sopo poso rqso sosq porq rqsq sqrq sorq)) ) { |
378 | 416 |
$args{ordnumber} = undef; |
... | ... | |
420 | 458 |
$item_parents{$source_item_id} ||= $source_item->$item_parent_column; |
421 | 459 |
my $item_parent = $item_parents{$source_item_id}; |
422 | 460 |
|
423 |
my $current_oe_item = SL::DB::OrderItem->new(map({ ( $_ => $source_item->$_ ) } |
|
424 |
qw(active_discount_source active_price_source base_qty cusordnumber |
|
425 |
description discount lastcost longdescription |
|
426 |
marge_percent marge_price_factor marge_total |
|
427 |
ordnumber parts_id price_factor price_factor_id pricegroup_id |
|
428 |
project_id qty reqdate sellprice serialnumber ship subtotal transdate unit |
|
429 |
optional |
|
430 |
)), |
|
431 |
custom_variables => \@custom_variables, |
|
432 |
); |
|
461 |
my $current_oe_item; |
|
462 |
if (ref($source) eq 'SL::DB::Order') { |
|
463 |
$current_oe_item = SL::DB::OrderItem->new(map({ ( $_ => $source_item->$_ ) } |
|
464 |
qw(active_discount_source active_price_source base_qty cusordnumber |
|
465 |
description discount lastcost longdescription |
|
466 |
marge_percent marge_price_factor marge_total |
|
467 |
ordnumber parts_id price_factor price_factor_id pricegroup_id |
|
468 |
project_id qty reqdate sellprice serialnumber ship subtotal transdate unit |
|
469 |
optional |
|
470 |
)), |
|
471 |
custom_variables => \@custom_variables, |
|
472 |
); |
|
473 |
} elsif (ref($source) eq 'SL::DB::Reclamation') { |
|
474 |
$current_oe_item = SL::DB::OrderItem->new( |
|
475 |
map({ ( $_ => $source_item->$_ ) } qw( |
|
476 |
active_discount_source active_price_source base_qty description |
|
477 |
discount lastcost longdescription parts_id price_factor |
|
478 |
price_factor_id pricegroup_id project_id qty reqdate sellprice |
|
479 |
serialnumber unit |
|
480 |
)), |
|
481 |
custom_variables => \@custom_variables, |
|
482 |
); |
|
483 |
} |
|
433 | 484 |
if ( $is_abbr_any->(qw(sopo)) ) { |
434 | 485 |
$current_oe_item->sellprice($source_item->lastcost); |
435 | 486 |
$current_oe_item->discount(0); |
... | ... | |
438 | 489 |
$current_oe_item->lastcost($source_item->sellprice); |
439 | 490 |
} |
440 | 491 |
$current_oe_item->{"converted_from_orderitems_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::Order'; |
492 |
$current_oe_item->{"converted_from_reclamation_item_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::Reclamation'; |
|
441 | 493 |
$current_oe_item; |
442 | 494 |
} @{ $items }; |
443 | 495 |
|
Auch abrufbar als: Unified diff
Workflow: order ↔ reclamation