PriceSource: unknown Flag um "fast" korrekt durchzureichen
[kivitendo-erp.git] / SL / PriceSource / Price.pm
1 package SL::PriceSource::Price;
2
3 use strict;
4
5 use parent 'SL::DB::Object';
6 use Rose::Object::MakeMethods::Generic (
7   scalar => [ qw(price description spec price_source invalid missing unknown) ],
8   'scalar --get_set_init' => [ qw(priority editable) ],
9 );
10
11 require SL::DB::Helper::Attr;
12 SL::DB::Helper::Attr::make(__PACKAGE__,
13   price => 'numeric(15,5)',
14 );
15
16 sub source {
17   $_[0]->price_source
18   ? $_[0]->price_source->name . '/' . $_[0]->spec
19   : '';
20 }
21
22 sub full_description {
23   my ($self) = @_;
24
25   $self->price_source
26     ? $self->price_source->description . ': ' . $self->description
27     : $self->description
28 }
29
30 sub source_description {
31   my ($self) = @_;
32
33   $self->price_source
34     ? $self->price_source->description
35     : $self->description
36 }
37
38 sub to_str {
39   "source: @{[ $_[0]->source ]}, price: @{[ $_[0]->price ]}, description: @{[ $_[0]->description ]}"
40 }
41
42 sub init_priority {
43   3
44 }
45
46 sub init_editable {
47   0
48 }
49
50 1;
51
52 __END__
53
54 =encoding utf-8
55
56 =head1 NAME
57
58 SL::PriceSource::Price - container to pass calculated prices around
59
60 =head1 SYNOPSIS
61
62   # in PriceSource::Base implementation
63   $price = SL::PriceSource::Price->new(
64     price        => 10.3,
65     spec         => '3', # something you can easily parse later
66     description  => t8('Fix price 10.3 for customer 3'),
67     price_source => $self,
68   )
69
70   # special empty price in SL::PriceSource, for internal use.
71   SL::PriceSource::Price->new(
72     description => t8('None (PriceSource)'),
73   );
74
75   # price can't be restored
76   SL::PriceSource::Price->new(
77     missing      => t8('Um, sorry, cannot find that one'),
78     price_source => $self,
79   );
80
81   # invalid price
82   SL::PriceSource::Price->new(
83     price        => $original_price,
84     spec         => $original_spec,
85     description  => $original_description,
86     invalid      => t8('Offer expired #1 weeks ago', $dt->delta_weeks),
87     price_source => $self,
88   );
89
90 =head1 DESCRIPTION
91
92 See L<SL::PriceSource> for information about the mechanism.
93
94 This is a container for prices that are generated by L<SL::PriceSource::Base>
95 implementations.
96
97 =head1 CONSTRUCTOR FIELDS
98
99 =over 4
100
101 =item C<price>
102
103 The price. A price of 0 is special and is considered undesirable. If passed as
104 part of C<available_prices> it will be filtered out. If returned as
105 C<best_price> or C<price_from_source> it will trigger a warning.
106
107 =item C<spec>
108
109 A unique string that can later be understood by the creating implementation.
110 Can be empty if the implementation only supports one price for a given
111 record_item.
112
113 =item C<description>
114
115 A localized short description of the origins of this price.
116
117 =item C<price_source>
118
119 A ref to the creating algorithm.
120
121 =item C<priority>
122
123 OPTIONAL. Prices may supply a numerical priority. Higher will trump lower, even when
124 supplying higher prices. Defaults to 3 (as in middle of 1-5).
125
126 =item C<editable>
127
128 OPTIONAL. Prices may flag themselves as editable. An editable price will still
129 be subject to checks for higher or lower prices, but will be rendered in a
130 fashion that allows the user to overwrite it.
131
132 This is potentially very distracting if the price is usually a default price
133 and will be changed in a lot of instances so use with caution.
134
135 On the other hand it can provide the capability that users unfamiliar with the
136 system will intuitively expect so it can be a good way to introduce the system.
137
138 =item C<missing>
139
140 OPTIONAL. Both indicator and localized message that the price with this spec
141 could not be reproduced and should be changed.
142
143 If price is missing, you do not need to supply anything except C<source>.
144
145 =item C<invalid>
146
147 OPTIONAL. Both indicator and localized message that the conditions for this
148 price are no longer valid, and that the price should be changed.
149
150 If price is missing, you do not need to supply anything except C<source>.
151
152 =item C<unknown>
153
154 OPTIONAL. Boolean indicator that this price was not computed for performance
155 reasons. This is only valid for PriceSources flagged as C<fast>. This price
156 must be ignored.
157
158 =back
159
160 =head1 SEE ALSO
161
162 L<SL::PriceSource>,
163 L<SL::PriceSource::Base>,
164 L<SL::PriceSource::ALL>
165
166 =head1 BUGS
167
168 None yet. :)
169
170 =head1 AUTHOR
171
172 Sven Schoeling E<lt>s.schoeling@linet-services.deE<gt>
173
174 =cut