PriceSource: depends_on entfernt
[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) ],
8 );
9
10 use SL::DB::Helper::Attr;
11 SL::DB::Helper::Attr::make(__PACKAGE__,
12   price => 'numeric(15,5)',
13 );
14
15 sub source {
16   $_[0]->price_source
17   ?  $_[0]->price_source->name . '/' . $_[0]->spec
18   : '';
19 }
20
21 sub full_description {
22   my ($self) = @_;
23
24   $self->price_source
25     ? $self->price_source->description . ': ' . $self->description
26     : $self->description
27 }
28
29 sub to_str {
30   "source: @{[ $_[0]->source ]}, price: @{[ $_[0]->price]}, description: @{[ $_[0]->description ]}"
31 }
32
33 1;
34
35 __END__
36
37 =encoding utf-8
38
39 =head1 NAME
40
41 SL::PriceSource::Price - contrainer to pass calculated prices around
42
43 =head1 SYNOPSIS
44
45   # in PriceSource::Base implementation
46   $price = SL::PriceSource::Price->new(
47     price        => 10.3,
48     spec         => '10.3', # something you can easily parse later
49     description  => t8('Fix price 10.3'),
50     price_source => $self,
51   )
52
53   # special empty price in SL::PriceSource
54   SL::PriceSource::Price->new(
55     description => t8('None (PriceSource)'),
56   );
57
58   # invalid price
59   SL::PriceSource::Price->new(
60     price        => $original_price,
61     spec         => $original_spec,
62     description  => $original_description,
63     invalid      => t8('Offer expired #1 weeks ago', $dt->delta_weeks),
64     price_source => $self,
65   );
66
67   # missing price
68   SL::PriceSource::Price->new(
69     price        => $original_price,              # will keep last entered price
70     spec         => $original_spec,
71     description  => '',
72     missing      => t8('Um, sorry, cannot find that one'),
73     price_source => $self,
74   );
75
76
77 =head1 DESCRIPTION
78
79 See L<SL::PriceSource> for information about the mechanism.
80
81 This is a container for prices that are generated by L<SL::PriceSource::Base>
82 implementations.
83
84 =head1 CONSTRUCTOR FIELDS
85
86 =over 4
87
88 =item C<price>
89
90 The price. A price of 0 is special and is considered undesirable. If passed as
91 part of C<available_prices> it will be filtered out. If returned as
92 C<best_price> or C<price_from_source> it will be warned about.
93
94 =item C<spec>
95
96 A unique string that can later be understood by the creating implementation.
97 Can be empty if the implementation only supports one price for a given
98 record_item.
99
100 =item C<description>
101
102 A localized short description of the origins of this price.
103
104 =item C<price_source>
105
106 A ref to the creating algorithm.
107
108 =item C<missing>
109
110 OPTIONAL. Both indicator and localized message that the price with this spec
111 could not be reproduced and should be changed.
112
113 =item C<invalid>
114
115 OPTIONAL. Both indicator and localized message that the conditions for this
116 price are no longer valid, and that the price should be changed.
117
118 =back
119
120 =head1 SEE ALSO
121
122 L<SL::PriceSource>,
123 L<SL::PriceSource::Base>,
124 L<SL::PriceSource::ALL>
125
126 =head1 BUGS
127
128 None yet. :)
129
130 =head1 AUTHOR
131
132 Sven Schoeling E<lt>s.schoeling@linet-services.deE<gt>
133
134 =cut