Revision 00b9499e
Von Thomas Heck vor etwa 12 Jahren hinzugefügt
SL/Controller/CsvImport/Base.pm | ||
---|---|---|
15 | 15 |
|
16 | 16 |
use Rose::Object::MakeMethods::Generic |
17 | 17 |
( |
18 |
scalar => [ qw(controller file csv) ], |
|
18 |
scalar => [ qw(controller file csv save_with_cascade) ],
|
|
19 | 19 |
'scalar --get_set_init' => [ qw(profile displayable_columns existing_objects class manager_class cvar_columns all_cvar_configs all_languages payment_terms_by all_vc vc_by) ], |
20 | 20 |
); |
21 | 21 |
|
... | ... | |
305 | 305 |
|
306 | 306 |
my $object = $entry->{object_to_save} || $entry->{object}; |
307 | 307 |
|
308 |
if (!$object->save) {
|
|
308 |
if ( !$object->save(cascade => !!$self->save_with_cascade()) ) {
|
|
309 | 309 |
push @{ $entry->{errors} }, $::locale->text('Error when saving: #1', $entry->{object}->db->error); |
310 | 310 |
} else { |
311 | 311 |
$self->controller->num_imported($self->controller->num_imported + 1); |
SL/Controller/CsvImport/Part.pm | ||
---|---|---|
367 | 367 |
|
368 | 368 |
sub handle_makemodel { |
369 | 369 |
my ($self, $entry) = @_; |
370 |
my $object = $entry->{object}; |
|
371 |
my $found_any; |
|
370 | 372 |
|
371 | 373 |
my @makemodels; |
372 | 374 |
foreach my $idx (map { substr $_, 5 } grep { m/^make_\d+$/ && $entry->{raw_data}->{$_} } keys %{ $entry->{raw_data} }) { |
... | ... | |
379 | 381 |
push @{ $entry->{errors} }, $::locale->text('Error: Invalid vendor in column make_#1', $idx); |
380 | 382 |
|
381 | 383 |
} else { |
384 |
$found_any = 1; |
|
382 | 385 |
push @makemodels, SL::DB::MakeModel->new(make => $vendor->id, |
383 | 386 |
model => $entry->{raw_data}->{"model_${idx}"}, |
384 | 387 |
lastcost_as_number => $entry->{raw_data}->{"lastcost_${idx}"}); |
... | ... | |
388 | 391 |
} |
389 | 392 |
} |
390 | 393 |
|
391 |
$entry->{object}->makemodels(\@makemodels); |
|
392 |
$entry->{object}->makemodel(scalar(@makemodels) ? 1 : 0); |
|
394 |
$object->makemodels(\@makemodels); |
|
395 |
$object->makemodel(scalar(@makemodels) ? 1 : 0); |
|
396 |
|
|
397 |
if ( !$entry->{part} || $self->settings->{article_number_policy} ne 'update_prices' ) { |
|
398 |
return; |
|
399 |
} |
|
400 |
|
|
401 |
my %old_makemodels_by_make = map { $_->make => $_ } $entry->{part}->makemodels; |
|
402 |
|
|
403 |
foreach my $makemodel ($object->makemodels()) { |
|
404 |
my $makemodel_orig = $old_makemodels_by_make{$makemodel->make}; |
|
405 |
$found_any = 1; |
|
406 |
|
|
407 |
if ($makemodel_orig) { |
|
408 |
$makemodel_orig->model($makemodel->model); |
|
409 |
$makemodel_orig->lastcost($makemodel->lastcost); |
|
410 |
|
|
411 |
} else { |
|
412 |
$entry->{part}->add_makemodels($makemodel); |
|
413 |
} |
|
414 |
} |
|
415 |
|
|
416 |
$entry->{part}->makemodel($object->makemodel); |
|
417 |
|
|
418 |
$self->save_with_cascade(1) if $found_any; |
|
393 | 419 |
} |
394 | 420 |
|
395 | 421 |
sub set_various_fields { |
Auch abrufbar als: Unified diff
Part-CSV-Import: Bei Update model_X und lastcost_X bei make_X berücksichtigen
implementiert #1901