Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision b16b33c2

Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt

  • ID b16b33c220a567bf8a8b998ff69d44d380b0a181
  • Vorgänger 1c10936d
  • Nachfolger 428bc365

CSV-Import Ansprechpersonen: Aktualisieren von Existierenden via Spalte "cp_id"

Conflicts:
SL/Controller/CsvImport/Contact.pm

Unterschiede anzeigen:

SL/Controller/CsvImport/Base.pm
153 153
           vendors   => SL::DB::Manager::Vendor->get_all };
154 154
}
155 155

  
156
sub force_allow_columns {
157
  return ();
158
}
159

  
156 160
sub init_vc_by {
157 161
  my ($self)    = @_;
158 162

  
......
222 226
  eval "require " . $self->class;
223 227

  
224 228
  my %unwanted = map { ( $_ => 1 ) } (qw(itime mtime), map { $_->name } @{ $self->class->meta->primary_key_columns });
229
  delete $unwanted{$_} for ($self->force_allow_columns);
230

  
225 231
  my %profile;
226 232
  for my $col ($self->class->meta->columns) {
227 233
    next if $unwanted{$col};
SL/Controller/CsvImport/Contact.pm
24 24
  return SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'Contacts' ]);
25 25
}
26 26

  
27
sub force_allow_columns {
28
  return qw(cp_id);
29
}
30

  
27 31
sub check_objects {
28 32
  my ($self) = @_;
29 33

  
30 34
  $self->controller->track_progress(phase => 'building data', progress => 0);
31 35

  
32
  my $i;
33
  my $num_data = scalar @{ $self->controller->data };
36
  my $i              = 0;
37
  my $num_data       = scalar @{ $self->controller->data };
38
  my $update_policy  = $self->controller->profile->get('update_policy') || 'update_existing';
39
  my %contacts_by_id = map { ( $_->cp_id => $_ ) } @{ $self->existing_objects };
40
  my $methods        = $self->controller->headers->{methods};
41
  my %used_methods   = map { ( $_ => 1 ) } @{ $methods };
42

  
34 43
  foreach my $entry (@{ $self->controller->data }) {
35 44
    $self->controller->track_progress(progress => $i/$num_data * 100) if $i % 100 == 0;
36 45

  
46
    my $object = $entry->{object};
47
    if ($object->cp_id) {
48
      my $existing_contact = $contacts_by_id{ $object->cp_id };
49
      if (!$existing_contact) {
50
        $contacts_by_id{ $object->cp_id } = $object;
51

  
52
      } elsif ($update_policy eq 'skip') {
53
        push(@{ $entry->{errors} }, $::locale->text('Skipping due to existing entry in database'));
54
        next;
55

  
56
      } elsif ($update_policy eq 'update_existing') {
57
        # Update existing customer/vendor records.
58
        $entry->{object_to_save} = $existing_contact;
59

  
60
        $object->cp_cv_id($existing_contact->cp_cv_id);
61

  
62
        foreach (qw(cp_name cp_gender)) {
63
          $object->$_($existing_contact->$_) if !$object->$_;
64
        }
65

  
66
        $existing_contact->$_( $entry->{object}->$_ ) for @{ $methods };
67

  
68
        push @{ $entry->{information} }, $::locale->text('Updating existing entry in database');
69

  
70
      } else {
71
        $object->cp_id(undef);
72
      }
73
    }
74

  
37 75
    $self->check_name($entry);
38 76
    $self->check_vc($entry, 'cp_cv_id');
39 77
    $self->check_gender($entry);
40 78
    $self->handle_cvars($entry);
79

  
80
    my @cleaned_fields = $self->clean_fields(qr{[\r\n]}, $object, qw(cp_title cp_givenname cp_name cp_email cp_phone1 cp_phone2 cp_fax cp_mobile1 cp_mobile2 cp_satphone cp_satfax
81
                                                                     cp_privatphone cp_privatemail cp_abteilung cp_street cp_zipcode cp_city cp_position));
82

  
83
    push @{ $entry->{information} }, $::locale->text('Illegal characters have been removed from the following fields: #1', join(', ', @cleaned_fields))
84
      if @cleaned_fields;
41 85
  } continue {
42 86
    $i++;
43 87
  }
......
105 149
                                 { name => 'cp_fax',         description => $::locale->text('Fax')                           },
106 150
                                 { name => 'cp_gender',      description => $::locale->text('Gender')                        },
107 151
                                 { name => 'cp_givenname',   description => $::locale->text('Given Name')                    },
152
                                 { name => 'cp_id',          description => $::locale->text('Database ID')                   },
108 153
                                 { name => 'cp_mobile1',     description => $::locale->text('Mobile1')                       },
109 154
                                 { name => 'cp_mobile2',     description => $::locale->text('Mobile2')                       },
110 155
                                 { name => 'cp_name',        description => $::locale->text('Name')                          },
locale/de/all
856 856
  'Execution type'              => 'Ausführungsart',
857 857
  'Existing Buchungsgruppen'    => 'Existierende Buchungsgruppen',
858 858
  'Existing Datasets'           => 'Existierende Datenbanken',
859
  'Existing contacts (with column \'cp_id\')' => 'Existierende Ansprechpersonen (mit Spalte \'cp_id\')',
859 860
  'Existing customers/vendors with same customer/vendor number' => 'Existierende Kunden/Lieferanten mit derselben Kunden-/Lieferantennummer',
860 861
  'Existing file on server'     => 'Auf dem Server existierende Datei',
861 862
  'Existing pending follow-ups for this item' => 'Noch nicht erledigte Wiedervorlagen für dieses Dokument',
......
1032 1033
  'Individual Items'            => 'Einzelteile',
1033 1034
  'Information'                 => 'Information',
1034 1035
  'Insert with new customer/vendor number' => 'Mit neuer Kunden-/Lieferantennummer anlegen',
1036
  'Insert with new database ID' => 'Neu anlegen mit neuer Datenbank-ID',
1035 1037
  'Insert with new part number' => 'Mit neuer Artikelnummer einfügen',
1036 1038
  'Interest'                    => 'Zinsen',
1037 1039
  'Interest Rate'               => 'Zinssatz',
......
2321 2323
  'You can either create a new database or chose an existing database.' => 'Sie können entweder eine neue Datenbank erstellen oder eine existierende auswählen.',
2322 2324
  'You can find information on the migration in the upgrade chapter of the documentation.' => 'Informationen über die Migration sind in der Upgrade Kapitel in der Dokumentation zu finden.',
2323 2325
  'You can only delete datasets that are not in use.' => 'Sie können nur Datenbanken löschen, die momentan nicht in Benutzung sind.',
2326
  'You can update existing contacts by providing the \'cp_id\' column with their database IDs. Otherwise: ' => 'Sie können existierende Einträge aktualisieren, indem Sie eine Spalte \'cp_id\' mit der Datenbank-ID des Eintrags mitgeben. Andernfalls: ',
2324 2327
  'You can use the following strings in the long description and all translations. They will be replaced by their actual values by kivitendo before they\'re output.' => 'Sie können die folgenden Begriffe in den Langtexten und allen Übersetzungen benutzen. Sie werden von kivitendo vor der Ausgabe durch ihren tatsächlichen Wert ersetzt.',
2325 2328
  'You cannot adjust the price for pricegroup "#1" by a negative percentage.' => 'Sie können den Preis für Preisgruppe "#1" um einen negativen Prozentwert anpassen.',
2326 2329
  'You cannot continue before all required modules are installed.' => 'Sie können nicht fortfahren, bevor alle benötigten Pakete installiert sind.',
templates/webpages/csv_import/_form_contacts.html
1
[%- USE LxERP -%][%- USE L -%]
2
<tr>
3
 <th align="right">[%- LxERP.t8("Existing contacts (with column 'cp_id')") %]:</th>
4
 <td colspan="10">
5
  [% opts = [ [ 'update_existing', LxERP.t8('Update properties of existing entries') ], [ 'insert_new', LxERP.t8('Insert with new database ID') ], [ 'skip', LxERP.t8('Skip entry') ] ] %]
6
  [% L.select_tag('settings.update_policy', opts, default = SELF.profile.get('update_policy'), style = 'width: 300px') %]
7
 </td>
8
</tr>
templates/webpages/csv_import/form.html
73 73

  
74 74
[%- IF SELF.type == 'contacts' %]
75 75
   <p>
76
    [%- LxERP.t8("You can update existing contacts by providing the 'cp_id' column with their database IDs. Otherwise: ") %]
76 77
    [%- LxERP.t8('At least one of the columns #1, customer, customernumber, vendor, vendornumber (depending on the target table) is required for matching the entry to an existing customer or vendor.', 'cp_cv_id') %]
77 78
   </p>
78 79

  
......
203 204
 [%- INCLUDE 'csv_import/_form_parts.html' %]
204 205
[%- ELSIF SELF.type == 'customers_vendors' %]
205 206
 [%- INCLUDE 'csv_import/_form_customers_vendors.html' %]
207
[%- ELSIF SELF.type == 'contacts' %]
208
 [%- INCLUDE 'csv_import/_form_contacts.html' %]
206 209
[%- END %]
207 210

  
208 211
   <tr>

Auch abrufbar als: Unified diff