From a4415997ce2a52e766b1457ddac37184e14aff26 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Fri, 23 Oct 2015 21:49:25 +0200 Subject: [PATCH] PriceSources: Fehlerbehandlung in PriceRules. --- SL/PriceSource/PriceRules.pm | 26 ++++++++++++++++++++++---- locale/de/all | 4 ++++ locale/en/all | 4 ++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/SL/PriceSource/PriceRules.pm b/SL/PriceSource/PriceRules.pm index 668557867..48ab56311 100644 --- a/SL/PriceSource/PriceRules.pm +++ b/SL/PriceSource/PriceRules.pm @@ -45,22 +45,40 @@ sub price_from_source { my ($self, $source, $spec) = @_; my $rule = SL::DB::Manager::PriceRule->find_by(id => $spec); + + return SL::PriceSource::Discount->new( + price_source => $self, + missing => t8('The price rule for this price does not exist anymore'), + ) if !$rule; + if ($rule->price_type != SL::DB::Manager::PriceRule::PRICE_DISCOUNT()) { return $self->make_price_from_rule($rule); + } else { + return SL::PriceSource::Price->new( + price_source => $self, + invalid => t8('The price rule is not a rule for prices'), + ); } - - return; } sub discount_from_source { my ($self, $source, $spec) = @_; my $rule = SL::DB::Manager::PriceRule->find_by(id => $spec); + + return SL::PriceSource::Discount->new( + price_source => $self, + missing => t8('The price rule for this discount does not exist anymore'), + ) if !$rule; + if ($rule->price_type == SL::DB::Manager::PriceRule::PRICE_DISCOUNT()) { return $self->make_discount_from_rule($rule); + } else { + return SL::PriceSource::Discount->new( + price_source => $self, + invalid => t8('The price rule is not a rule for discounts'), + ); } - - return; } sub best_price { diff --git a/locale/de/all b/locale/de/all index 3d86bbd3d..4191dab2b 100755 --- a/locale/de/all +++ b/locale/de/all @@ -2798,9 +2798,13 @@ $self->{texts} = { 'The predefined text has been saved.' => 'Der vordefinierte Textblock wurde gespeichert.', 'The predefined text is in use and cannot be deleted.' => 'Der vordefinierte Textblock wird verwendet und kann nicht gelöscht werden.', 'The preferred one is to install packages provided by your operating system distribution (e.g. Debian or RPM packages).' => 'Die bevorzugte Art, ein Perl-Modul zu installieren, ist durch Installation eines von Ihrem Betriebssystem zur Verfügung gestellten Paketes (z.B. Debian-Pakete oder RPM).', + 'The price rule for this discount does not exist anymore' => 'Die Preisregel für diesen Rabatt existiert nicht mehr', + 'The price rule for this price does not exist anymore' => 'Die Preisregel für diesen Preis existiert nicht mehr', 'The price rule has been created.' => 'Die Preisregel wurde angelegt.', 'The price rule has been deleted.' => 'Die Preisregel wurde gelöscht.', 'The price rule has been saved.' => 'Die Preisregel wurde gespeichert.', + 'The price rule is not a rule for discounts' => 'Die Preisregel ist keine Regel für Rabatte', + 'The price rule is not a rule for prices' => 'Die Preisregel ist keine Regel für Preise', 'The printer could not be deleted.' => 'Der Drucker konnte nicht gelöscht werden.', 'The printer has been created.' => 'Der Drucker wurde angelegt.', 'The printer has been deleted.' => 'Der Drucker wurde entfernt.', diff --git a/locale/en/all b/locale/en/all index c69f7b790..4141d7971 100644 --- a/locale/en/all +++ b/locale/en/all @@ -2213,6 +2213,10 @@ $self->{texts} = { 'The payment term is in use and cannot be deleted.' => '', 'The payments have been posted.' => '', 'The preferred one is to install packages provided by your operating system distribution (e.g. Debian or RPM packages).' => '', + 'The price rule for this discount does not exist anymore' => '', + 'The price rule for this price does not exist anymore' => '', + 'The price rule is not a rule for discounts' => '', + 'The price rule is not a rule for prices' => '', 'The printer could not be deleted.' => '', 'The printer has been created.' => '', 'The printer has been deleted.' => '', -- 2.20.1