From 35948584de818b00974b9dab65682c4d5ceba67f Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 2 Mar 2011 15:12:24 +0100 Subject: [PATCH] =?utf8?q?Anzeige=20und=20Import=20von=20=C3=BCbersetzten?= =?utf8?q?=20Artikeltexten=20und=20Bemerkungen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/CsvImport.pm | 2 +- SL/Controller/CsvImport/Base.pm | 12 +++++++ SL/Controller/CsvImport/Part.pm | 36 ++++++++++++++++++++- templates/webpages/csv_import/_preview.html | 6 ++++ 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/SL/Controller/CsvImport.pm b/SL/Controller/CsvImport.pm index 636709473..757110a55 100644 --- a/SL/Controller/CsvImport.pm +++ b/SL/Controller/CsvImport.pm @@ -18,7 +18,7 @@ use parent qw(SL::Controller::Base); use Rose::Object::MakeMethods::Generic ( scalar => [ qw(type profile file all_profiles all_charsets sep_char all_sep_chars quote_char all_quote_chars escape_char all_escape_chars all_buchungsgruppen - import_status errors headers data num_imported num_importable) ], + import_status errors headers raw_data_headers data num_imported num_importable) ], ); __PACKAGE__->run_before('check_auth'); diff --git a/SL/Controller/CsvImport/Base.pm b/SL/Controller/CsvImport/Base.pm index 152c8da91..0381b4b0b 100644 --- a/SL/Controller/CsvImport/Base.pm +++ b/SL/Controller/CsvImport/Base.pm @@ -36,6 +36,7 @@ sub run { $headers->{methods} = [ map { $profile->{$_} } @{ $headers->{headers} } ]; $headers->{used} = { map { ($_ => 1) } @{ $headers->{headers} } }; $self->controller->headers($headers); + $self->controller->raw_data_headers({ used => { }, headers => [ ] }); # my @data; # foreach my $object ($self->csv->get_objects) @@ -60,6 +61,17 @@ sub add_columns { } } +sub add_raw_data_columns { + my ($self, @columns) = @_; + + my $h = $self->controller->raw_data_headers; + + foreach my $column (grep { !$h->{used}->{$_} } @columns) { + $h->{used}->{$column} = 1; + push @{ $h->{headers} }, $column; + } +} + sub init_profile { my ($self) = @_; diff --git a/SL/Controller/CsvImport/Part.pm b/SL/Controller/CsvImport/Part.pm index 9d0e66ba3..e92cbfaa6 100644 --- a/SL/Controller/CsvImport/Part.pm +++ b/SL/Controller/CsvImport/Part.pm @@ -5,9 +5,11 @@ use strict; use SL::Helper::Csv; use SL::DB::Buchungsgruppe; +use SL::DB::Language; use SL::DB::PartsGroup; use SL::DB::PaymentTerm; use SL::DB::PriceFactor; +use SL::DB::Translation; use SL::DB::Unit; use parent qw(SL::Controller::CsvImport::Base); @@ -15,7 +17,8 @@ use parent qw(SL::Controller::CsvImport::Base); use Rose::Object::MakeMethods::Generic ( scalar => [ qw(table) ], - 'scalar --get_set_init' => [ qw(bg_by settings parts_by price_factors_by units_by payment_terms_by packing_types_by partsgroups_by) ], + 'scalar --get_set_init' => [ qw(bg_by settings parts_by price_factors_by units_by payment_terms_by packing_types_by partsgroups_by all_languages + translation_columns) ], ); sub init_class { @@ -88,6 +91,18 @@ sub init_settings { shoparticle_if_missing parts_type) }; } +sub init_all_languages { + my ($self) = @_; + + return SL::DB::Manager::Language->get_all; +} + +sub init_translation_columns { + my ($self) = @_; + + return [ map { ("description_" . $_->article_code, "notes_" . $_->article_code) } (@{ $self->all_languages }) ]; +} + sub check_objects { my ($self) = @_; @@ -107,6 +122,7 @@ sub check_objects { $self->check_existing($entry); $self->handle_prices($entry) if $self->settings->{sellprice_adjustment}; $self->handle_shoparticle($entry); + $self->handle_translations($entry); $self->set_various_fields($entry); } @@ -114,6 +130,8 @@ sub check_objects { $self->add_columns(qw(buchungsgruppen_id unit)); $self->add_columns(map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw (price_factor payment packing_type partsgroup)); $self->add_columns(qw(shop)) if $self->settings->{shoparticle_if_missing}; + + map { $self->add_raw_data_columns($_) if exists $self->controller->data->[0]->{raw_data}->{$_} } @{ $self->translation_columns }; } sub check_duplicates { @@ -356,6 +374,22 @@ sub check_unit { return 1; } +sub handle_translations { + my ($self, $entry) = @_; + + my @translations; + foreach my $language (@{ $self->all_languages }) { + my ($desc, $notes) = @{ $entry->{raw_data} }{ "description_" . $language->article_code, "notes_" . $language->article_code }; + next unless $desc || $notes; + + push @translations, SL::DB::Translation->new(language_id => $language->id, + translation => $desc, + longdescription => $notes); + } + + $entry->{object}->translations(\@translations); +} + sub set_various_fields { my ($self, $entry) = @_; diff --git a/templates/webpages/csv_import/_preview.html b/templates/webpages/csv_import/_preview.html index 139f4c8b0..08997b945 100644 --- a/templates/webpages/csv_import/_preview.html +++ b/templates/webpages/csv_import/_preview.html @@ -15,6 +15,9 @@ [%- FOREACH column = SELF.headers.headers %] [%- HTML.escape(column) %] [%- END %] + [%- FOREACH column = SELF.raw_data_headers.headers %] + [%- HTML.escape(column) %] + [%- END %] [%- LxERP.t8('Notes') %] @@ -23,6 +26,9 @@ [%- FOREACH method = SELF.headers.methods %] [%- HTML.escape(row.object.$method) %] [%- END %] + [%- FOREACH method = SELF.raw_data_headers.headers %] + [%- HTML.escape(row.raw_data.$method) %] + [%- END %] [%- FOREACH error = row.errors %][%- HTML.escape(error) %][% UNLESS loop.last %]
[%- END %][%- END %] -- 2.20.1