Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision e055b3ff

Von Moritz Bunkus vor mehr als 13 Jahren hinzugefügt

  • ID e055b3ff9423767fd109a8d7a36d354c8997c941
  • Vorgänger 39e13b0f
  • Nachfolger 1c84c7f2

Anzeigen und Importieren von benutzerdefinierten Variablen bei Kunden, Lieferanten, Artikeln

Unterschiede anzeigen:

SL/Controller/CsvImport/Base.pm
11 11
use Rose::Object::MakeMethods::Generic
12 12
(
13 13
 scalar                  => [ qw(controller file csv) ],
14
 'scalar --get_set_init' => [ qw(profile existing_objects class manager_class) ],
14
 'scalar --get_set_init' => [ qw(profile existing_objects class manager_class cvar_columns all_cvar_configs) ],
15 15
);
16 16

  
17 17
sub run {
......
72 72
  }
73 73
}
74 74

  
75
sub add_cvar_raw_data_columns {
76
  my ($self) = @_;
77

  
78
  map { $self->add_raw_data_columns($_) if exists $self->controller->data->[0]->{raw_data}->{$_} } @{ $self->cvar_columns };
79
}
80

  
81
sub init_cvar_columns {
82
  my ($self) = @_;
83

  
84
  return [ map { "cvar_" . $_->name } (@{ $self->all_cvar_configs }) ];
85
}
86

  
87
sub handle_cvars {
88
  my ($self, $entry) = @_;
89

  
90
  return unless $self->can('all_cvar_configs');
91

  
92
  my %type_to_column = ( text      => 'text_value',
93
                         textfield => 'text_value',
94
                         select    => 'text_value',
95
                         date      => 'timestamp_value_as_date',
96
                         timestamp => 'timestamp_value_as_date',
97
                         number    => 'number_value_as_number',
98
                         bool      => 'bool_value' );
99

  
100
  my @cvars;
101
  foreach my $config (@{ $self->all_cvar_configs }) {
102
    next unless exists $entry->{raw_data}->{ "cvar_" . $config->name };
103
    my $value  = $entry->{raw_data}->{ "cvar_" . $config->name };
104
    my $column = $type_to_column{ $config->type } || die "Program logic error: unknown custom variable storage type";
105

  
106
    push @cvars, SL::DB::CustomVariable->new(config_id => $config->id, $column => $value);
107
  }
108

  
109
  $entry->{object}->custom_variables(\@cvars);
110
}
111

  
75 112
sub init_profile {
76 113
  my ($self) = @_;
77 114

  
SL/Controller/CsvImport/CustomerVendor.pm
3 3
use strict;
4 4

  
5 5
use SL::Helper::Csv;
6
use SL::DB::CustomVariable;
7
use SL::DB::CustomVariableConfig;
6 8

  
7 9
use parent qw(SL::Controller::CsvImport::Base);
8 10

  
......
21 23
  $self->class('SL::DB::' . ucfirst($self->table));
22 24
}
23 25

  
26
sub init_all_cvar_configs {
27
  my ($self) = @_;
28

  
29
  return SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'CT' ]);
30
}
31

  
24 32
sub check_objects {
25 33
  my ($self) = @_;
26 34

  
......
43 51
    } else {
44 52
      $vcs_by_number{ $object->$numbercolumn } = $object;
45 53
    }
54

  
55
    $self->handle_cvars($entry);
46 56
  }
57

  
58
  $self->add_cvar_raw_data_columns;
47 59
}
48 60

  
49 61
sub check_duplicates {
......
103 115
         );
104 116
}
105 117

  
118
# TODO:
119
# Kundentyp
120
# salesman_id
121
# Sprache
122
# Zahlungsbedingungen
123

  
106 124
1;
SL/Controller/CsvImport/Part.pm
5 5
use SL::Helper::Csv;
6 6

  
7 7
use SL::DB::Buchungsgruppe;
8
use SL::DB::CustomVariable;
9
use SL::DB::CustomVariableConfig;
8 10
use SL::DB::Language;
9 11
use SL::DB::PartsGroup;
10 12
use SL::DB::PaymentTerm;
......
17 19
use Rose::Object::MakeMethods::Generic
18 20
(
19 21
 scalar                  => [ qw(table) ],
20
 '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
21
                                 translation_columns) ],
22
 'scalar --get_set_init' => [ qw(bg_by settings parts_by price_factors_by units_by payment_terms_by packing_types_by partsgroups_by
23
                                 all_languages translation_columns) ],
22 24
);
23 25

  
24 26
sub init_class {
......
97 99
  return SL::DB::Manager::Language->get_all;
98 100
}
99 101

  
102
sub init_all_cvar_configs {
103
  my ($self) = @_;
104

  
105
  return SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'IC' ]);
106
}
107

  
100 108
sub init_translation_columns {
101 109
  my ($self) = @_;
102 110

  
......
123 131
    $self->handle_prices($entry) if $self->settings->{sellprice_adjustment};
124 132
    $self->handle_shoparticle($entry);
125 133
    $self->handle_translations($entry);
134
    $self->handle_cvars($entry);
126 135
    $self->set_various_fields($entry);
127 136
  }
128 137

  
......
130 139
  $self->add_columns(qw(buchungsgruppen_id unit));
131 140
  $self->add_columns(map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw (price_factor payment packing_type partsgroup));
132 141
  $self->add_columns(qw(shop)) if $self->settings->{shoparticle_if_missing};
133

  
142
  $self->add_cvar_raw_data_columns;
134 143
  map { $self->add_raw_data_columns($_) if exists $self->controller->data->[0]->{raw_data}->{$_} } @{ $self->translation_columns };
135 144
}
136 145

  
......
417 426
  $self->SUPER::save_objects(data => $without_number);
418 427
}
419 428

  
420
# TODO:
421
#  CVARs ins Profil rein
422

  
423 429
1;

Auch abrufbar als: Unified diff