PriceSource: Erste Version
[kivitendo-erp.git] / SL / PriceSource / Base.pm
1 package SL::PriceSource::Base;
2
3 use strict;
4
5 use parent qw(SL::DB::Object);
6 use Rose::Object::MakeMethods::Generic (
7   scalar => [ qw(record_item record) ],
8 );
9
10 sub name { die 'name needs to be implemented' }
11
12 sub description { die 'description needs to be implemented' }
13
14 sub available_prices { die 'available_prices needs to be implemented' }
15
16 sub best_price { die 'best_price needs to be implemented' }
17
18 sub price_from_source { die 'price_from_source needs to be implemented:' . "@_" }
19
20 sub part {
21   $_[0]->record_item->part;
22 }
23
24 1;
25
26 __END__
27
28 =encoding utf-8
29
30 =head1 NAME
31
32 SL::PriceSource::Base - <oneliner description>
33
34 =head1 SYNOPSIS
35
36   # in consuming module
37 # TODO: thats bullshit, theres no need to have this pollute the namespace
38 # make a manager that handles this
39
40   my @list_of_price_sources = $record_item->price_sources;
41   for (@list_of_price_sources) {
42     my $internal_name   = $_->name;
43     my $translated_name = $_->description;
44     my $price           = $_->price;
45   }
46
47   $record_item->set_active_price_source($price_source)  # equivalent to:
48   $record_item->active_price_source($price_source->name);
49   $record_item->sellprice($price_source->price);
50
51   # for finer control
52   $price_source->needed_params
53   $price_source->supported_params
54
55 =head1 DESCRIPTION
56
57 PriceSource is an interface that allows generic algorithms to be used, to
58 calculate a price for a position in a record.
59
60 If any such price_source algorithm is known to the system, a user can chose
61 which of them should be used to claculate the price displayed in the record.
62
63 The algorithm is saved togetherwith the target price, so that changes in the
64 record can recalculate the price accordingly, and otherwise manual changes to
65 the price can reset the price_source used to custom (aka no price_source).
66
67 =head1 INTERFACE METHODS
68
69 =over 4
70
71 =item C<name>
72
73 Should return a unique internal name. Should be entered in
74 L<SL::PriceSource::ALL> so that a name_to_class lookup works.
75
76 =item C<description>
77
78 Should return a translated name.
79
80 =item C<needed_params>
81
82 Should return a list of elements that a record_item NEEDS to be used with this calulation.
83
84 Both C<needed_params> nad C<supported_params> are purely informational at this point.
85
86 =item C<supported_params>
87
88 Should return a list of elements that a record_item MAY HAVE to be used with this calulation.
89
90 Both C<needed_params> nad C<supported_params> are purely informational at this point.
91
92 =item C<price>
93
94 Calculate a price and return. Do not mutate the record_item. Should will return
95 undef if price is not applicable to the current record_item.
96
97 =back
98
99 =head1 BUGS
100
101 None yet. :)
102
103 =head1 AUTHOR
104
105 Sven Schoeling E<lt>s.schoeling@linet-services.deE<gt>
106
107 =cut