Revision 0af0977d
Von Bernd Bleßmann vor fast 10 Jahren hinzugefügt
SL/Controller/CsvImport/Inventory.pm | ||
---|---|---|
32 | 32 |
my ($self) = @_; |
33 | 33 |
|
34 | 34 |
my $profile = $self->SUPER::init_profile; |
35 |
delete @{$profile}{qw(trans_id oe_id orderitems_id bestbefore trans_type_id project_id)};
|
|
35 |
delete @{$profile}{qw(trans_id oe_id delivery_order_items_stock_id bestbefore trans_type_id project_id)};
|
|
36 | 36 |
|
37 | 37 |
return $profile; |
38 | 38 |
} |
... | ... | |
64 | 64 |
|
65 | 65 |
my $all_bins = SL::DB::Manager::Bin->get_all(); |
66 | 66 |
my $bins_by; |
67 |
$bins_by->{'wh_id+id'} = { map { ( $_->warehouse_id . '+' . $_->id => $_ ) } @{ $all_bins } };
|
|
68 |
$bins_by->{'wh_id+description'} = { map { ( $_->warehouse_id . '+' . $_->description => $_ ) } @{ $all_bins } };
|
|
67 |
$bins_by->{_wh_id_and_id_ident()} = { map { ( _wh_id_and_id_maker($_->warehouse_id, $_->id) => $_ ) } @{ $all_bins } };
|
|
68 |
$bins_by->{_wh_id_and_description_ident()} = { map { ( _wh_id_and_description_maker($_->warehouse_id, $_->description) => $_ ) } @{ $all_bins } };
|
|
69 | 69 |
|
70 | 70 |
return $bins_by; |
71 | 71 |
} |
... | ... | |
172 | 172 |
return 1; |
173 | 173 |
} |
174 | 174 |
|
175 |
# Check bin fior given warehouse, so check_warehouse must be called first.
|
|
175 |
# Check bin for given warehouse, so check_warehouse must be called first. |
|
176 | 176 |
sub check_bin { |
177 | 177 |
my ($self, $entry) = @_; |
178 | 178 |
|
... | ... | |
181 | 181 |
# If bin from front-end is enforced for all transfers, use this, if valid. |
182 | 182 |
if ($self->settings->{apply_bin} eq 'all') { |
183 | 183 |
$object->bin_id(undef); |
184 |
my $bin = $self->bins_by->{'wh_id+description'}->{ $object->warehouse_id . '+' . $self->settings->{bin} };
|
|
184 |
my $bin = $self->bins_by->{_wh_id_and_description_ident()}->{ _wh_id_and_description_maker($object->warehouse_id, $self->settings->{bin}) };
|
|
185 | 185 |
if (!$bin) { |
186 | 186 |
push @{ $entry->{errors} }, $::locale->text('Error: Invalid bin'); |
187 | 187 |
return 0; |
... | ... | |
194 | 194 |
if ( $self->settings->{apply_bin} eq 'missing' |
195 | 195 |
&& ! $object->bin_id |
196 | 196 |
&& ! $entry->{raw_data}->{bin} ) { |
197 |
my $bin = $self->bins_by->{'wh_id+description'}->{ $object->warehouse_id . '+' . $self->settings->{bin} };
|
|
197 |
my $bin = $self->bins_by->{_wh_id_and_description_ident()}->{ _wh_id_and_description_maker($object->warehouse_id, $self->settings->{bin}) };
|
|
198 | 198 |
if (!$bin) { |
199 | 199 |
push @{ $entry->{errors} }, $::locale->text('Error: Invalid bin'); |
200 | 200 |
return 0; |
... | ... | |
204 | 204 |
} |
205 | 205 |
|
206 | 206 |
# Check wether or not bin ID is valid. |
207 |
if ($object->bin_id && !$self->bins_by->{'wh_id+id'}->{ $object->warehouse_id . '+' . $object->bin_id }) {
|
|
207 |
if ($object->bin_id && !$self->bins_by->{_wh_id_and_id_ident()}->{ _wh_id_and_id_maker($object->warehouse_id, $object->bin_id) }) {
|
|
208 | 208 |
push @{ $entry->{errors} }, $::locale->text('Error: Invalid bin'); |
209 | 209 |
return 0; |
210 | 210 |
} |
211 | 211 |
|
212 | 212 |
# Map description to ID if given. |
213 | 213 |
if (!$object->bin_id && $entry->{raw_data}->{bin}) { |
214 |
my $bin = $self->bins_by->{'wh_id+description'}->{ $object->warehouse_id . '+' . $entry->{raw_data}->{bin} };
|
|
214 |
my $bin = $self->bins_by->{_wh_id_and_description_ident()}->{ _wh_id_and_description_maker($object->warehouse_id, $entry->{raw_data}->{bin}) };
|
|
215 | 215 |
if (!$bin) { |
216 | 216 |
push @{ $entry->{errors} }, $::locale->text('Error: Invalid bin'); |
217 | 217 |
return 0; |
... | ... | |
221 | 221 |
} |
222 | 222 |
|
223 | 223 |
if ($object->bin_id) { |
224 |
$entry->{info_data}->{bin} = $self->bins_by->{'wh_id+id'}->{ $object->warehouse_id . '+' . $object->bin_id }->description;
|
|
224 |
$entry->{info_data}->{bin} = $self->bins_by->{_wh_id_and_id_ident()}->{ _wh_id_and_id_maker($object->warehouse_id, $object->bin_id) }->description;
|
|
225 | 225 |
} else { |
226 | 226 |
push @{ $entry->{errors} }, $::locale->text('Error: Bin not found'); |
227 | 227 |
return 0; |
... | ... | |
287 | 287 |
|
288 | 288 |
# Actual quantity is read from stock or is the result of transfers for the |
289 | 289 |
# same part, warehouse and bin done before. |
290 |
my $key = $object->parts_id . '+' . $object->warehouse_id . '+' . $object->bin_id;
|
|
290 |
my $key = join '+', $object->parts_id, $object->warehouse_id, $object->bin_id;
|
|
291 | 291 |
if (!exists $self->{resulting_quantities}->{$key}) { |
292 | 292 |
my $stock = $object->part->get_simple_stock; |
293 | 293 |
my @stocked = grep { $_->{warehouse_id} == $object->warehouse_id && $_->{bin_id} == $object->bin_id } @$stock; |
... | ... | |
398 | 398 |
$self->SUPER::save_objects(%params); |
399 | 399 |
} |
400 | 400 |
|
401 |
sub _wh_id_and_description_ident { |
|
402 |
return 'wh_id+description'; |
|
403 |
} |
|
404 |
|
|
405 |
sub _wh_id_and_description_maker { |
|
406 |
return join '+', $_[0], $_[1] |
|
407 |
} |
|
408 |
|
|
409 |
sub _wh_id_and_id_ident { |
|
410 |
return 'wh_id+id'; |
|
411 |
} |
|
412 |
|
|
413 |
sub _wh_id_and_id_maker { |
|
414 |
return join '+', $_[0], $_[1] |
|
415 |
} |
|
416 |
|
|
401 | 417 |
1; |
Auch abrufbar als: Unified diff
Lagerbewegungs-Import: Hash-Keys über Subroutines erzeugen, um Tippfehler zu vermeiden/erkennen.