Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 08e12ce7

Von Tamino Steinert vor etwa 2 Jahren hinzugefügt

  • ID 08e12ce7532308114d58684086b9ead36fee3882
  • Vorgänger 5e7a4ba2
  • Nachfolger c8774e89

Workflow: order ↔ reclamation

Unterschiede anzeigen:

SL/DB/Order.pm
316 316
  return $delivery_order;
317 317
}
318 318

  
319
sub convert_to_reclamation {
320
  my ($self, %params) = @_;
321
  $params{destination_type} = $self->is_sales ? 'sales_reclamation'
322
                                              : 'purchase_reclamation';
323

  
324
  require SL::DB::Reclamation;
325
  my $reclamation = SL::DB::Reclamation->new_from($self, %params);
326

  
327
  return $reclamation;
328
}
329

  
319 330
sub _clone_orderitem_cvar {
320 331
  my ($cvar) = @_;
321 332

  
......
328 339
sub new_from {
329 340
  my ($class, $source, %params) = @_;
330 341

  
331
  croak("Unsupported source object type '" . ref($source) . "'") unless ref($source) eq 'SL::DB::Order';
342
  unless (any {ref($source) eq $_} qw(
343
    SL::DB::Order
344
    SL::DB::Reclamation
345
  )) {
346
    croak("Unsupported source object type '" . ref($source) . "'");
347
  }
332 348
  croak("A destination type must be given as parameter")         unless $params{destination_type};
333 349

  
334 350
  my $destination_type  = delete $params{destination_type};
......
348 364
    { from => 'request_quotation', to => 'sales_order',       abbr => 'rqso' },
349 365
    { from => 'sales_quotation',   to => 'request_quotation', abbr => 'sqrq' },
350 366
    { from => 'sales_order',       to => 'request_quotation', abbr => 'sorq' },
367
    { from => 'sales_reclamation', to => 'sales_order',       abbr => 'srso' },
368
    { from => 'purchase_reclamation', to => 'purchase_order', abbr => 'prpo' },
351 369
  );
352 370
  my $from_to = (grep { $_->{from} eq $source->type && $_->{to} eq $destination_type} @from_tos)[0];
353 371
  croak("Cannot convert from '" . $source->type . "' to '" . $destination_type . "'") if !$from_to;
......
361 379
  if (ref($source) eq 'SL::DB::Order') {
362 380
    $item_parent_id_column = 'trans_id';
363 381
    $item_parent_column    = 'order';
382
  } elsif ( ref($source) eq 'SL::DB::Reclamation') {
383
    $item_parent_id_column = 'reclamation_id';
384
    $item_parent_column    = 'reclamation';
364 385
  }
365 386

  
366
  my %args = ( map({ ( $_ => $source->$_ ) } qw(amount cp_id currency_id cusordnumber customer_id delivery_customer_id delivery_term_id delivery_vendor_id
367
                                                department_id exchangerate globalproject_id intnotes marge_percent marge_total language_id netamount notes
368
                                                ordnumber payment_id quonumber reqdate salesman_id shippingpoint shipvia taxincluded tax_point taxzone_id
369
                                                transaction_description vendor_id billing_address_id
370
                                             )),
371
               quotation => !!($destination_type =~ m{quotation$}),
372
               closed    => 0,
373
               delivered => 0,
374
               transdate => DateTime->today_local,
375
               employee  => SL::DB::Manager::Employee->current,
376
            );
377
  # reqdate in quotation is 'offer is valid    until reqdate'
378
  # reqdate in order     is 'will be delivered until reqdate'
379
  # both dates are setable (on|off)
380
  # and may have a additional interval in days (+ n days)
381
  # dies if this convention will change
382
  $args{reqdate} = $from_to->{to} =~ m/_quotation$/
383
                 ? $::instance_conf->get_reqdate_on
384
                 ? DateTime->today_local->next_workday(extra_days => $::instance_conf->get_reqdate_interval)->to_kivitendo
385
                 : undef
386
                 : $from_to->{to} =~ m/_order$/
387
                 ? $::instance_conf->get_deliverydate_on
388
                 ? DateTime->today_local->next_workday(extra_days => $::instance_conf->get_delivery_date_interval)->to_kivitendo
389
                 : undef
390
                 : die "Wrong state for reqdate";
387
  my %args;
388
  if (ref($source) eq 'SL::DB::Order') {
389
    %args = ( map({ ( $_ => $source->$_ ) } qw(amount cp_id currency_id cusordnumber customer_id delivery_customer_id delivery_term_id delivery_vendor_id
390
                                               department_id exchangerate globalproject_id intnotes marge_percent marge_total language_id netamount notes
391
                                               ordnumber payment_id quonumber reqdate salesman_id shippingpoint shipvia taxincluded tax_point taxzone_id
392
                                               transaction_description vendor_id billing_address_id
393
                                            )),
394
                 quotation => !!($destination_type =~ m{quotation$}),
395
                 closed    => 0,
396
                 delivered => 0,
397
                 transdate => DateTime->today_local,
398
                 employee  => SL::DB::Manager::Employee->current,
399
              );
400
    # reqdate in quotation is 'offer is valid    until reqdate'
401
    # reqdate in order     is 'will be delivered until reqdate'
402
    # both dates are setable (on|off)
403
    # and may have a additional interval in days (+ n days)
404
    # dies if this convention will change
405
    $args{reqdate} = $from_to->{to} =~ m/_quotation$/
406
                   ? $::instance_conf->get_reqdate_on
407
                   ? DateTime->today_local->next_workday(extra_days => $::instance_conf->get_reqdate_interval)->to_kivitendo
408
                   : undef
409
                   : $from_to->{to} =~ m/_order$/
410
                   ? $::instance_conf->get_deliverydate_on
411
                   ? DateTime->today_local->next_workday(extra_days => $::instance_conf->get_delivery_date_interval)->to_kivitendo
412
                   : undef
413
                   : die "Wrong state for reqdate";
414
  } elsif ( ref($source) eq 'SL::DB::Reclamation') {
415
    #TODO(Tamino): add billing_address_id to reclamation
416
    %args = ( map({ ( $_ => $source->$_ ) } qw(
417
        amount currency_id customer_id delivery_term_id department_id
418
        exchangerate globalproject_id intnotes language_id netamount
419
        notes payment_id  reqdate salesman_id shippingpoint shipvia taxincluded
420
        tax_point taxzone_id transaction_description vendor_id
421
      )),
422
      cp_id     => $source->{contact_id},
423
      closed    => 0,
424
      delivered => 0,
425
      transdate => DateTime->today_local,
426
      employee  => SL::DB::Manager::Employee->current,
427
   );
428
  }
391 429

  
392 430
  if ( $is_abbr_any->(qw(sopo poso rqso sosq porq rqsq sqrq sorq)) ) {
393 431
    $args{ordnumber} = undef;
......
434 472
    $item_parents{$source_item_id} ||= $source_item->$item_parent_column;
435 473
    my $item_parent                  = $item_parents{$source_item_id};
436 474

  
437
    my $current_oe_item = SL::DB::OrderItem->new(map({ ( $_ => $source_item->$_ ) }
438
                                                     qw(active_discount_source active_price_source base_qty cusordnumber
439
                                                        description discount lastcost longdescription
440
                                                        marge_percent marge_price_factor marge_total
441
                                                        ordnumber parts_id price_factor price_factor_id pricegroup_id
442
                                                        project_id qty reqdate sellprice serialnumber ship subtotal transdate unit
443
                                                        optional
444
                                                     )),
445
                                                 custom_variables => \@custom_variables,
446
    );
475
    my $current_oe_item;
476
    if (ref($source) eq 'SL::DB::Order') {
477
      $current_oe_item = SL::DB::OrderItem->new(map({ ( $_ => $source_item->$_ ) }
478
                                                       qw(active_discount_source active_price_source base_qty cusordnumber
479
                                                          description discount lastcost longdescription
480
                                                          marge_percent marge_price_factor marge_total
481
                                                          ordnumber parts_id price_factor price_factor_id pricegroup_id
482
                                                          project_id qty reqdate sellprice serialnumber ship subtotal transdate unit
483
                                                          optional
484
                                                       )),
485
                                                   custom_variables => \@custom_variables,
486
      );
487
    } elsif (ref($source) eq 'SL::DB::Reclamation') {
488
      $current_oe_item = SL::DB::OrderItem->new(
489
        map({ ( $_ => $source_item->$_ ) } qw(
490
          active_discount_source active_price_source base_qty description
491
          discount lastcost longdescription parts_id price_factor
492
          price_factor_id pricegroup_id project_id qty reqdate sellprice
493
          serialnumber unit
494
        )),
495
        custom_variables => \@custom_variables,
496
      );
497
    }
447 498
    if ( $is_abbr_any->(qw(sopo)) ) {
448 499
      $current_oe_item->sellprice($source_item->lastcost);
449 500
      $current_oe_item->discount(0);
......
452 503
      $current_oe_item->lastcost($source_item->sellprice);
453 504
    }
454 505
    $current_oe_item->{"converted_from_orderitems_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::Order';
506
    $current_oe_item->{"converted_from_reclamation_item_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::Reclamation';
455 507
    $current_oe_item;
456 508
  } @{ $items };
457 509

  

Auch abrufbar als: Unified diff