Beim CSV-Import Einträge in die Historie machen.
authorBernd Bleßmann <bernd@kivitendo-premium.de>
Wed, 16 Oct 2013 15:06:55 +0000 (17:06 +0200)
committerBernd Bleßmann <bernd@kivitendo-premium.de>
Wed, 16 Oct 2013 15:06:55 +0000 (17:06 +0200)
Fixt #1998.

SL/BackgroundJob/CsvImport.pm
SL/Controller/CsvImport.pm
SL/Controller/CsvImport/Base.pm

index ae71123..7df8b9b 100644 (file)
@@ -61,6 +61,7 @@ sub do_import {
 
   $c->profile($self->profile);
   $c->type($job->data_as_hash->{type});
+  $c->{employee_id} = $job->data_as_hash->{employee_id};
 
   my $test = $job->data_as_hash->{test};
 
index c509e21..c3b9d99 100644 (file)
@@ -272,10 +272,11 @@ sub test_and_import_deferred {
   }
 
   $self->{background_job} = SL::BackgroundJob::CsvImport->create_job(
-    file    => $self->csv_file_name,
-    profile => $self->profile,
-    type    => $self->profile->type,
-    test    => $params{test},
+    file        => $self->csv_file_name,
+    profile     => $self->profile,
+    type        => $self->profile->type,
+    test        => $params{test},
+    employee_id => SL::DB::Manager::Employee->current->id,
   )->save;
 
   if ($self->task_server->is_running) {
index db6dc4d..b3b9368 100644 (file)
@@ -2,7 +2,7 @@ package SL::Controller::CsvImport::Base;
 
 use strict;
 
-use List::MoreUtils qw(pairwise);
+use List::MoreUtils qw(pairwise any);
 
 use SL::Helper::Csv;
 use SL::DB::Currency;
@@ -11,6 +11,7 @@ use SL::DB::Language;
 use SL::DB::PaymentTerm;
 use SL::DB::Vendor;
 use SL::DB::Contact;
+use SL::DB::History;
 
 use parent qw(Rose::Object);
 
@@ -415,6 +416,7 @@ sub save_objects {
     if ( !$object->save(cascade => !!$self->save_with_cascade()) ) {
       push @{ $entry->{errors} }, $::locale->text('Error when saving: #1', $entry->{object}->db->error);
     } else {
+      $self->_save_history($object);
       $self->controller->num_imported($self->controller->num_imported + 1);
     }
   } continue {
@@ -457,4 +459,22 @@ sub clean_fields {
   return @cleaned_fields;
 }
 
+sub _save_history {
+  my ($self, $object) = @_;
+
+  if (any { $_ eq $self->controller->{type} } qw(parts customers_vendors)) {
+    my $snumbers = $self->controller->{type} eq 'parts'             ? 'partnumber_' . $object->partnumber
+                 : $self->controller->{type} eq 'customers_vendors' ?
+                     ($self->table eq 'customer' ? 'customernumber_' . $object->customernumber : 'vendornumber_' . $object->vendornumber)
+                 : '';
+
+    SL::DB::History->new(
+      trans_id    => $object->id,
+      snumbers    => $snumbers,
+      employee_id => $self->controller->{employee_id},
+      addition    => 'SAVED',
+    )->save();
+  }
+}
+
 1;