Revision adecbacd
Von Sven Schöling vor etwa 14 Jahren hinzugefügt
SL/DB/Part.pm | ||
---|---|---|
25 | 25 |
sub is_type { |
26 | 26 |
my $self = shift; |
27 | 27 |
my $type = lc(shift || ''); |
28 |
die 'invalid type' unless $type =~ /^(?:part|service|assembly)$/; |
|
28 | 29 |
|
29 |
if ($type =~ m/^part/) { |
|
30 |
return !$self->assembly && $self->inventory_accno_id ? 1 : 0; |
|
31 |
|
|
32 |
} elsif ($type =~ m/^service/) { |
|
33 |
return !$self->inventory_accno_id && !$self->assembly ? 1 : 0; |
|
30 |
return $self->type eq $type ? 1 : 0; |
|
31 |
} |
|
34 | 32 |
|
35 |
} elsif ($type =~ m/^assembl/) { |
|
36 |
return $self->assembly ? 1 : 0; |
|
33 |
sub is_part { $_[0]->is_type('part') } |
|
34 |
sub is_assembly { $_[0]->is_type('assembly') } |
|
35 |
sub is_service { $_[0]->is_type('service') } |
|
37 | 36 |
|
37 |
sub type { |
|
38 |
my ($self, $type) = @_; |
|
39 |
if (@_ > 1) { |
|
40 |
die 'invalid type' unless $type =~ /^(?:part|service|assembly)$/; |
|
41 |
$self->assembly( $type eq 'assembly' ? 1 : 0); |
|
42 |
$self->inventory_accno_id($type ne 'service' ? 1 : undef); |
|
38 | 43 |
} |
39 | 44 |
|
40 |
confess "Unknown type parameter '$type'"; |
|
45 |
return 'assembly' if $self->assembly; |
|
46 |
return 'part' if $self->inventory_accno_id; |
|
47 |
return 'service'; |
|
48 |
} |
|
49 |
|
|
50 |
sub new_part { |
|
51 |
my ($class, %params) = @_; |
|
52 |
$class->new(%params, type => 'part'); |
|
53 |
} |
|
54 |
|
|
55 |
sub new_assembly { |
|
56 |
my ($class, %params) = @_; |
|
57 |
$class->new(%params, type => 'assembly'); |
|
58 |
} |
|
59 |
|
|
60 |
sub new_service { |
|
61 |
my ($class, %params) = @_; |
|
62 |
$class->new(%params, type => 'service'); |
|
63 |
} |
|
64 |
|
|
65 |
sub orphaned { |
|
66 |
my ($self) = @_; |
|
67 |
die 'not an accessor' if @_ > 1; |
|
68 |
|
|
69 |
my @relations = qw( |
|
70 |
SL::DB::InvoiceItem |
|
71 |
SL::DB::OrderItem |
|
72 |
SL::DB::Inventory |
|
73 |
SL::DB::RMAItem |
|
74 |
); |
|
75 |
|
|
76 |
for my $class (@relations) { |
|
77 |
eval "require $class"; |
|
78 |
return 0 if $class->_get_manager_class->get_all_count(query => [ parts_id => $self->id ]); |
|
79 |
} |
|
80 |
return 1; |
|
41 | 81 |
} |
42 | 82 |
|
43 | 83 |
sub get_sellprice_info { |
... | ... | |
77 | 117 |
|
78 | 118 |
This is a standard Rose::DB::Object based model and can be used as one. |
79 | 119 |
|
80 |
=head1 FUNCTIONS |
|
120 |
=head1 TYPES |
|
121 |
|
|
122 |
Although the base class is called C<Part> we usually talk about C<Articles> if |
|
123 |
we mean instances of this class. This is because articles come in three |
|
124 |
flavours called: |
|
81 | 125 |
|
82 | 126 |
=over 4 |
83 | 127 |
|
84 |
=item is_type $type |
|
128 |
=item Part - a single part |
|
129 |
|
|
130 |
=item Service - a part without onhand, and without inventory accounting |
|
131 |
|
|
132 |
=item Assembly - a collection of both parts and services |
|
133 |
|
|
134 |
=back |
|
135 |
|
|
136 |
These types are sadly represented by data inside the class and cannot be |
|
137 |
migrated into a flag. To work around this, each C<Part> object knows what type |
|
138 |
it currently is. Since the type ist data driven, there ist no explicit setting |
|
139 |
method for it, but you can construct them explicitly with C<new_part>, |
|
140 |
C<new_service>, and C<new_assembly>. A Buchungsgruppe should be supplied in this |
|
141 |
case, but it will use the default Buchungsgruppe if you don't. |
|
142 |
|
|
143 |
Matching these there are assorted helper methods dealing with type: |
|
144 |
|
|
145 |
=head2 new_part PARAMS |
|
146 |
|
|
147 |
=head2 new_service PARAMS |
|
148 |
|
|
149 |
=head2 new_assembly PARAMS |
|
150 |
|
|
151 |
Will set the appropriate data fields so that the resulting instance will be of |
|
152 |
tthe requested type. Since part of the distinction are accounting targets, |
|
153 |
providing a C<Buchungsgruppe> is recommended. If none is given the constructor |
|
154 |
will load a default one and set the accounting targets from it. |
|
155 |
|
|
156 |
=head2 type |
|
157 |
|
|
158 |
Returns the type as a string. Can be one of C<part>, C<service>, C<assembly>. |
|
159 |
|
|
160 |
=head2 is_type TYPE |
|
85 | 161 |
|
86 | 162 |
Tests if the current object is a part, a service or an |
87 | 163 |
assembly. C<$type> must be one of the words 'part', 'service' or |
... | ... | |
90 | 166 |
Returns 1 if the requested type matches, 0 if it doesn't and |
91 | 167 |
C<confess>es if an unknown C<$type> parameter is encountered. |
92 | 168 |
|
93 |
=item get_sellprice_info %params |
|
169 |
=head2 is_part |
|
170 |
|
|
171 |
=head2 is_service |
|
172 |
|
|
173 |
=head2 is_assembly |
|
174 |
|
|
175 |
Shorthand for is_type('part') etc. |
|
176 |
|
|
177 |
=head1 FUNCTIONS |
|
178 |
|
|
179 |
=head2 get_sellprice_info %params |
|
94 | 180 |
|
95 | 181 |
Retrieves the C<sellprice> and C<price_factor_id> for a part under |
96 | 182 |
different conditions and returns a hash reference with those two keys. |
... | ... | |
104 | 190 |
If none of the above conditions is met then the information from |
105 | 191 |
C<$self> is used. |
106 | 192 |
|
107 |
=item get_ordered_qty %params
|
|
193 |
=head2 get_ordered_qty %params
|
|
108 | 194 |
|
109 | 195 |
Retrieves the quantity that has been ordered from a vendor but that |
110 | 196 |
has not been delivered yet. Only open purchase orders are considered. |
111 | 197 |
|
112 |
=item get_uncommissioned_qty %params
|
|
198 |
=head2 orphaned
|
|
113 | 199 |
|
114 |
Retrieves the quantity that has been ordered by a customer but that
|
|
115 |
has not been commissioned yet. Only open sales orders are considered.
|
|
200 |
Checks if this articke is used in orders, invoices, delivery orders or
|
|
201 |
assemblies.
|
|
116 | 202 |
|
117 |
=back |
|
203 |
=head2 buchungsgruppe BUCHUNGSGRUPPE |
|
204 |
|
|
205 |
Used to set the accounting informations from a L<SL:DB::Buchungsgruppe> object. |
|
206 |
Please note, that this is a write only accessor, the original Buchungsgruppe can |
|
207 |
not be retrieved from an article once set. |
|
118 | 208 |
|
119 | 209 |
=head1 AUTHOR |
120 | 210 |
|
Auch abrufbar als: Unified diff
SL::DB::Part.pm - types, methoden, doku
type modell santizied.
orphaned funktion erstellt.
Dokumentation erwitert.