Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 05d72378

Von Moritz Bunkus vor mehr als 13 Jahren hinzugefügt

  • ID 05d7237837da86645b52aa37c592be1a0d8a7eb6
  • Vorgänger 8d87ea57
  • Nachfolger 2225b5be

Bugfixes Artikelimport

Unterschiede anzeigen:

SL/Controller/CsvImport/Base.pm
23 23
                                  class                  => $self->class,
24 24
                                  profile                => $profile,
25 25
                                  ignore_unknown_columns => 1,
26
                                  strict_profile         => 1,
26 27
                                  map { ( $_ => $self->controller->profile->get($_) ) } qw(sep_char escape_char quote_char),
27 28
                                 ));
28 29
  $self->csv->parse;
SL/Controller/CsvImport/Part.pm
93 93

  
94 94
  return unless @{ $self->controller->data };
95 95

  
96
  $self->add_columns(qw(type)) if $self->settings->{parts_type} eq 'mixed';
97
  $self->add_columns(qw(buchungsgruppen_id unit));
98
  $self->add_columns(map { "${_}_id" } grep { exists $self->controller->data->[0]->{$_} } qw (price_factor payment packing_type partsgroup));
99

  
100 96
  foreach my $entry (@{ $self->controller->data }) {
101 97
    my $object   = $entry->{object};
102 98
    my $raw_data = $entry->{raw_data};
......
113 109
    $self->handle_shoparticle($entry);
114 110
    $self->set_various_fields($entry);
115 111
  }
112

  
113
  $self->add_columns(qw(type)) if $self->settings->{parts_type} eq 'mixed';
114
  $self->add_columns(qw(buchungsgruppen_id unit));
115
  $self->add_columns(map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw (price_factor payment packing_type partsgroup));
116
  $self->add_columns(qw(shop)) if $self->settings->{shoparticle_if_missing};
116 117
}
117 118

  
118 119
sub check_duplicates {
119 120
  my ($self, %params) = @_;
120 121

  
121
  die "IMPLEMENT ME";
122

  
123 122
  my $normalizer = sub { my $name = $_[0]; $name =~ s/[\s,\.\-]//g; return $name; };
124
  my $name_maker = sub { return $normalizer->($_[0]->shiptoname) . '--' . $normalizer->($_[0]->shiptostreet) };
123
  my $name_maker = sub { return $normalizer->($_[0]->description) };
125 124

  
126
  my %by_id_and_name;
125
  my %by_name;
127 126
  if ('check_db' eq $self->controller->profile->get('duplicates')) {
128
    foreach my $type (qw(customers vendors)) {
129
      foreach my $vc (@{ $self->all_vc->{$type} }) {
130
        $by_id_and_name{ $vc->id } = { map { ( $name_maker->($_) => 'db' ) } @{ $vc->shipto } };
131
      }
132
    }
127
    %by_name = map { ( $name_maker->($_) => 'db' ) } @{ $self->existing_objects };
133 128
  }
134 129

  
135 130
  foreach my $entry (@{ $self->controller->data }) {
......
137 132

  
138 133
    my $name = $name_maker->($entry->{object});
139 134

  
140
    $by_id_and_name{ $entry->{vc}->id } ||= { };
141
    if (!$by_id_and_name{ $entry->{vc}->id }->{ $name }) {
142
      $by_id_and_name{ $entry->{vc}->id }->{ $name } = 'csv';
135
    if (!$by_name{ $name }) {
136
      $by_name{ $name } = 'csv';
143 137

  
144 138
    } else {
145
      push @{ $entry->{errors} }, $by_id_and_name{ $entry->{vc}->id }->{ $name } eq 'db' ? $::locale->text('Duplicate in database') : $::locale->text('Duplicate in CSV file');
139
      push @{ $entry->{errors} }, $by_name{ $name } eq 'db' ? $::locale->text('Duplicate in database') : $::locale->text('Duplicate in CSV file');
146 140
    }
147 141
  }
148 142
}
......
207 201
    my $value      = $entry->{object}->$column;
208 202

  
209 203
    $value = $self->settings->{sellprice_adjustment_type} eq 'percent' ? $value * (100 + $adjustment) / 100 : $value + $adjustment;
210
    $entry->{object}->$column($::form->round_amount($self->settings->{sellprice_places}, $value));
204
    $entry->{object}->$column($::form->round_amount($value, $self->settings->{sellprice_places}));
211 205
  }
212 206
}
213 207

  
......
257 251

  
258 252
  # Map name to ID if given.
259 253
  if (!$object->price_factor_id && $entry->{raw_data}->{price_factor}) {
260
    my $id = $self->price_factors_by->{description}->{ $entry->{raw_data}->{price_factor} };
254
    my $pf = $self->price_factors_by->{description}->{ $entry->{raw_data}->{price_factor} };
261 255

  
262
    if (!$id) {
256
    if (!$pf) {
263 257
      push @{ $entry->{errors} }, $::locale->text('Error: Invalid price factor');
264 258
      return 0;
265 259
    }
266 260

  
267
    $object->price_factor_id($id);
261
    $object->price_factor_id($pf->id);
268 262
  }
269 263

  
270 264
  return 1;
......
283 277

  
284 278
  # Map name to ID if given.
285 279
  if (!$object->payment_id && $entry->{raw_data}->{payment}) {
286
    my $id = $self->payment_terms_by->{description}->{ $entry->{raw_data}->{payment} };
280
    my $terms = $self->payment_terms_by->{description}->{ $entry->{raw_data}->{payment} };
287 281

  
288
    if (!$id) {
282
    if (!$terms) {
289 283
      push @{ $entry->{errors} }, $::locale->text('Error: Invalid payment terms');
290 284
      return 0;
291 285
    }
292 286

  
293
    $object->payment_id($id);
287
    $object->payment_id($terms->id);
294 288
  }
295 289

  
296 290
  return 1;
......
309 303

  
310 304
  # Map name to ID if given.
311 305
  if (!$object->packing_type_id && $entry->{raw_data}->{packing_type}) {
312
    my $id = $self->packing_type_by->{description}->{ $entry->{raw_data}->{packing_type} };
306
    my $type = $self->packing_types_by->{description}->{ $entry->{raw_data}->{packing_type} };
313 307

  
314
    if (!$id) {
308
    if (!$type) {
315 309
      push @{ $entry->{errors} }, $::locale->text('Error: Invalid packing type');
316 310
      return 0;
317 311
    }
318 312

  
319
    $object->packing_type_id($id);
313
    $object->packing_type_id($type->id);
320 314
  }
321 315

  
322 316
  return 1;
......
335 329

  
336 330
  # Map name to ID if given.
337 331
  if (!$object->partsgroup_id && $entry->{raw_data}->{partsgroup}) {
338
    my $id = $self->partsgroups_by->{partsgroup}->{ $entry->{raw_data}->{partsgroup} };
332
    my $pg = $self->partsgroups_by->{partsgroup}->{ $entry->{raw_data}->{partsgroup} };
339 333

  
340
    if (!$id) {
334
    if (!$pg) {
341 335
      push @{ $entry->{errors} }, $::locale->text('Error: Invalid parts group');
342 336
      return 0;
343 337
    }
344 338

  
345
    $object->partsgroup_id($id);
339
    $object->partsgroup_id($pg->id);
346 340
  }
347 341

  
348 342
  return 1;

Auch abrufbar als: Unified diff