-sub check_currency {
- my ($self, $entry) = @_;
-
- my $object = $entry->{object};
-
- # Check whether or not currency ID is valid.
- if ($object->currency_id && !$self->currencies_by->{id}->{ $object->currency_id }) {
- push @{ $entry->{errors} }, $::locale->text('Error: Invalid currency');
- return 0;
- }
-
- # Map name to ID if given.
- if (!$object->currency_id && $entry->{raw_data}->{currency}) {
- my $currency = $self->currencies_by->{name}->{ $entry->{raw_data}->{currency} };
- if (!$currency) {
- push @{ $entry->{errors} }, $::locale->text('Error: Invalid currency');
- return 0;
- }
-
- $object->currency_id($currency->id);
- }
-
- # Set default currency if none was given.
- $object->currency_id($self->default_currency_id) if !$object->currency_id;
-
- $entry->{raw_data}->{currency_id} = $object->currency_id;
-
- return 1;
-}
-