Revision df1b03d5
Von Sven Schöling vor mehr als 9 Jahren hinzugefügt
SL/PriceSource/Pricegroup.pm | ||
---|---|---|
4 | 4 |
use parent qw(SL::PriceSource::Base); |
5 | 5 |
|
6 | 6 |
use SL::PriceSource::Price; |
7 |
use SL::DB::Price; |
|
7 | 8 |
use SL::Locale::String; |
8 | 9 |
use List::UtilsBy qw(min_by); |
9 | 10 |
use List::Util qw(first); |
... | ... | |
15 | 16 |
sub available_prices { |
16 | 17 |
my ($self, %params) = @_; |
17 | 18 |
|
19 |
return () unless $self->record->is_sales; |
|
20 |
|
|
18 | 21 |
my $item = $self->record_item; |
19 | 22 |
|
20 | 23 |
my $prices = SL::DB::Manager::Price->get_all( |
... | ... | |
33 | 36 |
sub price_from_source { |
34 | 37 |
my ($self, $source, $spec) = @_; |
35 | 38 |
|
36 |
my $price = SL::DB::Manager::Price->find_by(id => $spec);
|
|
39 |
my $price = SL::DB::Manager::Price->find_by(pricegroup_id => $spec, parts_id => $self->part->id);
|
|
37 | 40 |
|
41 |
# TODO: if someone deletes the prices entry, this fails. add a fallback |
|
38 | 42 |
return $self->make_price($price); |
39 | 43 |
} |
40 | 44 |
|
41 | 45 |
sub best_price { |
42 | 46 |
my ($self, %params) = @_; |
43 | 47 |
|
44 |
my @prices = $self->availabe_prices; |
|
48 |
return () unless $self->record->is_sales; |
|
49 |
|
|
50 |
my @prices = $self->available_prices; |
|
45 | 51 |
my $customer = $self->record->customer; |
46 |
my $min_price = min_by { $_->price } @prices; |
|
47 | 52 |
|
48 |
return $min_price if !$customer || !$customer->cv_klass;
|
|
53 |
return () if !$customer || !$customer->klass;
|
|
49 | 54 |
|
50 |
my $best_price = first { $_->spec == $customer->cv_class } @prices;
|
|
55 |
my $best_price = first { $_->spec == $customer->klass } @prices;
|
|
51 | 56 |
|
52 |
return $best_price || $min_price;
|
|
57 |
return $best_price || ();
|
|
53 | 58 |
} |
54 | 59 |
|
55 | 60 |
sub make_price { |
... | ... | |
57 | 62 |
|
58 | 63 |
SL::PriceSource::Price->new( |
59 | 64 |
price => $price_obj->price, |
60 |
spec => $price_obj->id, |
|
65 |
spec => $price_obj->pricegroup->id,
|
|
61 | 66 |
description => $price_obj->pricegroup->pricegroup, |
62 | 67 |
price_source => $self, |
63 | 68 |
) |
Auch abrufbar als: Unified diff
PriceSource: Featureabdeckung
- Einkaufs/Verkauf abgedeckt
- Klarere Regeln für price_from_source, available_prices und best_price
- makemodels unterstützung
- bugfixes für Rechnungen und neue Belege
- best_price jetzt getestet
- Verkäuferabhängigkeit von makemodels und pricegroup implementiert und getestet