From: Thomas Heck Date: Mon, 20 Aug 2012 12:54:01 +0000 (+0200) Subject: Part-CSV-Import: Bei Update model_X und lastcost_X bei make_X berücksichtigen X-Git-Tag: release-3.0.0beta1~280 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=00b9499e32bdf89676f1933cbd4cab39502c3210;p=kivitendo-erp.git Part-CSV-Import: Bei Update model_X und lastcost_X bei make_X berücksichtigen implementiert #1901 --- diff --git a/SL/Controller/CsvImport/Base.pm b/SL/Controller/CsvImport/Base.pm index eda921f42..31d1d9ece 100644 --- a/SL/Controller/CsvImport/Base.pm +++ b/SL/Controller/CsvImport/Base.pm @@ -15,7 +15,7 @@ use parent qw(Rose::Object); use Rose::Object::MakeMethods::Generic ( - scalar => [ qw(controller file csv) ], + scalar => [ qw(controller file csv save_with_cascade) ], '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) ], ); @@ -305,7 +305,7 @@ sub save_objects { my $object = $entry->{object_to_save} || $entry->{object}; - if (!$object->save) { + if ( !$object->save(cascade => !!$self->save_with_cascade()) ) { push @{ $entry->{errors} }, $::locale->text('Error when saving: #1', $entry->{object}->db->error); } else { $self->controller->num_imported($self->controller->num_imported + 1); diff --git a/SL/Controller/CsvImport/Part.pm b/SL/Controller/CsvImport/Part.pm index 5d203a9a5..d39927ad9 100644 --- a/SL/Controller/CsvImport/Part.pm +++ b/SL/Controller/CsvImport/Part.pm @@ -367,6 +367,8 @@ sub handle_pricegroups { sub handle_makemodel { my ($self, $entry) = @_; + my $object = $entry->{object}; + my $found_any; my @makemodels; foreach my $idx (map { substr $_, 5 } grep { m/^make_\d+$/ && $entry->{raw_data}->{$_} } keys %{ $entry->{raw_data} }) { @@ -379,6 +381,7 @@ sub handle_makemodel { push @{ $entry->{errors} }, $::locale->text('Error: Invalid vendor in column make_#1', $idx); } else { + $found_any = 1; push @makemodels, SL::DB::MakeModel->new(make => $vendor->id, model => $entry->{raw_data}->{"model_${idx}"}, lastcost_as_number => $entry->{raw_data}->{"lastcost_${idx}"}); @@ -388,8 +391,31 @@ sub handle_makemodel { } } - $entry->{object}->makemodels(\@makemodels); - $entry->{object}->makemodel(scalar(@makemodels) ? 1 : 0); + $object->makemodels(\@makemodels); + $object->makemodel(scalar(@makemodels) ? 1 : 0); + + if ( !$entry->{part} || $self->settings->{article_number_policy} ne 'update_prices' ) { + return; + } + + my %old_makemodels_by_make = map { $_->make => $_ } $entry->{part}->makemodels; + + foreach my $makemodel ($object->makemodels()) { + my $makemodel_orig = $old_makemodels_by_make{$makemodel->make}; + $found_any = 1; + + if ($makemodel_orig) { + $makemodel_orig->model($makemodel->model); + $makemodel_orig->lastcost($makemodel->lastcost); + + } else { + $entry->{part}->add_makemodels($makemodel); + } + } + + $entry->{part}->makemodel($object->makemodel); + + $self->save_with_cascade(1) if $found_any; } sub set_various_fields {