1 package SL::BackgroundJob::UpdateExchangerates::Base;
5 use parent qw(Rose::Object);
7 use Rose::Object::MakeMethods::Generic (
8 scalar => [ qw(options) ],
12 my ($self, $rates) = @_;
13 die 'needs to be overwritten';
16 sub translate_currency_name {
17 my ($self, $name) = @_;
19 return $name if (!$self->options->{translate});
20 return $self->options->{translate}->{$name} if $self->options->{translate}->{$name};
34 SL::BackgroundJob::UpdateExchangerates::Base - Base class for background job to update exchange rates.
39 use parent qw(SL::BackgroundJob::UpdateExchangerates::Base);
43 my ($self, $rates) = @_;
45 foreach my $rate (@$rates) {
46 my $from = $self->translate_currency_name($rate->{from}->name);
47 my $to = $self->translate_currency_name($rate->{to}->name);
48 if ( $from eq 'EUR' && $to eq 'USD') {
49 $rate->{rate} = 0.9205 if $rate->{dir} eq 'buy';
50 $rate->{rate} = 0.9202 if $rate->{dir} eq 'sell';
57 This is a base class for a worker to update exchange rates.
63 =item C<update_rates $rates>
65 Your class will be instanciated and the update_rates method will be invoked.
66 This method can update known requeseted rates. Therefor an array of hashes with
67 information of the requested rates is provided. Each hash consists of the
74 from: currency (instance of SL::DB::Currency) to be converted from
78 to: currency (instance of SL::DB::Currency) to be converted to
86 Your class should add a 'rate'-entry to each hash, if it can provide the rate
87 information. If not, it should leave the hash-entry as it is.
95 =item C<translate_currency_name $name>
97 Returns the translated currency name, if a translation is given. This can be used to translate client specific
98 currency notations to the one used by the worker module. Translations are give as data to the background job:
108 Bernd Bleßmann E<lt>bernd@kivitendo-premium.deE<gt>