From e1c3b6b77d4407069cb09897a9e79cd8686e41bf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Fri, 23 Oct 2015 21:28:23 +0200 Subject: [PATCH] PriceSources: discount_from_source analog zu price_from_source implemeniert. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Wenn keine zur Rabatt-Quelle passende Klasse gefunden werden kann, wird auch hier ein spezieller leerer Rabatt zurückgeliefert. --- SL/PriceSource.pm | 35 +++++++++++++++++++++++++++++++++++ SL/PriceSource/Base.pm | 2 ++ SL/PriceSource/Business.pm | 4 +++- SL/PriceSource/Customer.pm | 4 +++- SL/PriceSource/Makemodel.pm | 2 ++ SL/PriceSource/MasterData.pm | 2 ++ SL/PriceSource/PriceRules.pm | 15 +++++++++++++-- SL/PriceSource/Pricegroup.pm | 2 ++ SL/PriceSource/Vendor.pm | 4 +++- bin/mozilla/io.pl | 2 +- 10 files changed, 66 insertions(+), 6 deletions(-) diff --git a/SL/PriceSource.pm b/SL/PriceSource.pm index 681210c00..66daad285 100644 --- a/SL/PriceSource.pm +++ b/SL/PriceSource.pm @@ -31,6 +31,17 @@ sub price_from_source { : empty_price(); } +sub discount_from_source { + my ($self, $source) = @_; + my ($source_name, $spec) = split m{/}, $source, 2; + + my $class = SL::PriceSource::ALL->price_source_class_by_name($source_name); + + return $class + ? $class->new(record_item => $self->record_item, record => $self->record)->discount_from_source($source, $spec) + : empty_discount(); +} + sub available_prices { map { $_->available_prices } $_[0]->all_price_sources; } @@ -54,6 +65,12 @@ sub empty_price { ); } +sub empty_discount { + SL::PriceSource::Discount->new( + description => t8('None (PriceSource Discount)'), + ); +} + 1; __END__ @@ -136,25 +153,43 @@ not have to be registered in C. Attempts to retrieve a formerly calculated price with the same conditions +=item C + +Attempts to retrieve a formerly calculated discount with the same conditions + =item C Returns all available prices. +=item C + +Returns all available discounts. + =item C Attempts to get the best available price. returns L if no price is found. +=item C + +Attempts to get the best available discount. returns L if no discount is found. + =item C A special empty price, that does not change the previously entered price, and opens the price field to manual changes. +=item C + +A special empty discount, that does not change the previously entered discount, and +opens the discount field to manual changes. + =back =head1 SEE ALSO L, L, +L, L =head1 BUGS AND CAVEATS diff --git a/SL/PriceSource/Base.pm b/SL/PriceSource/Base.pm index 8233c58bd..1e8f20d93 100644 --- a/SL/PriceSource/Base.pm +++ b/SL/PriceSource/Base.pm @@ -21,6 +21,8 @@ sub best_discounts { die 'best_discounts needs to be implemented' } sub price_from_source { die 'price_from_source needs to be implemented:' . "@_" } +sub discount_from_source { die 'discount_from_source needs to be implemented:' . "@_" } + sub part { $_[0]->record_item->part; } diff --git a/SL/PriceSource/Business.pm b/SL/PriceSource/Business.pm index fc7b298fc..20a1d549a 100644 --- a/SL/PriceSource/Business.pm +++ b/SL/PriceSource/Business.pm @@ -28,7 +28,9 @@ sub available_discounts { ); } -sub price_from_source { +sub price_from_source { } + +sub discount_from_source { my ($self, $source, $spec) = @_; my $business = SL::DB::Business->load_cached($spec); diff --git a/SL/PriceSource/Customer.pm b/SL/PriceSource/Customer.pm index 52d35ee92..c0cfbc09a 100644 --- a/SL/PriceSource/Customer.pm +++ b/SL/PriceSource/Customer.pm @@ -29,7 +29,9 @@ sub available_discounts { ); } -sub price_from_source { +sub price_from_source { } + +sub discount_from_source { my ($self, $source, $spec) = @_; my $customer = SL::DB::Customer->load_cached($spec); diff --git a/SL/PriceSource/Makemodel.pm b/SL/PriceSource/Makemodel.pm index 3c5031d1d..bda7b81ef 100644 --- a/SL/PriceSource/Makemodel.pm +++ b/SL/PriceSource/Makemodel.pm @@ -39,6 +39,8 @@ sub price_from_source { } +sub discount_from_source { } + sub best_price { my ($self, %params) = @_; diff --git a/SL/PriceSource/MasterData.pm b/SL/PriceSource/MasterData.pm index 14fe88f34..1305f4b04 100644 --- a/SL/PriceSource/MasterData.pm +++ b/SL/PriceSource/MasterData.pm @@ -31,6 +31,8 @@ sub price_from_source { : do { die "unknown spec '$spec'" }; } +sub discount_from_source { } + sub best_price { $_[0]->record->is_sales ? $_[0]->make_sellprice diff --git a/SL/PriceSource/PriceRules.pm b/SL/PriceSource/PriceRules.pm index e1d1c126b..668557867 100644 --- a/SL/PriceSource/PriceRules.pm +++ b/SL/PriceSource/PriceRules.pm @@ -44,12 +44,23 @@ sub available_discounts { sub price_from_source { my ($self, $source, $spec) = @_; + my $rule = SL::DB::Manager::PriceRule->find_by(id => $spec); + if ($rule->price_type != SL::DB::Manager::PriceRule::PRICE_DISCOUNT()) { + return $self->make_price_from_rule($rule); + } + + return; +} + +sub discount_from_source { + my ($self, $source, $spec) = @_; + my $rule = SL::DB::Manager::PriceRule->find_by(id => $spec); if ($rule->price_type == SL::DB::Manager::PriceRule::PRICE_DISCOUNT()) { return $self->make_discount_from_rule($rule); - } else { - return $self->make_price_from_rule($rule); } + + return; } sub best_price { diff --git a/SL/PriceSource/Pricegroup.pm b/SL/PriceSource/Pricegroup.pm index 2a8adae13..6408300b1 100644 --- a/SL/PriceSource/Pricegroup.pm +++ b/SL/PriceSource/Pricegroup.pm @@ -44,6 +44,8 @@ sub price_from_source { return $self->make_price($price); } +sub discount_from_source { } + sub best_price { my ($self, %params) = @_; diff --git a/SL/PriceSource/Vendor.pm b/SL/PriceSource/Vendor.pm index 0b09ad698..7eee13085 100644 --- a/SL/PriceSource/Vendor.pm +++ b/SL/PriceSource/Vendor.pm @@ -28,7 +28,9 @@ sub available_discounts { ); } -sub price_from_source { +sub price_from_source { } + +sub discount_from_source { my ($self, $source, $spec) = @_; my $vendor = SL::DB::Vendor->load_cached($spec); diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index 4ad3cbf2f..f42db4654 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -345,7 +345,7 @@ sub display_row { if ($form->{"id_${i}"} && !$is_delivery_order) { my $price_source = SL::PriceSource->new(record_item => $record_item, record => $record); my $price = $price_source->price_from_source($::form->{"active_price_source_$i"}); - my $discount = $price_source->price_from_source($::form->{"active_discount_source_$i"}); + my $discount = $price_source->discount_from_source($::form->{"active_discount_source_$i"}); my $best_price = $price_source->best_price; my $best_discount = $price_source->best_discount; $column_data{price_source} .= $cgi->button(-value => $price->source_description, -onClick => "kivi.io.price_chooser($i)"); -- 2.20.1