From ec4aa5bbad60c76fd7b898fcbbdf2de705a055c4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Wed, 16 Oct 2013 17:06:55 +0200 Subject: [PATCH] =?utf8?q?Beim=20CSV-Import=20Eintr=C3=A4ge=20in=20die=20H?= =?utf8?q?istorie=20machen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fixt #1998. --- SL/BackgroundJob/CsvImport.pm | 1 + SL/Controller/CsvImport.pm | 9 +++++---- SL/Controller/CsvImport/Base.pm | 22 +++++++++++++++++++++- 3 files changed, 27 insertions(+), 5 deletions(-) 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; -- 2.20.1