1 package SL::PriceSource;
 
   4 use parent 'SL::DB::Object';
 
   5 use Rose::Object::MakeMethods::Generic (
 
   6   scalar => [ qw(record_item) ],
 
   9 use List::UtilsBy qw(min_by);
 
  10 use SL::PriceSource::ALL;
 
  11 use SL::PriceSource::Price;
 
  12 use SL::Locale::String;
 
  14 sub all_price_sources {
 
  18     $_->new(record_item => $self->record_item)
 
  19   } SL::PriceSource::ALL->all_price_sources
 
  22 sub price_from_source {
 
  23   my ($self, $source) = @_;
 
  24   my ($source_name, $spec) = split m{/}, $source, 2;
 
  26   my $class = SL::PriceSource::ALL->price_source_class_by_name($source_name);
 
  29     ? $class->new(record_item => $self->record_item)->price_from_source($source, $spec)
 
  33 sub available_prices {
 
  34   map { $_->available_prices } $_[0]->all_price_sources;
 
  38   min_by { $_->price } map { $_->best_price } $_[0]->all_price_sources;
 
  42   SL::PriceSource::Price->new(
 
  44     description => t8('None (PriceSource)'),
 
  56 SL::PriceSource - mixin for price_sources in record items
 
  60   # in record item class
 
  66   $record_item->all_price_sources
 
  67   $record_item->price_source      # get
 
  68   $record_item->price_source($c)  # set
 
  70   $record_item->update_price_source # set price to calculated
 
  74 This mixin provides a way to use price_source objects from within a record item.
 
  75 Record items in this contest mean OrderItems, InvoiceItems and
 
  82 returns a list of price_source objects which are created with the current record
 
  87 returns the object representing the currently chosen price_source method or
 
  88 undef if custom price is chosen. Note that this must not necessarily be the
 
  89 active price, if something affecting the price_source has changed, the price
 
  90 calculated can differ from the price in the record. It is the responsibility of
 
  91 the implementing code to decide what to do in this case.
 
  99 Sven Schoeling E<lt>s.schoeling@linet-services.deE<gt>