X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/c21d2acca00997c4ca0be66f053dfdd0180f68f8..eebe8e90991eacadb6fbd20a648c152017a620c7:/SL/PriceSource/Base.pm?ds=inline diff --git a/SL/PriceSource/Base.pm b/SL/PriceSource/Base.pm new file mode 100644 index 000000000..618512d94 --- /dev/null +++ b/SL/PriceSource/Base.pm @@ -0,0 +1,107 @@ +package SL::PriceSource::Base; + +use strict; + +use parent qw(SL::DB::Object); +use Rose::Object::MakeMethods::Generic ( + scalar => [ qw(record_item record) ], +); + +sub name { die 'name needs to be implemented' } + +sub description { die 'description needs to be implemented' } + +sub available_prices { die 'available_prices needs to be implemented' } + +sub best_price { die 'best_price needs to be implemented' } + +sub price_from_source { die 'price_from_source needs to be implemented:' . "@_" } + +sub part { + $_[0]->record_item->part; +} + +1; + +__END__ + +=encoding utf-8 + +=head1 NAME + +SL::PriceSource::Base - + +=head1 SYNOPSIS + + # in consuming module +# TODO: thats bullshit, theres no need to have this pollute the namespace +# make a manager that handles this + + my @list_of_price_sources = $record_item->price_sources; + for (@list_of_price_sources) { + my $internal_name = $_->name; + my $translated_name = $_->description; + my $price = $_->price; + } + + $record_item->set_active_price_source($price_source) # equivalent to: + $record_item->active_price_source($price_source->name); + $record_item->sellprice($price_source->price); + + # for finer control + $price_source->needed_params + $price_source->supported_params + +=head1 DESCRIPTION + +PriceSource is an interface that allows generic algorithms to be used, to +calculate a price for a position in a record. + +If any such price_source algorithm is known to the system, a user can chose +which of them should be used to claculate the price displayed in the record. + +The algorithm is saved togetherwith the target price, so that changes in the +record can recalculate the price accordingly, and otherwise manual changes to +the price can reset the price_source used to custom (aka no price_source). + +=head1 INTERFACE METHODS + +=over 4 + +=item C + +Should return a unique internal name. Should be entered in +L so that a name_to_class lookup works. + +=item C + +Should return a translated name. + +=item C + +Should return a list of elements that a record_item NEEDS to be used with this calulation. + +Both C nad C are purely informational at this point. + +=item C + +Should return a list of elements that a record_item MAY HAVE to be used with this calulation. + +Both C nad C are purely informational at this point. + +=item C + +Calculate a price and return. Do not mutate the record_item. Should will return +undef if price is not applicable to the current record_item. + +=back + +=head1 BUGS + +None yet. :) + +=head1 AUTHOR + +Sven Schoeling Es.schoeling@linet-services.deE + +=cut