Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision f7c01833

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

  • ID f7c018334a07ee00579f923422ab03bd0a277750
  • Vorgänger bf0b9c5e
  • Nachfolger 0f214df5

CsvImport: Aufträge: Einheiten behandeln

Unterschiede anzeigen:

SL/Controller/CsvImport/Order.pm
3 3

  
4 4
use strict;
5 5

  
6
use List::MoreUtils qw(any);
6
use List::MoreUtils qw(any none);
7 7

  
8 8
use SL::Helper::Csv;
9 9
use SL::Controller::CsvImport::Helper::Consistency;
......
18 18
use SL::DB::Project;
19 19
use SL::DB::Shipto;
20 20
use SL::DB::TaxZone;
21
use SL::DB::Unit;
21 22
use SL::TransNumber;
22 23

  
23 24
use parent qw(SL::Controller::CsvImport::BaseMulti);
......
25 26

  
26 27
use Rose::Object::MakeMethods::Generic
27 28
(
28
 'scalar --get_set_init' => [ qw(settings languages_by parts_by contacts_by ct_shiptos_by price_factors_by pricegroups_by) ],
29
 'scalar --get_set_init' => [ qw(settings languages_by parts_by contacts_by ct_shiptos_by price_factors_by pricegroups_by units_by) ],
29 30
);
30 31

  
31 32

  
......
237 238
  return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_pricegroups } } ) } qw(id pricegroup) };
238 239
}
239 240

  
241
sub init_units_by {
242
  my ($self) = @_;
243

  
244
  my $all_units = SL::DB::Manager::Unit->get_all;
245
  return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_units } } ) } qw(name) };
246
}
247

  
240 248
sub check_objects {
241 249
  my ($self) = @_;
242 250

  
......
370 378

  
371 379
  my $part_obj = SL::DB::Part->new(id => $object->parts_id)->load;
372 380

  
381
  $self->handle_unit($entry);
382
  $self->handle_sellprice($entry);
383

  
373 384
  # copy from part if not given
374 385
  $object->description($part_obj->description) unless $object->description;
375 386
  $object->longdescription($part_obj->notes)   unless $object->longdescription;
376
  $object->unit($part_obj->unit)               unless $object->unit;
377
  $object->sellprice($part_obj->sellprice)     unless defined $object->sellprice;
378 387
  $object->lastcost($part_obj->lastcost)       unless defined $object->lastcost;
379 388

  
380 389
  # set to 0 if not given
......
386 395
  $self->check_pricegroup($entry);
387 396
}
388 397

  
398
sub handle_unit {
399
  my ($self, $entry) = @_;
400

  
401
  my $object = $entry->{object};
402

  
403
  # Set unit from part if not given.
404
  if (!$object->unit) {
405
    $object->unit($object->part->unit);
406
    return 1;
407
  }
408

  
409
  # Check whether or not unit is valid.
410
  if ($object->unit && !$self->units_by->{name}->{ $object->unit }) {
411
    push @{ $entry->{errors} }, $::locale->text('Error: Invalid unit');
412
    return 0;
413
  }
414

  
415
  # Check whether unit is convertible to parts unit
416
  if (none { $object->unit eq $_ } map { $_->name } @{ $object->part->unit_obj->convertible_units }) {
417
    push @{ $entry->{errors} }, $::locale->text('Error: Invalid unit');
418
    return 0;
419
  }
420

  
421
  return 1;
422
}
423

  
424
sub handle_sellprice {
425
  my ($self, $entry) = @_;
426

  
427
  my $object = $entry->{object};
428

  
429
  # Set sellprice from part if not given. Convert with respect to unit.
430
  if (!defined $object->sellprice) {
431
    my $sellprice = $object->part->sellprice;
432

  
433
    if ($object->unit ne $object->part->unit) {
434
      $sellprice = $object->unit_obj->convert_to($sellprice, $object->part->unit_obj);
435
    }
436
    $object->sellprice($sellprice);
437
  }
438
}
439

  
389 440
sub check_part {
390 441
  my ($self, $entry) = @_;
391 442

  
locale/de/all
1167 1167
  'Error: Invalid salesman'     => 'Fehler: Ungültiger Verkäufer',
1168 1168
  'Error: Invalid shipto'       => 'Fehler: Lieferadresse ungültig',
1169 1169
  'Error: Invalid tax zone'     => 'Fehler: Steuerzone ungültig',
1170
  'Error: Invalid unit'         => 'Fehler: Einheit ungültig',
1170 1171
  'Error: Invalid vendor in column make_#1' => 'Fehler: Lieferant ungültig in Spalte make_#1',
1171 1172
  'Error: Invalid warehouse'    => 'Fehler: Ungültiges Lager',
1172 1173
  'Error: Name missing'         => 'Fehler: Name fehlt',
locale/en/all
1167 1167
  'Error: Invalid salesman'     => '',
1168 1168
  'Error: Invalid shipto'       => '',
1169 1169
  'Error: Invalid tax zone'     => '',
1170
  'Error: Invalid unit'         => '',
1170 1171
  'Error: Invalid vendor in column make_#1' => '',
1171 1172
  'Error: Invalid warehouse'    => '',
1172 1173
  'Error: Name missing'         => '',

Auch abrufbar als: Unified diff