From: Bernd Bleßmann Date: Wed, 16 Oct 2013 15:06:55 +0000 (+0200) Subject: Beim CSV-Import Einträge in die Historie machen. X-Git-Tag: release-3.1.0beta1~31^2~3^2 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=ec4aa5bbad60c76fd7b898fcbbdf2de705a055c4;p=kivitendo-erp.git Beim CSV-Import Einträge in die Historie machen. Fixt #1998. --- diff --git a/SL/BackgroundJob/CsvImport.pm b/SL/BackgroundJob/CsvImport.pm index ae7112384..7df8b9b47 100644 --- a/SL/BackgroundJob/CsvImport.pm +++ b/SL/BackgroundJob/CsvImport.pm @@ -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}; diff --git a/SL/Controller/CsvImport.pm b/SL/Controller/CsvImport.pm index c509e2108..c3b9d99cc 100644 --- a/SL/Controller/CsvImport.pm +++ b/SL/Controller/CsvImport.pm @@ -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) { diff --git a/SL/Controller/CsvImport/Base.pm b/SL/Controller/CsvImport/Base.pm index db6dc4d87..b3b9368c7 100644 --- a/SL/Controller/CsvImport/Base.pm +++ b/SL/Controller/CsvImport/Base.pm @@ -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;