From: Moritz Bunkus Date: Wed, 2 Mar 2011 15:30:56 +0000 (+0100) Subject: Anzeigen und Importieren von benutzerdefinierten Variablen bei Kunden, Lieferanten... X-Git-Tag: release-2.7.0beta1~396^2~26 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=e055b3ff9423767fd109a8d7a36d354c8997c941;p=kivitendo-erp.git Anzeigen und Importieren von benutzerdefinierten Variablen bei Kunden, Lieferanten, Artikeln --- diff --git a/SL/Controller/CsvImport/Base.pm b/SL/Controller/CsvImport/Base.pm index 0381b4b0b..91efaaaac 100644 --- a/SL/Controller/CsvImport/Base.pm +++ b/SL/Controller/CsvImport/Base.pm @@ -11,7 +11,7 @@ use parent qw(Rose::Object); use Rose::Object::MakeMethods::Generic ( scalar => [ qw(controller file csv) ], - 'scalar --get_set_init' => [ qw(profile existing_objects class manager_class) ], + 'scalar --get_set_init' => [ qw(profile existing_objects class manager_class cvar_columns all_cvar_configs) ], ); sub run { @@ -72,6 +72,43 @@ sub add_raw_data_columns { } } +sub add_cvar_raw_data_columns { + my ($self) = @_; + + map { $self->add_raw_data_columns($_) if exists $self->controller->data->[0]->{raw_data}->{$_} } @{ $self->cvar_columns }; +} + +sub init_cvar_columns { + my ($self) = @_; + + return [ map { "cvar_" . $_->name } (@{ $self->all_cvar_configs }) ]; +} + +sub handle_cvars { + my ($self, $entry) = @_; + + return unless $self->can('all_cvar_configs'); + + my %type_to_column = ( text => 'text_value', + textfield => 'text_value', + select => 'text_value', + date => 'timestamp_value_as_date', + timestamp => 'timestamp_value_as_date', + number => 'number_value_as_number', + bool => 'bool_value' ); + + my @cvars; + foreach my $config (@{ $self->all_cvar_configs }) { + next unless exists $entry->{raw_data}->{ "cvar_" . $config->name }; + 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); + } + + $entry->{object}->custom_variables(\@cvars); +} + sub init_profile { my ($self) = @_; diff --git a/SL/Controller/CsvImport/CustomerVendor.pm b/SL/Controller/CsvImport/CustomerVendor.pm index 9cb115745..a82af654a 100644 --- a/SL/Controller/CsvImport/CustomerVendor.pm +++ b/SL/Controller/CsvImport/CustomerVendor.pm @@ -3,6 +3,8 @@ package SL::Controller::CsvImport::CustomerVendor; use strict; use SL::Helper::Csv; +use SL::DB::CustomVariable; +use SL::DB::CustomVariableConfig; use parent qw(SL::Controller::CsvImport::Base); @@ -21,6 +23,12 @@ sub init_class { $self->class('SL::DB::' . ucfirst($self->table)); } +sub init_all_cvar_configs { + my ($self) = @_; + + return SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'CT' ]); +} + sub check_objects { my ($self) = @_; @@ -43,7 +51,11 @@ sub check_objects { } else { $vcs_by_number{ $object->$numbercolumn } = $object; } + + $self->handle_cvars($entry); } + + $self->add_cvar_raw_data_columns; } sub check_duplicates { @@ -103,4 +115,10 @@ sub field_lengths { ); } +# TODO: +# Kundentyp +# salesman_id +# Sprache +# Zahlungsbedingungen + 1; diff --git a/SL/Controller/CsvImport/Part.pm b/SL/Controller/CsvImport/Part.pm index e92cbfaa6..9746b7e64 100644 --- a/SL/Controller/CsvImport/Part.pm +++ b/SL/Controller/CsvImport/Part.pm @@ -5,6 +5,8 @@ use strict; use SL::Helper::Csv; use SL::DB::Buchungsgruppe; +use SL::DB::CustomVariable; +use SL::DB::CustomVariableConfig; use SL::DB::Language; use SL::DB::PartsGroup; use SL::DB::PaymentTerm; @@ -17,8 +19,8 @@ use parent qw(SL::Controller::CsvImport::Base); use Rose::Object::MakeMethods::Generic ( scalar => [ qw(table) ], - 'scalar --get_set_init' => [ qw(bg_by settings parts_by price_factors_by units_by payment_terms_by packing_types_by partsgroups_by all_languages - translation_columns) ], + 'scalar --get_set_init' => [ qw(bg_by settings parts_by price_factors_by units_by payment_terms_by packing_types_by partsgroups_by + all_languages translation_columns) ], ); sub init_class { @@ -97,6 +99,12 @@ sub init_all_languages { return SL::DB::Manager::Language->get_all; } +sub init_all_cvar_configs { + my ($self) = @_; + + return SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'IC' ]); +} + sub init_translation_columns { my ($self) = @_; @@ -123,6 +131,7 @@ sub check_objects { $self->handle_prices($entry) if $self->settings->{sellprice_adjustment}; $self->handle_shoparticle($entry); $self->handle_translations($entry); + $self->handle_cvars($entry); $self->set_various_fields($entry); } @@ -130,7 +139,7 @@ sub check_objects { $self->add_columns(qw(buchungsgruppen_id unit)); $self->add_columns(map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw (price_factor payment packing_type partsgroup)); $self->add_columns(qw(shop)) if $self->settings->{shoparticle_if_missing}; - + $self->add_cvar_raw_data_columns; map { $self->add_raw_data_columns($_) if exists $self->controller->data->[0]->{raw_data}->{$_} } @{ $self->translation_columns }; } @@ -417,7 +426,4 @@ sub save_objects { $self->SUPER::save_objects(data => $without_number); } -# TODO: -# CVARs ins Profil rein - 1;