From 0de514ad672b52435b74b12002a8000ebc883321 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Fri, 16 Aug 2013 16:05:17 +0200 Subject: [PATCH] =?utf8?q?W=C3=A4hrung=20auf=20Kundenw=C3=A4hrung=20setzte?= =?utf8?q?n,=20wenn=20nicht=20angegeben.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/CsvImport/Order.pm | 42 ++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/SL/Controller/CsvImport/Order.pm b/SL/Controller/CsvImport/Order.pm index e46c14170..e50b197c8 100644 --- a/SL/Controller/CsvImport/Order.pm +++ b/SL/Controller/CsvImport/Order.pm @@ -24,7 +24,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 departments_by projects_by ct_shiptos_by taxzones_by price_factors_by pricegroups_by) ], + 'scalar --get_set_init' => [ qw(settings languages_by parts_by contacts_by departments_by projects_by ct_shiptos_by taxzones_by price_factors_by pricegroups_by currencies_by) ], ); @@ -81,7 +81,8 @@ sub setup_displayable_columns { $self->add_displayable_columns($self->settings->{'order_column'}, { name => 'datatype', description => $self->settings->{'order_column'} }, { name => 'closed', description => $::locale->text('Closed') }, - { name => 'curr', description => $::locale->text('Currency') }, + { name => 'currency', description => $::locale->text('Currency') }, + { name => 'currency_id', description => $::locale->text('Currency (database ID)') }, { name => 'cusordnumber', description => $::locale->text('Customer Order Number') }, { name => 'delivered', description => $::locale->text('Delivered') }, { name => 'employee_id', description => $::locale->text('Employee (database ID)') }, @@ -225,6 +226,12 @@ sub init_pricegroups_by { return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_pricegroups } } ) } qw(id pricegroup) }; } +sub init_currencies_by { + my ($self) = @_; + + return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_currencies } } ) } qw(id name) }; +} + sub check_objects { my ($self) = @_; @@ -255,10 +262,11 @@ sub check_objects { $self->check_project($entry, global => 1); $self->check_ct_shipto($entry); $self->check_taxzone($entry); + $self->check_currency($entry); if ($vc_obj) { # copy from customer if not given - foreach (qw(payment_id language_id taxzone_id)) { + foreach (qw(payment_id language_id taxzone_id currency_id)) { $entry->{object}->$_($vc_obj->$_) unless $entry->{object}->$_; } } @@ -285,7 +293,7 @@ sub check_objects { { header => $::locale->text('Customer/Vendor'), method => 'vc_name' }); # Todo: access via ->[0] ok? Better: search first order column and use this $self->add_columns($self->settings->{'order_column'}, - map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw(payment language department globalproject taxzone cp)); + map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw(payment language department globalproject taxzone cp currency)); $self->add_columns($self->settings->{'order_column'}, 'globalproject_id') if exists $self->controller->data->[0]->{raw_data}->{globalprojectnumber}; $self->add_columns($self->settings->{'order_column'}, 'cp_id') if exists $self->controller->data->[0]->{raw_data}->{contact}; @@ -615,7 +623,6 @@ sub check_taxzone { return 1; } - sub check_price_factor { my ($self, $entry) = @_; @@ -666,6 +673,31 @@ sub check_pricegroup { 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); + } + + return 1; +} + sub save_objects { my ($self, %params) = @_; -- 2.20.1