Revision c1ed1e91
Von Tamino Steinert vor fast 2 Jahren hinzugefügt
SL/DB/Order.pm | ||
---|---|---|
299 | 299 |
return $delivery_order; |
300 | 300 |
} |
301 | 301 |
|
302 |
sub convert_to_reclamation { |
|
303 |
my ($self, %params) = @_; |
|
304 |
$params{destination_type} = $self->is_sales ? 'sales_reclamation' |
|
305 |
: 'purchase_reclamation'; |
|
306 |
|
|
307 |
require SL::DB::Reclamation; |
|
308 |
my $reclamation = SL::DB::Reclamation->new_from($self, %params); |
|
309 |
|
|
310 |
return $reclamation; |
|
311 |
} |
|
312 |
|
|
302 | 313 |
sub _clone_orderitem_cvar { |
303 | 314 |
my ($cvar) = @_; |
304 | 315 |
|
... | ... | |
311 | 322 |
sub new_from { |
312 | 323 |
my ($class, $source, %params) = @_; |
313 | 324 |
|
314 |
croak("Unsupported source object type '" . ref($source) . "'") unless ref($source) eq 'SL::DB::Order'; |
|
325 |
unless (any {ref($source) eq $_} qw( |
|
326 |
SL::DB::Order |
|
327 |
SL::DB::Reclamation |
|
328 |
)) { |
|
329 |
croak("Unsupported source object type '" . ref($source) . "'"); |
|
330 |
} |
|
315 | 331 |
croak("A destination type must be given as parameter") unless $params{destination_type}; |
316 | 332 |
|
317 | 333 |
my $destination_type = delete $params{destination_type}; |
... | ... | |
327 | 343 |
{ from => 'purchase_order', to => 'sales_order', abbr => 'poso' }, |
328 | 344 |
{ from => 'sales_order', to => 'sales_quotation', abbr => 'sosq' }, |
329 | 345 |
{ from => 'purchase_order', to => 'request_quotation', abbr => 'porq' }, |
346 |
{ from => 'sales_reclamation', to => 'sales_order', abbr => 'srso' }, |
|
347 |
{ from => 'purchase_reclamation', to => 'purchase_order', abbr => 'prpo' }, |
|
330 | 348 |
); |
331 | 349 |
my $from_to = (grep { $_->{from} eq $source->type && $_->{to} eq $destination_type} @from_tos)[0]; |
332 | 350 |
croak("Cannot convert from '" . $source->type . "' to '" . $destination_type . "'") if !$from_to; |
... | ... | |
340 | 358 |
if (ref($source) eq 'SL::DB::Order') { |
341 | 359 |
$item_parent_id_column = 'trans_id'; |
342 | 360 |
$item_parent_column = 'order'; |
361 |
} elsif ( ref($source) eq 'SL::DB::Reclamation') { |
|
362 |
$item_parent_id_column = 'reclamation_id'; |
|
363 |
$item_parent_column = 'reclamation'; |
|
343 | 364 |
} |
344 | 365 |
|
345 |
my %args = ( map({ ( $_ => $source->$_ ) } qw(amount cp_id currency_id cusordnumber customer_id delivery_customer_id delivery_term_id delivery_vendor_id |
|
346 |
department_id exchangerate globalproject_id intnotes marge_percent marge_total language_id netamount notes |
|
347 |
ordnumber payment_id quonumber reqdate salesman_id shippingpoint shipvia taxincluded tax_point taxzone_id |
|
348 |
transaction_description vendor_id billing_address_id |
|
349 |
)), |
|
350 |
quotation => !!($destination_type =~ m{quotation$}), |
|
351 |
closed => 0, |
|
352 |
delivered => 0, |
|
353 |
transdate => DateTime->today_local, |
|
354 |
employee => SL::DB::Manager::Employee->current, |
|
355 |
); |
|
366 |
my %args; |
|
367 |
if (ref($source) eq 'SL::DB::Order') { |
|
368 |
%args = ( map({ ( $_ => $source->$_ ) } qw(amount cp_id currency_id cusordnumber customer_id delivery_customer_id delivery_term_id delivery_vendor_id |
|
369 |
department_id exchangerate globalproject_id intnotes marge_percent marge_total language_id netamount notes |
|
370 |
ordnumber payment_id quonumber reqdate salesman_id shippingpoint shipvia taxincluded tax_point taxzone_id |
|
371 |
transaction_description vendor_id billing_address_id |
|
372 |
)), |
|
373 |
quotation => !!($destination_type =~ m{quotation$}), |
|
374 |
closed => 0, |
|
375 |
delivered => 0, |
|
376 |
transdate => DateTime->today_local, |
|
377 |
employee => SL::DB::Manager::Employee->current, |
|
378 |
); |
|
379 |
} elsif ( ref($source) eq 'SL::DB::Reclamation') { |
|
380 |
#TODO(Tamino): add billing_address_id to reclamation |
|
381 |
%args = ( map({ ( $_ => $source->$_ ) } qw( |
|
382 |
amount currency_id customer_id delivery_term_id department_id |
|
383 |
exchangerate globalproject_id intnotes language_id netamount |
|
384 |
notes payment_id reqdate salesman_id shippingpoint shipvia taxincluded |
|
385 |
tax_point taxzone_id transaction_description vendor_id |
|
386 |
)), |
|
387 |
cp_id => $source->{contact_id}, |
|
388 |
closed => 0, |
|
389 |
delivered => 0, |
|
390 |
transdate => DateTime->today_local, |
|
391 |
employee => SL::DB::Manager::Employee->current, |
|
392 |
); |
|
393 |
} |
|
356 | 394 |
|
357 | 395 |
if ( $is_abbr_any->(qw(sopo poso)) ) { |
358 | 396 |
$args{ordnumber} = undef; |
... | ... | |
402 | 440 |
$item_parents{$source_item_id} ||= $source_item->$item_parent_column; |
403 | 441 |
my $item_parent = $item_parents{$source_item_id}; |
404 | 442 |
|
405 |
my $current_oe_item = SL::DB::OrderItem->new(map({ ( $_ => $source_item->$_ ) } |
|
406 |
qw(active_discount_source active_price_source base_qty cusordnumber |
|
407 |
description discount lastcost longdescription |
|
408 |
marge_percent marge_price_factor marge_total |
|
409 |
ordnumber parts_id price_factor price_factor_id pricegroup_id |
|
410 |
project_id qty reqdate sellprice serialnumber ship subtotal transdate unit |
|
411 |
optional |
|
412 |
)), |
|
413 |
custom_variables => \@custom_variables, |
|
414 |
); |
|
443 |
my $current_oe_item; |
|
444 |
if (ref($source) eq 'SL::DB::Order') { |
|
445 |
$current_oe_item = SL::DB::OrderItem->new(map({ ( $_ => $source_item->$_ ) } |
|
446 |
qw(active_discount_source active_price_source base_qty cusordnumber |
|
447 |
description discount lastcost longdescription |
|
448 |
marge_percent marge_price_factor marge_total |
|
449 |
ordnumber parts_id price_factor price_factor_id pricegroup_id |
|
450 |
project_id qty reqdate sellprice serialnumber ship subtotal transdate unit |
|
451 |
optional |
|
452 |
)), |
|
453 |
custom_variables => \@custom_variables, |
|
454 |
); |
|
455 |
} elsif (ref($source) eq 'SL::DB::Reclamation') { |
|
456 |
$current_oe_item = SL::DB::OrderItem->new( |
|
457 |
map({ ( $_ => $source_item->$_ ) } qw( |
|
458 |
active_discount_source active_price_source base_qty description |
|
459 |
discount lastcost longdescription parts_id price_factor |
|
460 |
price_factor_id pricegroup_id project_id qty reqdate sellprice |
|
461 |
serialnumber unit |
|
462 |
)), |
|
463 |
custom_variables => \@custom_variables, |
|
464 |
); |
|
465 |
} |
|
415 | 466 |
if ( $is_abbr_any->(qw(sopo)) ) { |
416 | 467 |
$current_oe_item->sellprice($source_item->lastcost); |
417 | 468 |
$current_oe_item->discount(0); |
... | ... | |
420 | 471 |
$current_oe_item->lastcost($source_item->sellprice); |
421 | 472 |
} |
422 | 473 |
$current_oe_item->{"converted_from_orderitems_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::Order'; |
474 |
$current_oe_item->{"converted_from_reclamation_item_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::Reclamation'; |
|
423 | 475 |
$current_oe_item; |
424 | 476 |
} @{ $items }; |
425 | 477 |
|
Auch abrufbar als: Unified diff
Workflow: order ↔ reclamation