1 package SL::PriceSource::Makemodel;
4 use parent qw(SL::PriceSource::Base);
6 use SL::PriceSource::Price;
7 use SL::Locale::String;
9 use List::UtilsBy qw(min_by);
11 sub name { 'makemodel' }
13 sub description { t8('Makemodel Price') }
15 sub available_prices {
16 my ($self, %params) = @_;
18 return () if !$self->part;
19 return () if $self->record->is_sales;
21 map { $self->make_price_from_makemodel($_) }
22 grep { $_->make == $self->record->vendor_id }
23 $self->part->makemodels;
26 sub available_discounts { }
28 sub price_from_source {
29 my ($self, $source, $spec) = @_;
31 my $makemodel = SL::DB::Manager::MakeModel->find_by(id => $spec);
33 return SL::PriceSource::Price->new(
34 price_source => $self,
35 missing => t8('This makemodel price does not exist anymore'),
38 return $self->make_price_from_makemodel($makemodel);
42 sub discount_from_source { }
45 my ($self, %params) = @_;
47 return () if $self->record->is_sales;
49 min_by { $_->price } $self->available_prices;
55 sub make_price_from_makemodel {
56 my ($self, $makemodel) = @_;
58 return SL::PriceSource::Price->new(
59 price => $makemodel->lastcost,
60 spec => $makemodel->id,
61 description => $makemodel->model,
62 price_source => $self,