Revision 35948584
Von Moritz Bunkus vor mehr als 13 Jahren hinzugefügt
SL/Controller/CsvImport.pm | ||
---|---|---|
18 | 18 |
use Rose::Object::MakeMethods::Generic |
19 | 19 |
( |
20 | 20 |
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 |
21 |
import_status errors headers data num_imported num_importable) ], |
|
21 |
import_status errors headers raw_data_headers data num_imported num_importable) ],
|
|
22 | 22 |
); |
23 | 23 |
|
24 | 24 |
__PACKAGE__->run_before('check_auth'); |
SL/Controller/CsvImport/Base.pm | ||
---|---|---|
36 | 36 |
$headers->{methods} = [ map { $profile->{$_} } @{ $headers->{headers} } ]; |
37 | 37 |
$headers->{used} = { map { ($_ => 1) } @{ $headers->{headers} } }; |
38 | 38 |
$self->controller->headers($headers); |
39 |
$self->controller->raw_data_headers({ used => { }, headers => [ ] }); |
|
39 | 40 |
|
40 | 41 |
# my @data; |
41 | 42 |
# foreach my $object ($self->csv->get_objects) |
... | ... | |
60 | 61 |
} |
61 | 62 |
} |
62 | 63 |
|
64 |
sub add_raw_data_columns { |
|
65 |
my ($self, @columns) = @_; |
|
66 |
|
|
67 |
my $h = $self->controller->raw_data_headers; |
|
68 |
|
|
69 |
foreach my $column (grep { !$h->{used}->{$_} } @columns) { |
|
70 |
$h->{used}->{$column} = 1; |
|
71 |
push @{ $h->{headers} }, $column; |
|
72 |
} |
|
73 |
} |
|
74 |
|
|
63 | 75 |
sub init_profile { |
64 | 76 |
my ($self) = @_; |
65 | 77 |
|
SL/Controller/CsvImport/Part.pm | ||
---|---|---|
5 | 5 |
use SL::Helper::Csv; |
6 | 6 |
|
7 | 7 |
use SL::DB::Buchungsgruppe; |
8 |
use SL::DB::Language; |
|
8 | 9 |
use SL::DB::PartsGroup; |
9 | 10 |
use SL::DB::PaymentTerm; |
10 | 11 |
use SL::DB::PriceFactor; |
12 |
use SL::DB::Translation; |
|
11 | 13 |
use SL::DB::Unit; |
12 | 14 |
|
13 | 15 |
use parent qw(SL::Controller::CsvImport::Base); |
... | ... | |
15 | 17 |
use Rose::Object::MakeMethods::Generic |
16 | 18 |
( |
17 | 19 |
scalar => [ qw(table) ], |
18 |
'scalar --get_set_init' => [ qw(bg_by settings parts_by price_factors_by units_by payment_terms_by packing_types_by partsgroups_by) ], |
|
20 |
'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 |
|
21 |
translation_columns) ], |
|
19 | 22 |
); |
20 | 23 |
|
21 | 24 |
sub init_class { |
... | ... | |
88 | 91 |
shoparticle_if_missing parts_type) }; |
89 | 92 |
} |
90 | 93 |
|
94 |
sub init_all_languages { |
|
95 |
my ($self) = @_; |
|
96 |
|
|
97 |
return SL::DB::Manager::Language->get_all; |
|
98 |
} |
|
99 |
|
|
100 |
sub init_translation_columns { |
|
101 |
my ($self) = @_; |
|
102 |
|
|
103 |
return [ map { ("description_" . $_->article_code, "notes_" . $_->article_code) } (@{ $self->all_languages }) ]; |
|
104 |
} |
|
105 |
|
|
91 | 106 |
sub check_objects { |
92 | 107 |
my ($self) = @_; |
93 | 108 |
|
... | ... | |
107 | 122 |
$self->check_existing($entry); |
108 | 123 |
$self->handle_prices($entry) if $self->settings->{sellprice_adjustment}; |
109 | 124 |
$self->handle_shoparticle($entry); |
125 |
$self->handle_translations($entry); |
|
110 | 126 |
$self->set_various_fields($entry); |
111 | 127 |
} |
112 | 128 |
|
... | ... | |
114 | 130 |
$self->add_columns(qw(buchungsgruppen_id unit)); |
115 | 131 |
$self->add_columns(map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw (price_factor payment packing_type partsgroup)); |
116 | 132 |
$self->add_columns(qw(shop)) if $self->settings->{shoparticle_if_missing}; |
133 |
|
|
134 |
map { $self->add_raw_data_columns($_) if exists $self->controller->data->[0]->{raw_data}->{$_} } @{ $self->translation_columns }; |
|
117 | 135 |
} |
118 | 136 |
|
119 | 137 |
sub check_duplicates { |
... | ... | |
356 | 374 |
return 1; |
357 | 375 |
} |
358 | 376 |
|
377 |
sub handle_translations { |
|
378 |
my ($self, $entry) = @_; |
|
379 |
|
|
380 |
my @translations; |
|
381 |
foreach my $language (@{ $self->all_languages }) { |
|
382 |
my ($desc, $notes) = @{ $entry->{raw_data} }{ "description_" . $language->article_code, "notes_" . $language->article_code }; |
|
383 |
next unless $desc || $notes; |
|
384 |
|
|
385 |
push @translations, SL::DB::Translation->new(language_id => $language->id, |
|
386 |
translation => $desc, |
|
387 |
longdescription => $notes); |
|
388 |
} |
|
389 |
|
|
390 |
$entry->{object}->translations(\@translations); |
|
391 |
} |
|
392 |
|
|
359 | 393 |
sub set_various_fields { |
360 | 394 |
my ($self, $entry) = @_; |
361 | 395 |
|
templates/webpages/csv_import/_preview.html | ||
---|---|---|
15 | 15 |
[%- FOREACH column = SELF.headers.headers %] |
16 | 16 |
<th>[%- HTML.escape(column) %]</th> |
17 | 17 |
[%- END %] |
18 |
[%- FOREACH column = SELF.raw_data_headers.headers %] |
|
19 |
<th>[%- HTML.escape(column) %]</th> |
|
20 |
[%- END %] |
|
18 | 21 |
<th>[%- LxERP.t8('Notes') %]</th> |
19 | 22 |
</tr> |
20 | 23 |
|
... | ... | |
23 | 26 |
[%- FOREACH method = SELF.headers.methods %] |
24 | 27 |
<td>[%- HTML.escape(row.object.$method) %]</td> |
25 | 28 |
[%- END %] |
29 |
[%- FOREACH method = SELF.raw_data_headers.headers %] |
|
30 |
<td>[%- HTML.escape(row.raw_data.$method) %]</td> |
|
31 |
[%- END %] |
|
26 | 32 |
<td> |
27 | 33 |
[%- FOREACH error = row.errors %][%- HTML.escape(error) %][% UNLESS loop.last %]<br>[%- END %][%- END %] |
28 | 34 |
</td> |
Auch abrufbar als: Unified diff
Anzeige und Import von übersetzten Artikeltexten und Bemerkungen