Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision ae47b240

Von Kivitendo Admin vor etwa 10 Jahren hinzugefügt

  • ID ae47b240b0a1d1d793240c660feeb3f0532122ab
  • Vorgänger 1d61ec90
  • Nachfolger 75620714

CsvImport Taxzone für CustomerVendor und Order

check_taxzone aus Order nach CsvImport/Helper/Consistency.pm ausgelagert
und um die Option take_default für CustomerVendor Import erweitert.

Behebt Ticket 9.

Unterschiede anzeigen:

SL/Controller/CsvImport.pm
27 27
use Rose::Object::MakeMethods::Generic
28 28
(
29 29
 scalar                  => [ qw(type profile file all_profiles all_charsets sep_char all_sep_chars quote_char all_quote_chars escape_char all_escape_chars all_buchungsgruppen all_units
30
                                 import_status errors headers raw_data_headers info_headers data num_imported num_importable displayable_columns file) ],
30
                                 import_status errors headers raw_data_headers info_headers data num_imported num_importable displayable_columns file all_taxzones) ],
31 31
 'scalar --get_set_init' => [ qw(worker task_server) ],
32 32
 'array'                 => [
33 33
   progress_tracker     => { },
......
267 267
            : $self->type eq 'orders'            ? $::locale->text('CSV import: orders')
268 268
            : die;
269 269

  
270
  if ($self->{type} eq 'customers_vendors' or $self->{type} eq 'orders'  ) {
271
    $self->all_taxzones(SL::DB::Manager::TaxZone->get_all_sorted(query => [ obsolete => 0 ]));
272
  };
273

  
270 274
  if ($self->{type} eq 'parts') {
271 275
    $self->all_buchungsgruppen(SL::DB::Manager::Buchungsgruppe->get_all_sorted);
272 276
    $self->all_units(SL::DB::Manager::Unit->get_all_sorted);
SL/Controller/CsvImport/CustomerVendor.pm
67 67
    $self->check_business($entry);
68 68
    $self->check_payment($entry);
69 69
    $self->check_delivery_term($entry);
70
    $self->check_taxzone($entry,  take_default => 1);
70 71
    $self->check_currency($entry, take_default => 1);
71 72
    $self->handle_cvars($entry);
72 73

  
73 74
    next if @{ $entry->{errors} };
74 75

  
75 76
    my @cleaned_fields = $self->clean_fields(qr{[\r\n]}, $object, qw(name department_1 department_2 street zipcode city country contact phone fax homepage email cc bcc
76
                                                                     taxnumber account_number bank_code bank username greeting));
77
                                                                     taxnumber account_number bank_code bank username greeting taxzone));
77 78

  
78 79
    push @{ $entry->{information} }, $::locale->text('Illegal characters have been removed from the following fields: #1', join(', ', @cleaned_fields))
79 80
      if @cleaned_fields;
......
100 101
    $i++;
101 102
  }
102 103

  
103
  $self->add_columns(map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw(language business payment delivery_term));
104
  $self->add_columns(map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw(language business payment delivery_term taxzone));
104 105
  $self->add_cvar_raw_data_columns;
105 106
}
106 107

  
......
267 268
                                 { name => 'phone',             description => $::locale->text('Phone')                           },
268 269
                                 { name => 'street',            description => $::locale->text('Street')                          },
269 270
                                 { name => 'taxnumber',         description => $::locale->text('Tax Number / SSN')                },
270
                                 { name => 'taxzone_id',        description => $::locale->text('Steuersatz')                      },
271
                                 { name => 'taxzone',           description => $::locale->text('Tax zone (description)')          },
272
                                 { name => 'taxzone_id',        description => $::locale->text('Tax zone (database ID)')          },
271 273
                                 { name => 'user_password',     description => $::locale->text('Password')                        },
272 274
                                 { name => 'username',          description => $::locale->text('Username')                        },
273 275
                                 { name => 'ustid',             description => $::locale->text('sales tax identification number') },
SL/Controller/CsvImport/Helper/Consistency.pm
4 4

  
5 5
use SL::DB::Default;
6 6
use SL::DB::Currency;
7
use SL::DB::TaxZone;
7 8

  
8 9
use SL::Helper::Csv::Error;
9 10

  
10 11
use parent qw(Exporter);
11
our @EXPORT = qw(check_currency);
12
our @EXPORT = qw(check_currency check_taxzone);
12 13

  
13 14
#
14 15
# public functions
......
47 48
  return 1;
48 49
}
49 50

  
51
sub check_taxzone {
52
  my ($self, $entry, %params) = @_;
53

  
54
  my $object = $entry->{object};
55

  
56
  # Check whether the CSV contains the parameters taxzone_id or taxzone, and
57
  # check them for validity. 
58
  # If one of them was given, but is invalid, return an error
59

  
60
  # If neither was given:
61
  # a) if param take_default was set, use the taxzone_id from the profile
62
  #    (customer/vendor import)
63
  # b) if param take_default was not set, do nothing, return without error, and
64
  #    taxzone_id may be set later by other means (order import uses cv settings)
65

  
66
 
67
  # if $object->taxzone_id is defined (from CSV line), check if it is valid
68
  if ($object->taxzone_id && ! _taxzones_by($self)->{id}->{ $object->taxzone_id }) {
69
    push @{ $entry->{errors} }, $::locale->text('Error: Invalid tax zone');
70
    return 0;
71
  }
72

  
73
  # if there was no taxzone_id in CSV, but a taxzone entry, check if it is a
74
  # valid taxzone and set the id
75
  if (!$object->taxzone_id && $entry->{raw_data}->{taxzone}) {
76
    my $taxzone = _taxzones_by($self)->{description}->{ $entry->{raw_data}->{taxzone} };
77
    if (!$taxzone) {
78
      push @{ $entry->{errors} }, $::locale->text('Error: Invalid tax zone');
79
      return 0;
80
    }
81

  
82
    $object->taxzone_id($taxzone->id);
83
  }
84

  
85
  # The take_default option should only be used for the customer/vendor case,
86
  # as the default for imported orders is the taxzone according to the customer
87
  # or vendor
88
  # if neither taxzone_id nor taxzone were defined, use the default taxzone as
89
  # defined from the import settings (a default/fallback taxzone that is to be
90
  # used will always be selected)
91

  
92
  if (!$object->taxzone_id && $params{take_default}) {
93
    # my $default_id = $self->settings->{'default_taxzone'};
94
    my $default_id = $self->controller->profile->get('default_taxzone');
95
    $object->taxzone_id($default_id);
96
    # check if default taxzone_id is valid just to be sure
97
    if (! _taxzones_by($self)->{id}->{ $object->taxzone_id }) {
98
      push @{ $entry->{errors} }, $::locale->text('Error with default taxzone');
99
      return 0;
100
    };
101
  };
102

  
103
  # for the order import at this stage $object->taxzone_id may still not be
104
  # defined, in this case the customer/vendor taxzone will be used. 
105

  
106
  return 1;
107
}
108

  
50 109
#
51 110
# private functions
52 111
#
......
69 128
  return SL::DB::Default->get->currency_id;
70 129
}
71 130

  
131
sub _taxzones_by {
132
  my ($self) = @_;
133

  
134
  return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ _all_taxzones($self) } } ) } qw(id description) };
135
}
136

  
137
sub _all_taxzones {
138
  my ($self) = @_;
139

  
140
  return SL::DB::Manager::TaxZone->get_all_sorted(query => [ obsolete => 0 ]);
141
}
142

  
72 143
1;
SL/Controller/CsvImport/Order.pm
25 25

  
26 26
use Rose::Object::MakeMethods::Generic
27 27
(
28
 'scalar --get_set_init' => [ qw(settings languages_by parts_by contacts_by departments_by projects_by ct_shiptos_by taxzones_by price_factors_by pricegroups_by) ],
28
 'scalar --get_set_init' => [ qw(settings languages_by parts_by contacts_by departments_by projects_by ct_shiptos_by price_factors_by pricegroups_by) ],
29 29
);
30 30

  
31 31

  
......
227 227
  return $sby;
228 228
}
229 229

  
230
sub init_taxzones_by {
231
  my ($self) = @_;
232

  
233
  my $all_taxzones = SL::DB::Manager::TaxZone->get_all;
234
  return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_taxzones } } ) } qw(id description) };
235
}
236

  
237 230
sub init_price_factors_by {
238 231
  my ($self) = @_;
239 232

  
......
574 567
  return 1;
575 568
}
576 569

  
577
sub check_taxzone {
578
  my ($self, $entry) = @_;
579

  
580
  my $object = $entry->{object};
581

  
582
  # Check wether or not taxzone ID is valid.
583
  if ($object->taxzone_id && !$self->taxzones_by->{id}->{ $object->taxzone_id }) {
584
    push @{ $entry->{errors} }, $::locale->text('Error: Invalid tax zone');
585
    return 0;
586
  }
587

  
588
  # Map description to ID if given.
589
  if (!$object->taxzone_id && $entry->{raw_data}->{taxzone}) {
590
    my $taxzone = $self->taxzones_by->{description}->{ $entry->{raw_data}->{taxzone} };
591
    if (!$taxzone) {
592
      push @{ $entry->{errors} }, $::locale->text('Error: Invalid tax zone');
593
      return 0;
594
    }
595

  
596
    $object->taxzone_id($taxzone->id);
597
  }
598

  
599
  return 1;
600
}
601

  
602 570
sub check_price_factor {
603 571
  my ($self, $entry) = @_;
604 572

  
locale/de/all
775 775
  'Default hourly rate for new customers' => 'Standard-Stundensatz für neue Kunden',
776 776
  'Default output medium'       => 'Standardausgabekanal',
777 777
  'Default printer'             => 'Standarddrucker',
778
  'Default taxzone'             => 'Standardsteuerzone',
778 779
  'Default template format'     => 'Standardvorlagenformat',
779 780
  'Default transport article number' => 'Standard Versand / Transport-Erinnerungs-Artikel',
780 781
  'Default unit'                => 'Standardeinheit',
......
1040 1041
  'Error message from the database driver:' => 'Fehlermeldung des Datenbanktreibers:',
1041 1042
  'Error message from the database: #1' => 'Fehlermeldung der Datenbank: #1',
1042 1043
  'Error when saving: #1'       => 'Fehler beim Speichern: #1',
1044
  'Error with default taxzone'  => 'Ungültige Standardsteuerzone',
1043 1045
  'Error!'                      => 'Fehler!',
1044 1046
  'Error: Buchungsgruppe missing or invalid' => 'Fehler: Buchungsgruppe fehlt oder ungültig',
1045 1047
  'Error: Customer/vendor missing' => 'Fehler: Kunde/Lieferant fehlt',
templates/webpages/csv_import/_form_customers_vendors.html
16 16
  [% L.select_tag('settings.update_policy', opts, default = SELF.profile.get('update_policy'), style = 'width: 300px') %]
17 17
 </td>
18 18
</tr>
19

  
20
<tr>
21
 <th align="right" valign="top">[%- LxERP.t8('Default taxzone') %]:</th>
22
 <td colspan="10" valign="top">
23
  [% L.select_tag('settings.default_taxzone', SELF.all_taxzones, default = SELF.profile.get('default_taxzone'), title_key = 'description', style => 'width: 300px') %]
24
 </td>
25
</tr>
26

  

Auch abrufbar als: Unified diff