Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 5fcdbc58

Von Bernd Bleßmann vor mehr als 3 Jahren hinzugefügt

  • ID 5fcdbc58f212a020ff67de3e66edf7ad4845fb8d
  • Vorgänger be076f02
  • Nachfolger ffd2ad0a

CsvImport: Aufträge: Preise/Rabatte aus Preisquellen ermitteln, …

… wenn in der CSV-Datei nicht angegeben. Und Preisquelle auch setzen.

Unterschiede anzeigen:

SL/Controller/CsvImport/Order.pm
19 19
use SL::DB::Shipto;
20 20
use SL::DB::TaxZone;
21 21
use SL::DB::Unit;
22
use SL::PriceSource;
22 23
use SL::TransNumber;
23 24

  
24 25
use parent qw(SL::Controller::CsvImport::BaseMulti);
......
271 272

  
272 273
  my $i = 0;
273 274
  my $num_data = scalar @{ $self->controller->data };
275
  my $order_entry;
274 276
  foreach my $entry (@{ $self->controller->data }) {
275 277
    $self->controller->track_progress(progress => $i/$num_data * 100) if $i % 100 == 0;
276 278

  
......
278 280

  
279 281
    if ($entry->{raw_data}->{datatype} eq $self->_order_column) {
280 282
      $self->handle_order($entry);
283
      $order_entry = $entry;
281 284
    } elsif ($entry->{raw_data}->{datatype} eq $self->_item_column && $entry->{object}->can('part')) {
282
      $self->handle_item($entry);
285
      $self->handle_item($entry, $order_entry);
286
    } else {
287
      $order_entry = undef;
283 288
    }
289

  
284 290
    $self->handle_cvars($entry, sub_module => 'orderitems');
285 291

  
286 292
  } continue {
......
383 389
}
384 390

  
385 391
sub handle_item {
386
  my ($self, $entry) = @_;
392
  my ($self, $entry, $order_entry) = @_;
393

  
394
  return unless $order_entry;
387 395

  
388 396
  my $object = $entry->{object};
397

  
389 398
  return unless $self->check_part($entry);
390 399

  
391 400
  my $part_obj = SL::DB::Part->new(id => $object->parts_id)->load;
392 401

  
393 402
  $self->handle_unit($entry);
394
  $self->handle_sellprice($entry);
395
  $self->handle_discount($entry);
396 403

  
397 404
  # copy from part if not given
398 405
  $object->description($part_obj->description) unless $object->description;
......
405 412
  $self->check_project($entry, global => 0);
406 413
  $self->check_price_factor($entry);
407 414
  $self->check_pricegroup($entry);
415

  
416
  $self->handle_sellprice($entry, $order_entry);
417
  $self->handle_discount($entry, $order_entry);
408 418
}
409 419

  
410 420
sub handle_unit {
......
434 444
}
435 445

  
436 446
sub handle_sellprice {
437
  my ($self, $entry) = @_;
447
  my ($self, $entry, $record_entry) = @_;
438 448

  
439
  my $object = $entry->{object};
449
  my $item   = $entry->{object};
450
  my $record = $record_entry->{object};
451

  
452
  return if !$record->customervendor;
440 453

  
441
  # Set sellprice from part if not given. Convert with respect to unit.
442
  if (!defined $object->sellprice) {
443
    my $sellprice = $object->part->sellprice;
454
  # If sellprice is given, set price source to pricegroup if given or to none.
455
  if (exists $entry->{raw_data}->{sellprice}) {
456
    my $price_source      = SL::PriceSource->new(record_item => $item, record => $record);
457
    my $price_source_spec = $item->pricegroup_id ? 'pricegroup' . '/' . $item->pricegroup_id : '';
458
    my $price             = $price_source->price_from_source($price_source_spec);
459
    $item->active_price_source($price->source);
444 460

  
445
    if ($object->unit ne $object->part->unit) {
446
      $sellprice = $object->unit_obj->convert_to($sellprice, $object->part->unit_obj);
461
  } else {
462
    # Set sellprice the best price of price source
463
    my $price_source = SL::PriceSource->new(record_item => $item, record => $record);
464
    my $price        = $price_source->best_price;
465
    if ($price) {
466
      $item->sellprice($price->price);
467
      $item->active_price_source($price->source);
468
    } else {
469
      $item->sellprice(0);
470
      $item->active_price_source($price_source->price_from_source('')->source);
447 471
    }
448
    $object->sellprice($sellprice);
449 472
  }
450 473
}
451 474

  
452 475
sub handle_discount {
453
  my ($self, $entry) = @_;
476
  my ($self, $entry, $record_entry) = @_;
454 477

  
455
  my $object = $entry->{object};
478
  my $item   = $entry->{object};
479
  my $record = $record_entry->{object};
480

  
481
  return if !$record->customervendor;
482

  
483
  # If discount is given, set discount source to none.
484
  if (exists $entry->{raw_data}->{discount}) {
485
    $item->discount($item->discount/100.0)      if $item->discount;
486
    $item->discount(0)                      unless $item->discount;
456 487

  
457
  $object->discount($object->discount/100.0)     if $object->discount;
458
  $object->discount(0)                       unless $object->discount;
488
    my $price_source = SL::PriceSource->new(record_item => $item, record => $record);
489
    my $discount     = $price_source->price_from_source('');
490
    $item->active_discount_source($discount->source);
491

  
492
  } else {
493
    # Set discount the best discount of price source
494
    my $price_source = SL::PriceSource->new(record_item => $item, record => $record);
495
    my $discount     = $price_source->best_discount;
496
    if ($discount) {
497
      $item->discount($discount->discount);
498
      $item->active_discount_source($discount->source);
499
    } else {
500
      $item->discount(0);
501
      $item->active_discount_source($price_source->discount_from_source('')->source);
502
    }
503
  }
459 504
}
460 505

  
461 506
sub check_part {

Auch abrufbar als: Unified diff