Revision 228dfbdc
Von Niclas Zimmermann vor etwa 11 Jahren hinzugefügt
SL/Controller/CsvImport/CustomerVendor.pm | ||
---|---|---|
3 | 3 |
use strict; |
4 | 4 |
|
5 | 5 |
use SL::Helper::Csv; |
6 |
use SL::Helper::Csv::Consistency;
|
|
6 |
use SL::Controller::CsvImport::Helper::Consistency;
|
|
7 | 7 |
use SL::DB::Business; |
8 | 8 |
use SL::DB::CustomVariable; |
9 | 9 |
use SL::DB::CustomVariableConfig; |
... | ... | |
66 | 66 |
$self->check_language($entry); |
67 | 67 |
$self->check_business($entry); |
68 | 68 |
$self->check_payment($entry); |
69 |
SL::Helper::Csv::Consistency->check_currency($entry, take_default => 1);
|
|
69 |
$self->check_currency($entry, take_default => 1);
|
|
70 | 70 |
$self->handle_cvars($entry); |
71 | 71 |
|
72 | 72 |
next if @{ $entry->{errors} }; |
SL/Controller/CsvImport/Helper/Consistency.pm | ||
---|---|---|
1 |
package SL::Controller::CsvImport::Helper::Consistency; |
|
2 |
|
|
3 |
use strict; |
|
4 |
|
|
5 |
use SL::DB::Default; |
|
6 |
use SL::DB::Currency; |
|
7 |
|
|
8 |
use SL::Helper::Csv::Error; |
|
9 |
|
|
10 |
use parent qw(Exporter); |
|
11 |
our @EXPORT = qw(check_currency); |
|
12 |
|
|
13 |
# |
|
14 |
# public functions |
|
15 |
# |
|
16 |
|
|
17 |
sub check_currency { |
|
18 |
my ($self, $entry, %params) = @_; |
|
19 |
|
|
20 |
my $object = $entry->{object}; |
|
21 |
|
|
22 |
# Check whether or not currency ID is valid. |
|
23 |
if ($object->currency_id && ! _currencies_by($self)->{id}->{ $object->currency_id }) { |
|
24 |
push @{ $entry->{errors} }, $::locale->text('Error: Invalid currency'); |
|
25 |
return 0; |
|
26 |
} |
|
27 |
|
|
28 |
# Map name to ID if given. |
|
29 |
if (!$object->currency_id && $entry->{raw_data}->{currency}) { |
|
30 |
my $currency = _currencies_by($self)->{name}->{ $entry->{raw_data}->{currency} }; |
|
31 |
if (!$currency) { |
|
32 |
push @{ $entry->{errors} }, $::locale->text('Error: Invalid currency'); |
|
33 |
return 0; |
|
34 |
} |
|
35 |
|
|
36 |
$object->currency_id($currency->id); |
|
37 |
} |
|
38 |
|
|
39 |
# Set default currency if none was given and take_default is true. |
|
40 |
$object->currency_id(_default_currency_id($self)) if !$object->currency_id and $params{take_default}; |
|
41 |
|
|
42 |
$entry->{raw_data}->{currency_id} = $object->currency_id; |
|
43 |
|
|
44 |
return 1; |
|
45 |
} |
|
46 |
|
|
47 |
# |
|
48 |
# private functions |
|
49 |
# |
|
50 |
|
|
51 |
sub _currencies_by { |
|
52 |
my ($self) = @_; |
|
53 |
|
|
54 |
return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ _all_currencies($self) } } ) } qw(id name) }; |
|
55 |
} |
|
56 |
|
|
57 |
sub _all_currencies { |
|
58 |
my ($self) = @_; |
|
59 |
|
|
60 |
return SL::DB::Manager::Currency->get_all; |
|
61 |
} |
|
62 |
|
|
63 |
sub _default_currency_id { |
|
64 |
my ($self) = @_; |
|
65 |
|
|
66 |
return SL::DB::Default->get->currency_id; |
|
67 |
} |
|
68 |
|
|
69 |
1; |
SL/Controller/CsvImport/Order.pm | ||
---|---|---|
6 | 6 |
use List::MoreUtils qw(any); |
7 | 7 |
|
8 | 8 |
use SL::Helper::Csv; |
9 |
use SL::Controller::CsvImport::Helper::Consistency; |
|
9 | 10 |
use SL::DB::Order; |
10 | 11 |
use SL::DB::OrderItem; |
11 | 12 |
use SL::DB::Part; |
... | ... | |
324 | 325 |
$self->check_project($entry, global => 1); |
325 | 326 |
$self->check_ct_shipto($entry); |
326 | 327 |
$self->check_taxzone($entry); |
327 |
SL::Helper::Csv::Consistency->check_currency($entry, take_default => 0);
|
|
328 |
$self->check_currency($entry, take_default => 0);
|
|
328 | 329 |
|
329 | 330 |
if ($vc_obj) { |
330 | 331 |
# copy from customer if not given |
SL/Helper/Csv/Consistency.pm | ||
---|---|---|
1 |
package SL::Helper::Csv::Consistency; |
|
2 |
|
|
3 |
use strict; |
|
4 |
|
|
5 |
use SL::DB::Default; |
|
6 |
use SL::DB::Currency; |
|
7 |
|
|
8 |
use SL::Helper::Csv::Error; |
|
9 |
|
|
10 |
# |
|
11 |
# public functions |
|
12 |
# |
|
13 |
|
|
14 |
sub check_currency { |
|
15 |
my ($self, $entry, %params) = @_; |
|
16 |
|
|
17 |
my $object = $entry->{object}; |
|
18 |
|
|
19 |
# Check whether or not currency ID is valid. |
|
20 |
if ($object->currency_id && !$self->_currencies_by->{id}->{ $object->currency_id }) { |
|
21 |
push @{ $entry->{errors} }, $::locale->text('Error: Invalid currency'); |
|
22 |
return 0; |
|
23 |
} |
|
24 |
|
|
25 |
# Map name to ID if given. |
|
26 |
if (!$object->currency_id && $entry->{raw_data}->{currency}) { |
|
27 |
my $currency = $self->_currencies_by->{name}->{ $entry->{raw_data}->{currency} }; |
|
28 |
if (!$currency) { |
|
29 |
push @{ $entry->{errors} }, $::locale->text('Error: Invalid currency'); |
|
30 |
return 0; |
|
31 |
} |
|
32 |
|
|
33 |
$object->currency_id($currency->id); |
|
34 |
} |
|
35 |
|
|
36 |
# Set default currency if none was given and take_default is true. |
|
37 |
$object->currency_id($self->_default_currency_id) if !$object->currency_id and $params{take_default}; |
|
38 |
|
|
39 |
$entry->{raw_data}->{currency_id} = $object->currency_id; |
|
40 |
|
|
41 |
return 1; |
|
42 |
} |
|
43 |
|
|
44 |
# |
|
45 |
# private functions |
|
46 |
# |
|
47 |
|
|
48 |
sub _currencies_by { |
|
49 |
my ($self) = @_; |
|
50 |
|
|
51 |
return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->_all_currencies } } ) } qw(id name) }; |
|
52 |
} |
|
53 |
|
|
54 |
sub _all_currencies { |
|
55 |
my ($self) = @_; |
|
56 |
|
|
57 |
return SL::DB::Manager::Currency->get_all; |
|
58 |
} |
|
59 |
|
|
60 |
sub _default_currency_id { |
|
61 |
my ($self) = @_; |
|
62 |
|
|
63 |
return SL::DB::Default->get->currency_id; |
|
64 |
} |
|
65 |
|
|
66 |
1; |
Auch abrufbar als: Unified diff
Verbessern von Helfer Konsistenz-Check
Der Konsistenz-Check wird in den Ordner SL/Controller/CsvImport/Helper/
verschoben. Weiterhin ist er jetzt als Mixin programmiert.