Revision 01a4e61c
Von Bernd Bleßmann vor fast 11 Jahren hinzugefügt
SL/Controller/CsvImport/BaseMulti.pm | ||
---|---|---|
8 | 8 |
|
9 | 9 |
use parent qw(SL::Controller::CsvImport::Base); |
10 | 10 |
|
11 |
use Rose::Object::MakeMethods::Generic |
|
12 |
( |
|
13 |
'scalar --get_set_init' => [ qw(cvar_configs_by cvar_columns_by) ], |
|
14 |
); |
|
15 |
|
|
11 | 16 |
sub run { |
12 | 17 |
my ($self, %params) = @_; |
13 | 18 |
|
... | ... | |
124 | 129 |
} |
125 | 130 |
} |
126 | 131 |
|
132 |
sub add_cvar_raw_data_columns { |
|
133 |
my ($self) = @_; |
|
134 |
|
|
135 |
foreach my $data (@{ $self->controller->data }) { |
|
136 |
my $ri = $data->{raw_data}->{datatype}; |
|
137 |
map { $self->add_raw_data_columns($ri, $_) if exists $data->{raw_data}->{$_} } @{ $self->cvar_columns_by->{row_ident}->{$ri} }; |
|
138 |
} |
|
139 |
} |
|
140 |
|
|
141 |
sub init_cvar_configs_by { |
|
142 |
# Must be overridden by derived specialized importer classes. |
|
143 |
return {}; |
|
144 |
} |
|
145 |
|
|
146 |
sub init_cvar_columns_by { |
|
147 |
my ($self) = @_; |
|
148 |
|
|
149 |
my $ccb; |
|
150 |
foreach my $p (@{ $self->profile }) { |
|
151 |
my $ri = $p->{row_ident}; |
|
152 |
$ccb->{row_ident}->{$ri} = [ map { "cvar_" . $_->name } (@{ $self->cvar_configs_by->{row_ident}->{$ri} }) ]; |
|
153 |
} |
|
154 |
|
|
155 |
return $ccb; |
|
156 |
} |
|
157 |
|
|
158 |
sub handle_cvars { |
|
159 |
my ($self, $entry, %params) = @_; |
|
160 |
|
|
161 |
my %type_to_column = ( text => 'text_value', |
|
162 |
textfield => 'text_value', |
|
163 |
select => 'text_value', |
|
164 |
date => 'timestamp_value_as_date', |
|
165 |
timestamp => 'timestamp_value_as_date', |
|
166 |
number => 'number_value_as_number', |
|
167 |
bool => 'bool_value' ); |
|
168 |
|
|
169 |
$params{sub_module} ||= ''; |
|
170 |
my @cvars; |
|
171 |
foreach my $config (@{ $self->cvar_configs_by->{row_ident}->{$entry->{raw_data}->{datatype}} }) { |
|
172 |
next unless exists $entry->{raw_data}->{ "cvar_" . $config->name }; |
|
173 |
my $value = $entry->{raw_data}->{ "cvar_" . $config->name }; |
|
174 |
my $column = $type_to_column{ $config->type } || die "Program logic error: unknown custom variable storage type"; |
|
175 |
|
|
176 |
push @cvars, SL::DB::CustomVariable->new(config_id => $config->id, $column => $value, sub_module => $params{sub_module}); |
|
177 |
} |
|
178 |
|
|
179 |
$entry->{object}->custom_variables(\@cvars) if @cvars; |
|
180 |
} |
|
181 |
|
|
127 | 182 |
sub init_profile { |
128 | 183 |
my ($self) = @_; |
129 | 184 |
|
... | ... | |
145 | 200 |
$prof{$col} = $name; |
146 | 201 |
} |
147 | 202 |
|
148 |
$prof{ 'cvar_' . $_->name } = '' for @{ $self->all_cvar_configs };
|
|
203 |
$prof{ 'cvar_' . $_->name } = '' for @{ $self->cvar_configs_by->{class}->{$class} };
|
|
149 | 204 |
|
150 | 205 |
$class =~ m/^SL::DB::(.+)/; |
151 | 206 |
push @profile, {'profile' => \%prof, 'class' => $class, 'row_ident' => $::locale->text($1)}; |
... | ... | |
186 | 241 |
} |
187 | 242 |
} |
188 | 243 |
|
244 |
sub add_cvar_columns_to_displayable_columns { |
|
245 |
my ($self, $row_ident) = @_; |
|
246 |
|
|
247 |
$self->add_displayable_columns($row_ident, |
|
248 |
map { { name => 'cvar_' . $_->name, |
|
249 |
description => $::locale->text('#1 (custom variable)', $_->description) } } |
|
250 |
@{ $self->cvar_configs_by->{row_ident}->{$row_ident} }); |
|
251 |
} |
|
252 |
|
|
189 | 253 |
sub is_multiplexed { 1 } |
190 | 254 |
|
191 | 255 |
1; |
SL/Controller/CsvImport/Order.pm | ||
---|---|---|
41 | 41 |
} |
42 | 42 |
|
43 | 43 |
|
44 |
sub init_cvar_configs_by { |
|
45 |
my ($self) = @_; |
|
46 |
|
|
47 |
my $item_cvar_configs = SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'IC' ]); |
|
48 |
$item_cvar_configs = [grep { $_->has_flag('editable') } @{ $item_cvar_configs }]; |
|
49 |
|
|
50 |
my $ccb; |
|
51 |
$ccb->{class}->{'SL::DB::Order'} = []; |
|
52 |
$ccb->{class}->{'SL::DB::OrderItem'} = $item_cvar_configs; |
|
53 |
$ccb->{row_ident}->{$self->_order_column} = []; |
|
54 |
$ccb->{row_ident}->{$self->_item_column} = $item_cvar_configs; |
|
55 |
|
|
56 |
return $ccb; |
|
57 |
} |
|
58 |
|
|
59 |
|
|
44 | 60 |
sub init_profile { |
45 | 61 |
my ($self) = @_; |
46 | 62 |
|
... | ... | |
123 | 139 |
{ name => 'shipto_id', description => $::locale->text('Ship to (database ID)') }, |
124 | 140 |
); |
125 | 141 |
|
142 |
$self->add_cvar_columns_to_displayable_columns($self->_item_column); |
|
143 |
|
|
126 | 144 |
$self->add_displayable_columns($self->_item_column, |
127 | 145 |
{ name => 'datatype', description => $self->_item_column }, |
128 | 146 |
{ name => 'cusordnumber', description => $::locale->text('Customer Order Number') }, |
... | ... | |
247 | 265 |
} elsif ($entry->{raw_data}->{datatype} eq $self->_item_column && $entry->{object}->can('part')) { |
248 | 266 |
$self->handle_item($entry); |
249 | 267 |
} |
268 |
$self->handle_cvars($entry, sub_module => 'orderitems'); |
|
250 | 269 |
|
251 | 270 |
} continue { |
252 | 271 |
$i++; |
... | ... | |
267 | 286 |
map { "${_}_id" } grep { exists $self->controller->data->[1]->{raw_data}->{$_} } qw(project price_factor pricegroup)); |
268 | 287 |
$self->add_columns($self->_item_column, 'project_id') if exists $self->controller->data->[1]->{raw_data}->{projectnumber}; |
269 | 288 |
|
289 |
$self->add_cvar_raw_data_columns(); |
|
270 | 290 |
|
271 | 291 |
$self->add_items_to_order(); |
272 | 292 |
$self->handle_prices_and_taxes(); |
Auch abrufbar als: Unified diff
benutzerdef. Variable behandeln.