From: Moritz Bunkus Date: Wed, 29 May 2013 13:45:47 +0000 (+0200) Subject: Währung beim CSV-Import Kunden/Lieferanten unterstützen X-Git-Tag: release-3.1.0beta1~401^2~3 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=d70e6870a8cbadc86b0584a780e6f84c95dcb21d;p=kivitendo-erp.git Währung beim CSV-Import Kunden/Lieferanten unterstützen Fixt #2282. --- diff --git a/SL/Controller/CsvImport/Base.pm b/SL/Controller/CsvImport/Base.pm index 7f4326a07..db6dc4d87 100644 --- a/SL/Controller/CsvImport/Base.pm +++ b/SL/Controller/CsvImport/Base.pm @@ -5,6 +5,7 @@ use strict; use List::MoreUtils qw(pairwise); use SL::Helper::Csv; +use SL::DB::Currency; use SL::DB::Customer; use SL::DB::Language; use SL::DB::PaymentTerm; @@ -16,7 +17,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 all_vc vc_by) ], + 'scalar --get_set_init' => [ qw(profile displayable_columns existing_objects class manager_class cvar_columns all_cvar_configs all_languages payment_terms_by all_currencies default_currency_id all_vc vc_by) ], ); sub run { @@ -139,6 +140,18 @@ sub init_all_languages { return SL::DB::Manager::Language->get_all; } +sub init_all_currencies { + my ($self) = @_; + + return SL::DB::Manager::Currency->get_all; +} + +sub init_default_currency_id { + my ($self) = @_; + + return SL::DB::Default->get->currency_id; +} + sub init_payment_terms_by { my ($self) = @_; diff --git a/SL/Controller/CsvImport/CustomerVendor.pm b/SL/Controller/CsvImport/CustomerVendor.pm index 96eb69691..47964936e 100644 --- a/SL/Controller/CsvImport/CustomerVendor.pm +++ b/SL/Controller/CsvImport/CustomerVendor.pm @@ -13,7 +13,7 @@ use parent qw(SL::Controller::CsvImport::Base); use Rose::Object::MakeMethods::Generic ( - 'scalar --get_set_init' => [ qw(table languages_by businesses_by) ], + 'scalar --get_set_init' => [ qw(table languages_by businesses_by currencies_by) ], ); sub init_table { @@ -44,6 +44,12 @@ sub init_languages_by { return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_languages } } ) } qw(id description article_code) }; } +sub init_currencies_by { + my ($self) = @_; + + return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_currencies } } ) } qw(id name) }; +} + sub check_objects { my ($self) = @_; @@ -65,6 +71,7 @@ sub check_objects { $self->check_language($entry); $self->check_business($entry); $self->check_payment($entry); + $self->check_currency($entry); $self->handle_cvars($entry); next if @{ $entry->{errors} }; @@ -155,6 +162,36 @@ sub check_language { return 1; } +sub check_currency { + my ($self, $entry) = @_; + + my $object = $entry->{object}; + + # Check whether or not currency ID is valid. + if ($object->currency_id && !$self->currencies_by->{id}->{ $object->currency_id }) { + push @{ $entry->{errors} }, $::locale->text('Error: Invalid currency'); + return 0; + } + + # Map name to ID if given. + if (!$object->currency_id && $entry->{raw_data}->{currency}) { + my $currency = $self->currencies_by->{name}->{ $entry->{raw_data}->{currency} }; + if (!$currency) { + push @{ $entry->{errors} }, $::locale->text('Error: Invalid currency'); + return 0; + } + + $object->currency_id($currency->id); + } + + # Set default currency if none was given. + $object->currency_id($self->default_currency_id) if !$object->currency_id; + + $entry->{raw_data}->{currency_id} = $object->currency_id; + + return 1; +} + sub check_business { my ($self, $entry) = @_; @@ -253,6 +290,8 @@ sub setup_displayable_columns { { name => 'contact', description => $::locale->text('Contact') }, { name => 'country', description => $::locale->text('Country') }, { name => 'creditlimit', description => $::locale->text('Credit Limit') }, + { name => 'currency', description => $::locale->text('Currency') }, + { name => 'currency_id', description => $::locale->text('Currency (database ID)') }, { name => 'customernumber', description => $::locale->text('Customer Number') }, { name => 'department_1', description => $::locale->text('Department 1') }, { name => 'department_2', description => $::locale->text('Department 2') }, diff --git a/locale/de/all b/locale/de/all index ca3457568..18470b177 100755 --- a/locale/de/all +++ b/locale/de/all @@ -298,7 +298,6 @@ $self->{texts} = { 'Billing/shipping address (street)' => 'Rechnungsadresse (Straße)', 'Billing/shipping address (zipcode)' => 'Rechnungsadresse (PLZ)', 'Bin' => 'Lagerplatz', - 'Bin 2' => '', 'Bin From' => 'Quelllagerplatz', 'Bin List' => 'Lagerliste', 'Bin To' => 'Ziellagerplatz', @@ -528,6 +527,7 @@ $self->{texts} = { 'Curr' => 'Währung', 'Currencies' => 'Währungen', 'Currency' => 'Währung', + 'Currency (database ID)' => 'Währung (Datenbank-ID)', 'Current / Next Level' => 'Aktuelles / Nächstes Mahnlevel', 'Current Earnings' => 'Gewinn', 'Current assets account' => 'Konto für Umlaufvermögen', @@ -608,9 +608,7 @@ $self->{texts} = { 'Decrease' => 'Verringern', 'Default (no language selected)' => 'Standard (keine Sprache ausgewählt)', 'Default Accounts' => 'Standardkonten', - 'Default Bin' => '', 'Default Customer/Vendor Language' => 'Standard-Kunden-/Lieferantensprache', - 'Default Warehouse' => '', 'Default buchungsgruppe' => 'Standardbuchungsgruppe', 'Default currency' => 'Standardwährung', 'Default currency missing!' => 'Standardwährung fehlt!', @@ -835,6 +833,7 @@ $self->{texts} = { 'Error: Customer/vendor not found' => 'Fehler: Kunde/Lieferant nicht gefunden', 'Error: Gender (cp_gender) missing or invalid' => 'Fehler: Geschlecht (cp_gender) fehlt oder ungültig', 'Error: Invalid business' => 'Fehler: Kunden-/Lieferantentyp ungültig', + 'Error: Invalid currency' => 'Fehler: ungültige Währung', 'Error: Invalid language' => 'Fehler: Sprache ungültig', 'Error: Invalid part type' => 'Fehler: Artikeltyp ungültig', 'Error: Invalid parts group' => 'Fehler: Warengruppe ungültig', @@ -937,8 +936,8 @@ $self->{texts} = { 'Fristsetzung' => 'Fristsetzung', 'From' => 'Von', 'From Date' => 'Von', - 'From this version on it is necessary to name a default value.' => 'Ab dieser Version benötigt kivitendo eine Standardwährung.', 'From this version on a new feature is available.' => 'Ab dieser Version ist ein neues Feature verfügbar.', + 'From this version on it is necessary to name a default value.' => 'Ab dieser Version benötigt kivitendo eine Standardwährung.', 'From this version on the partnumber of services, articles and assemblies have to be unique.' => 'Ab dieser Version müssen Artikelnummern eindeutig vergeben werden.', 'From this version on the taxkey 0 must have a tax rate of 0 (for DATEV compatibility).' => 'Ab dieser Version muss der Steuerschlüssel 0 einen Steuersatz von 0% haben (auf Grund der DATEV-Kompatibilität).', 'Full Access' => 'Vollzugriff',