From: Bernd Bleßmann Date: Thu, 23 Mar 2017 22:09:08 +0000 (+0100) Subject: CsvImport Aufträge: bei nicht eindeutigen Artikeln Fehler melden. X-Git-Tag: release-3.5.4~1172 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=9ca0da81731536fd78983f92f4f491c34bebb7e6;p=kivitendo-erp.git CsvImport Aufträge: bei nicht eindeutigen Artikeln Fehler melden. --- diff --git a/SL/Controller/CsvImport/Order.pm b/SL/Controller/CsvImport/Order.pm index 4393fd424..484f5b87c 100644 --- a/SL/Controller/CsvImport/Order.pm +++ b/SL/Controller/CsvImport/Order.pm @@ -26,7 +26,7 @@ use parent qw(SL::Controller::CsvImport::BaseMulti); use Rose::Object::MakeMethods::Generic ( - 'scalar --get_set_init' => [ qw(settings languages_by parts_by contacts_by ct_shiptos_by price_factors_by pricegroups_by units_by) ], + 'scalar --get_set_init' => [ qw(settings languages_by all_parts parts_by part_counts_by contacts_by ct_shiptos_by price_factors_by pricegroups_by units_by) ], ); @@ -194,11 +194,27 @@ sub init_languages_by { return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_languages } } ) } qw(id description article_code) }; } +sub init_all_parts { + my ($self) = @_; + + return SL::DB::Manager::Part->get_all; +} + sub init_parts_by { my ($self) = @_; - my $all_parts = SL::DB::Manager::Part->get_all; - return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_parts } } ) } qw(id partnumber ean description) }; + return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_parts } } ) } qw(id partnumber ean description) }; +} + +sub init_part_counts_by { + my ($self) = @_; + + my $part_counts_by; + + $part_counts_by->{ean}-> {$_->ean}++ for @{ $self->all_parts }; + $part_counts_by->{description}->{$_->description}++ for @{ $self->all_parts }; + + return $part_counts_by; } sub init_contacts_by { @@ -436,6 +452,7 @@ sub check_part { my ($self, $entry) = @_; my $object = $entry->{object}; + my $is_ambiguous; # Check whether or not part ID is valid. if ($object->parts_id && !$self->parts_by->{id}->{ $object->parts_id }) { @@ -462,7 +479,11 @@ sub check_part { return 0; } - $object->parts_id($part->id); + if ($self->part_counts_by->{description}->{ $entry->{raw_data}->{description} } > 1) { + $is_ambiguous = 1; + } else { + $object->parts_id($part->id); + } } # Map ean to ID if given. @@ -473,13 +494,21 @@ sub check_part { return 0; } - $object->parts_id($part->id); + if ($self->part_counts_by->{ean}->{ $entry->{raw_data}->{ean} } > 1) { + $is_ambiguous = 1; + } else { + $object->parts_id($part->id); + } } if ($object->parts_id) { $entry->{info_data}->{partnumber} = $self->parts_by->{id}->{ $object->parts_id }->partnumber; } else { - push @{ $entry->{errors} }, $::locale->text('Error: Part not found'); + if ($is_ambiguous) { + push @{ $entry->{errors} }, $::locale->text('Error: Part is ambiguous'); + } else { + push @{ $entry->{errors} }, $::locale->text('Error: Part not found'); + } return 0; } diff --git a/locale/de/all b/locale/de/all index fb3614d9f..dc5d106af 100755 --- a/locale/de/all +++ b/locale/de/all @@ -1227,6 +1227,7 @@ $self->{texts} = { 'Error: Invalid warehouse id' => 'Ungültige Lager-ID', 'Error: Invalid warehouse name #1' => 'Ungültiger Lagername \'#1\'', 'Error: Name missing' => 'Fehler: Name fehlt', + 'Error: Part is ambiguous' => 'Artikel ist mehrdeutig', 'Error: Part is obsolete' => 'Fehler: Artikel ist ungültig', 'Error: Part not found' => 'Fehler: Artikel nicht gefunden', 'Error: Quantity to transfer is zero.' => 'Fehler: Zu bewegende Menge ist Null.', diff --git a/locale/en/all b/locale/en/all index 987bd471b..ad7a4ff46 100644 --- a/locale/en/all +++ b/locale/en/all @@ -1214,6 +1214,7 @@ $self->{texts} = { 'Error: Invalid warehouse id' => '', 'Error: Invalid warehouse name #1' => '', 'Error: Name missing' => '', + 'Error: Part is ambiguous' => '', 'Error: Part is obsolete' => '', 'Error: Part not found' => '', 'Error: Quantity to transfer is zero.' => '',