From: Sven Schöling Date: Mon, 8 Dec 2014 13:11:21 +0000 (+0100) Subject: PriceSource: Priorität auf Preisquellenebene verstehen und umsetzen. X-Git-Tag: release-3.2.1~6 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=9f66626118ec0cdcee8082b3d81f288bbfa23648;p=kivitendo-erp.git PriceSource: Priorität auf Preisquellenebene verstehen und umsetzen. Priorität kann jetzt von den einzelnen Preisquellen durchgereicht werden --- diff --git a/SL/PriceSource.pm b/SL/PriceSource.pm index ac419a670..89dffba89 100644 --- a/SL/PriceSource.pm +++ b/SL/PriceSource.pm @@ -40,11 +40,11 @@ sub available_discounts { } sub best_price { - min_by { $_->price } grep { $_->price > 0 } grep { $_ } map { $_->best_price } $_[0]->all_price_sources; + min_by { $_->price } max_by { $_->priority } grep { $_->price > 0 } grep { $_ } map { $_->best_price } $_[0]->all_price_sources; } sub best_discount { - max_by { $_->discount } grep { $_->discount } grep { $_ } map { $_->best_discount } $_[0]->all_price_sources; + max_by { $_->discount } max_by { $_->priority } grep { $_->discount } grep { $_ } map { $_->best_discount } $_[0]->all_price_sources; } sub empty_price { diff --git a/SL/PriceSource/Discount.pm b/SL/PriceSource/Discount.pm index ded123a81..a7475eae2 100644 --- a/SL/PriceSource/Discount.pm +++ b/SL/PriceSource/Discount.pm @@ -5,6 +5,7 @@ use strict; use parent 'SL::DB::Object'; use Rose::Object::MakeMethods::Generic ( scalar => [ qw(discount description spec price_source invalid missing) ], + 'scalar --get_set_init' => [ qw(priority) ], ); require SL::DB::Helper::Attr; @@ -38,6 +39,10 @@ sub to_str { "source: @{[ $_[0]->source ]}, discount: @{[ $_[0]->discount ]}, description: @{[ $_[0]->description ]}" } +sub init_priority { + 3 +} + 1; __END__ @@ -109,6 +114,11 @@ A localized short description of the origins of this discount. A ref to the creating algorithm. +=item C + +OPTIONAL. Discounts may supply a numerical priority. Higher will trump over lower, even when +supplying lower discounts. Defaults to 3 (as in middle of 1-5). + =item C OPTIONAL. Both indicator and localized message that the discount with this spec diff --git a/SL/PriceSource/Price.pm b/SL/PriceSource/Price.pm index 71bd1ff4f..b17fb36d8 100644 --- a/SL/PriceSource/Price.pm +++ b/SL/PriceSource/Price.pm @@ -5,6 +5,7 @@ use strict; use parent 'SL::DB::Object'; use Rose::Object::MakeMethods::Generic ( scalar => [ qw(price description spec price_source invalid missing) ], + 'scalar --get_set_init' => [ qw(priority) ], ); require SL::DB::Helper::Attr; @@ -38,6 +39,10 @@ sub to_str { "source: @{[ $_[0]->source ]}, price: @{[ $_[0]->price ]}, description: @{[ $_[0]->description ]}" } +sub init_priority { + 3 +} + 1; __END__ @@ -109,6 +114,11 @@ A localized short description of the origins of this price. A ref to the creating algorithm. +=item C + +OPTIONAL. Prices may supply a numerical priority. Higher will trump over lower, even when +supplying higher prices. Defaults to 3 (as in middle of 1-5). + =item C OPTIONAL. Both indicator and localized message that the price with this spec diff --git a/SL/PriceSource/PriceRules.pm b/SL/PriceSource/PriceRules.pm index 140706d47..e1d1c126b 100644 --- a/SL/PriceSource/PriceRules.pm +++ b/SL/PriceSource/PriceRules.pm @@ -92,6 +92,7 @@ sub make_price_from_rule { price => $self->price_for_rule($rule), spec => $rule->id, description => $rule->name, + priority => $rule->priority, price_source => $self, (invalid => t8('This Price Rule is no longer valid'))x!!$rule->obsolete, ) @@ -104,6 +105,7 @@ sub make_discount_from_rule { discount => $rule->discount / 100, spec => $rule->id, description => $rule->name, + priority => $rule->priority, price_source => $self, (invalid => t8('This Price Rule is no longer valid'))x!!$rule->obsolete, )