1 package SL::Helper::Csv::Consistency;
8 use SL::Helper::Csv::Error;
15 my ($self, $entry, %params) = @_;
17 my $object = $entry->{object};
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');
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} };
29 push @{ $entry->{errors} }, $::locale->text('Error: Invalid currency');
33 $object->currency_id($currency->id);
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};
39 $entry->{raw_data}->{currency_id} = $object->currency_id;
51 return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->_all_currencies } } ) } qw(id name) };
57 return SL::DB::Manager::Currency->get_all;
60 sub _default_currency_id {
63 return SL::DB::Default->get->currency_id;