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