CSV-Import für benutzerdefinierte Variablen gefixt
[kivitendo-erp.git] / SL / Controller / CsvImport / Base.pm
index b6bf801..5aa6066 100644 (file)
@@ -9,12 +9,13 @@ use SL::DB::Customer;
 use SL::DB::Language;
 use SL::DB::PaymentTerm;
 use SL::DB::Vendor;
+use SL::DB::Contact;
 
 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) ],
 );
 
@@ -30,6 +31,10 @@ sub run {
                                   strict_profile         => 1,
                                   map { ( $_ => $self->controller->profile->get($_) ) } qw(sep_char escape_char quote_char),
                                  ));
+
+  my $old_numberformat      = $::myconfig{numberformat};
+  $::myconfig{numberformat} = $self->controller->profile->get('numberformat');
+
   $self->csv->parse;
 
   $self->controller->errors([ $self->csv->errors ]) if $self->csv->errors;
@@ -50,6 +55,8 @@ sub run {
   $self->check_objects;
   $self->check_duplicates if $self->controller->profile->get('duplicates', 'no_check') ne 'no_check';
   $self->fix_field_lengths;
+
+  $::myconfig{numberformat} = $old_numberformat;
 }
 
 sub add_columns {
@@ -178,7 +185,7 @@ sub handle_cvars {
     my $value  = $entry->{raw_data}->{ "cvar_" . $config->name };
     my $column = $type_to_column{ $config->type } || die "Program logic error: unknown custom variable storage type";
 
-    push @cvars, SL::DB::CustomVariable->new(config_id => $config->id, $column => $value);
+    push @cvars, SL::DB::CustomVariable->new(config_id => $config->id, $column => $value, sub_module => '');
   }
 
   $entry->{object}->custom_variables(\@cvars);
@@ -296,7 +303,9 @@ sub save_objects {
   foreach my $entry (@{ $data }) {
     next if @{ $entry->{errors} };
 
-    if (!$entry->{object}->save) {
+    my $object = $entry->{object_to_save} || $entry->{object};
+
+    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);