Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 3063b9a8

Von Sven Schöling vor fast 12 Jahren hinzugefügt

  • ID 3063b9a83fbf516b55feebb66c2fdc8d3c349944
  • Vorgänger b6cdc154
  • Nachfolger dea7951f

PartImport: check_existing etwas optimiert, spart bei Testimports gut 40% Zeit.

Unterschiede anzeigen:

SL/Controller/CsvImport.pm
305 305

  
306 306
  my $worker = $self->worker();
307 307

  
308
  $worker->run;
308
  $worker->run(%params);
309 309

  
310 310
  return if $self->errors;
311 311

  
SL/Controller/CsvImport/Base.pm
15 15

  
16 16
use Rose::Object::MakeMethods::Generic
17 17
(
18
 scalar                  => [ qw(controller file csv save_with_cascade) ],
18
 scalar                  => [ qw(controller file csv test_run save_with_cascade) ],
19 19
 'scalar --get_set_init' => [ qw(profile displayable_columns existing_objects class manager_class cvar_columns all_cvar_configs all_languages payment_terms_by all_vc vc_by) ],
20 20
);
21 21

  
22 22
sub run {
23
  my ($self) = @_;
23
  my ($self, %params) = @_;
24

  
25
  $self->test_run($params{test_run});
24 26

  
25 27
  $self->controller->track_progress(phase => 'parsing csv', progress => 0);
26 28

  
SL/Controller/CsvImport/Part.pm
4 4

  
5 5
use SL::Helper::Csv;
6 6

  
7
use SL::DBUtils;
7 8
use SL::DB::Buchungsgruppe;
8 9
use SL::DB::CustomVariable;
9 10
use SL::DB::CustomVariableConfig;
......
60 61
sub init_parts_by {
61 62
  my ($self) = @_;
62 63

  
63
  my $parts_by = { id         => { map { ( $_->id => $_ ) } grep { !$_->assembly } @{ $self->existing_objects } },
64
                   partnumber => { part    => { },
65
                                   service => { } } };
66

  
67
  foreach my $part (@{ $self->existing_objects }) {
68
    next if $part->assembly;
69
    $parts_by->{partnumber}->{ $part->type }->{ $part->partnumber } = $part;
64
#  my $parts_by = { id         => { map { ( $_->id => $_ ) } grep { !$_->assembly } @{ $self->existing_objects } },
65
#                   partnumber => { part    => { },
66
#                                   service => { } } };
67
#
68
#  foreach my $part (@{ $self->existing_objects }) {
69
#    next if $part->assembly;
70
#    $parts_by->{partnumber}->{ $part->type }->{ $part->partnumber } = $part;
71
#  }
72

  
73
  my $parts_by = {};
74
  my $sth = prepare_execute_query($::form, $::form->get_standard_dbh, 'SELECT partnumber FROM parts');
75
  while (my ($partnumber) = $sth->fetchrow_array()) {
76
    $parts_by->{partnumber}{$partnumber} = 1;
70 77
  }
71 78

  
72 79
  return $parts_by;
......
196 203

  
197 204
  my $object = $entry->{object};
198 205

  
199
  $entry->{part} = SL::DB::Manager::Part->find_by(
200
    SL::DB::Manager::Part->type_filter($object->type),
201
    ( partnumber => $object->partnumber )                 x!! $object->partnumber,
202
  );
206
  if (!$self->test_run && $object->partnumber && $self->parts_by->{partnumber}{$object->partnumber}) {
207
    $entry->{part} = SL::DB::Manager::Part->find_by(
208
      SL::DB::Manager::Part->type_filter($object->type),
209
      ( partnumber => $object->partnumber )                 x!! $object->partnumber,
210
    );
211
  }
203 212

  
204 213
  if ($self->settings->{article_number_policy} eq 'update_prices') {
214
    if ($object->partnumber && $self->parts_by->{partnumber}{$object->partnumber}) {
215
      push @{ $entry->{information} }, $::locale->text('Updating prices of existing entry in database');
216
    }
205 217
    if ($entry->{part}) {
206 218
      map { $entry->{part}->$_( $object->$_ ) if defined $object->$_ } qw(sellprice listprice lastcost);
207 219

  

Auch abrufbar als: Unified diff