From: Bernd Bleßmann Date: Tue, 21 Mar 2017 09:09:01 +0000 (+0100) Subject: CsvImport: bei nicht eindeutigen Kunden/Lieferanten Fehler melden. X-Git-Tag: release-3.5.4~1174 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=8bf65ceabe6fcc0a80ca940e04a8d5219aa2d3d2;p=kivitendo-erp.git CsvImport: bei nicht eindeutigen Kunden/Lieferanten Fehler melden. --- diff --git a/SL/Controller/CsvImport/Base.pm b/SL/Controller/CsvImport/Base.pm index e0e60e474..206fce3aa 100644 --- a/SL/Controller/CsvImport/Base.pm +++ b/SL/Controller/CsvImport/Base.pm @@ -23,7 +23,7 @@ use parent qw(Rose::Object); use Rose::Object::MakeMethods::Generic ( scalar => [ qw(controller file csv test_run save_with_cascade) ], - 'scalar --get_set_init' => [ qw(profile displayable_columns existing_objects class manager_class cvar_columns all_cvar_configs all_languages payment_terms_by delivery_terms_by all_bank_accounts all_vc vc_by clone_methods) ], + 'scalar --get_set_init' => [ qw(profile displayable_columns existing_objects class manager_class cvar_columns all_cvar_configs all_languages payment_terms_by delivery_terms_by all_bank_accounts all_vc vc_by vc_counts_by clone_methods) ], ); sub run { @@ -197,6 +197,21 @@ sub init_vc_by { gln => \%by_gln }; } +sub init_vc_counts_by { + my ($self) = @_; + + my $vc_counts_by; + + $vc_counts_by->{number}->{customers}->{$_->number}++ for @{ $self->all_vc->{customers} }; + $vc_counts_by->{number}->{vendors}-> {$_->number}++ for @{ $self->all_vc->{vendors} }; + $vc_counts_by->{name}-> {customers}->{$_->name}++ for @{ $self->all_vc->{customers} }; + $vc_counts_by->{name}-> {vendors}-> {$_->name}++ for @{ $self->all_vc->{vendors} }; + $vc_counts_by->{gln}-> {customers}->{$_->gln}++ for @{ $self->all_vc->{customers} }; + $vc_counts_by->{gln}-> {vendors}-> {$_->gln}++ for @{ $self->all_vc->{vendors} }; + + return $vc_counts_by; +} + sub check_vc { my ($self, $entry, $id_column) = @_; @@ -204,28 +219,60 @@ sub check_vc { $entry->{object}->$id_column(undef) if !$self->vc_by->{id}->{ $entry->{object}->$id_column }; } + my $is_ambiguous; if (!$entry->{object}->$id_column) { - my $vc = ($entry->{raw_data}->{customernumber} && $self->vc_by->{number}->{customers}->{ $entry->{raw_data}->{customernumber} }) - || ($entry->{raw_data}->{vendornumber} && $self->vc_by->{number}->{vendors}->{ $entry->{raw_data}->{vendornumber} }); + my $vc = $entry->{raw_data}->{customernumber} && $self->vc_by->{number}->{customers}->{ $entry->{raw_data}->{customernumber} }; + if ($vc && $self->vc_counts_by->{number}->{customers}->{ $entry->{raw_data}->{customernumber} } > 1) { + $vc = undef; + $is_ambiguous = 1; + } + $vc ||= $entry->{raw_data}->{vendornumber} && $self->vc_by->{number}->{vendors}->{ $entry->{raw_data}->{vendornumber} }; + if ($vc && $self->vc_counts_by->{number}->{vendors}->{ $entry->{raw_data}->{vendornumber} } > 1) { + $vc = undef; + $is_ambiguous = 1; + } + $entry->{object}->$id_column($vc->id) if $vc; } if (!$entry->{object}->$id_column) { - my $vc = ($entry->{raw_data}->{customer} && $self->vc_by->{name}->{customers}->{ $entry->{raw_data}->{customer} }) - || ($entry->{raw_data}->{vendor} && $self->vc_by->{name}->{vendors}->{ $entry->{raw_data}->{vendor} }); + my $vc = $entry->{raw_data}->{customer} && $self->vc_by->{name}->{customers}->{ $entry->{raw_data}->{customer} }; + if ($vc && $self->vc_counts_by->{name}->{customers}->{ $entry->{raw_data}->{customer} } > 1) { + $vc = undef; + $is_ambiguous = 1; + } + $vc ||= $entry->{raw_data}->{vendor} && $self->vc_by->{name}->{vendors}->{ $entry->{raw_data}->{vendor} }; + if ($vc && $self->vc_counts_by->{name}->{vendors}->{ $entry->{raw_data}->{vendor} } > 1) { + $vc = undef; + $is_ambiguous = 1; + } + $entry->{object}->$id_column($vc->id) if $vc; } if (!$entry->{object}->$id_column) { - my $vc = ($entry->{raw_data}->{customer_gln} && $self->vc_by->{gln}->{customers}->{ $entry->{raw_data}->{customer_gln} }) - || ($entry->{raw_data}->{vendor_gln} && $self->vc_by->{gln}->{vendors}->{ $entry->{raw_data}->{vendor_gln} } ); + my $vc = $entry->{raw_data}->{customer_gln} && $self->vc_by->{gln}->{customers}->{ $entry->{raw_data}->{customer_gln} }; + if ($vc && $self->vc_counts_by->{gln}->{customers}->{ $entry->{raw_data}->{customer_gln} } > 1) { + $vc = undef; + $is_ambiguous = 1; + } + $vc ||= $entry->{raw_data}->{vendor_gln} && $self->vc_by->{gln}->{vendors}->{ $entry->{raw_data}->{vendor_gln} }; + if ($vc && $self->vc_counts_by->{gln}->{vendors}->{ $entry->{raw_data}->{vendor_gln} } > 1) { + $vc = undef; + $is_ambiguous = 1; + } + $entry->{object}->$id_column($vc->id) if $vc; } if ($entry->{object}->$id_column) { $entry->{info_data}->{vc_name} = $self->vc_by->{id}->{ $entry->{object}->$id_column }->name; } else { - push @{ $entry->{errors} }, $::locale->text('Error: Customer/vendor not found'); + if ($is_ambiguous) { + push @{ $entry->{errors} }, $::locale->text('Error: Customer/vendor is ambiguous'); + } else { + push @{ $entry->{errors} }, $::locale->text('Error: Customer/vendor not found'); + } } } diff --git a/locale/de/all b/locale/de/all index 3c5eb163d..fb3614d9f 100755 --- a/locale/de/all +++ b/locale/de/all @@ -1197,6 +1197,7 @@ $self->{texts} = { 'Error: A quantity or a target quantity must be given.' => 'Fehler: Menge oder Zielmenge muss angegeben werden.', 'Error: Bin #1 is not from warehouse #2' => 'Lager \'#2\' hat keinen Lagerplatz \'#1\'', 'Error: Bin not found' => 'Fehler: Lagerplatz nicht gefunden', + 'Error: Customer/vendor is ambiguous' => 'Kunde/Lieferant ist mehrdeutig', 'Error: Customer/vendor missing' => 'Fehler: Kunde/Lieferant fehlt', 'Error: Customer/vendor not found' => 'Fehler: Kunde/Lieferant nicht gefunden', 'Error: Found local bank account number but local bank code doesn\'t match' => 'Fehler: Kontonummer wurde gefunden aber gespeicherte Bankleitzahl stimmt nicht überein', diff --git a/locale/en/all b/locale/en/all index 5eae4eedd..987bd471b 100644 --- a/locale/en/all +++ b/locale/en/all @@ -1183,6 +1183,7 @@ $self->{texts} = { 'Error: A quantity or a target quantity must be given.' => '', 'Error: Bin #1 is not from warehouse #2' => '', 'Error: Bin not found' => '', + 'Error: Customer/vendor is ambiguous' => '', 'Error: Customer/vendor missing' => '', 'Error: Customer/vendor not found' => '', 'Error: Found local bank account number but local bank code doesn\'t match' => '',