Revision cf3a8cf7
Von Sven Schöling vor mehr als 7 Jahren hinzugefügt
SL/Dev/Part.pm | ||
---|---|---|
2 | 2 |
|
3 | 3 |
use strict; |
4 | 4 |
use base qw(Exporter); |
5 |
our @EXPORT = qw(create_part create_service create_assembly create_assortment); |
|
5 |
our @EXPORT_OK = qw(new_part new_service new_assembly new_assortment); |
|
6 |
our %EXPORT_TAGS = (ALL => \@EXPORT_OK); |
|
6 | 7 |
|
7 | 8 |
use SL::DB::Part; |
8 | 9 |
use SL::DB::Unit; |
9 | 10 |
use SL::DB::Buchungsgruppe; |
10 | 11 |
|
11 |
sub create_part {
|
|
12 |
sub new_part {
|
|
12 | 13 |
my (%params) = @_; |
13 | 14 |
|
14 | 15 |
my $part = SL::DB::Part->new_part( |
... | ... | |
22 | 23 |
return $part; |
23 | 24 |
} |
24 | 25 |
|
25 |
sub create_service {
|
|
26 |
sub new_service {
|
|
26 | 27 |
my (%params) = @_; |
27 | 28 |
|
28 | 29 |
my $part = SL::DB::Part->new_service( |
... | ... | |
36 | 37 |
return $part; |
37 | 38 |
} |
38 | 39 |
|
39 |
sub create_assembly {
|
|
40 |
sub new_assembly {
|
|
40 | 41 |
my (%params) = @_; |
41 | 42 |
|
42 | 43 |
my $assnumber = delete $params{assnumber}; |
... | ... | |
48 | 49 |
$assembly_items = delete $params{assembly_items}; |
49 | 50 |
} else { |
50 | 51 |
for my $i ( 1 .. delete $params{number_of_parts} || 3) { |
51 |
my $part = SL::Dev::Part::create_part(partnumber => "$base_partnumber $i",
|
|
52 |
description => "Testpart $i",
|
|
53 |
)->save;
|
|
52 |
my $part = new_part(partnumber => "$base_partnumber $i",
|
|
53 |
description => "Testpart $i", |
|
54 |
)->save; |
|
54 | 55 |
push( @{$assembly_items}, SL::DB::Assembly->new(parts_id => $part->id, |
55 | 56 |
qty => 1, |
56 | 57 |
position => $i, |
... | ... | |
71 | 72 |
return $assembly; |
72 | 73 |
} |
73 | 74 |
|
74 |
sub create_assortment {
|
|
75 |
sub new_assortment {
|
|
75 | 76 |
my (%params) = @_; |
76 | 77 |
|
77 | 78 |
my $assnumber = delete $params{assnumber}; |
... | ... | |
83 | 84 |
$assortment_items = delete $params{assortment_items}; |
84 | 85 |
} else { |
85 | 86 |
for my $i ( 1 .. delete $params{number_of_parts} || 3) { |
86 |
my $part = SL::Dev::Part::create_part(partnumber => "$base_partnumber $i",
|
|
87 |
description => "Testpart $i",
|
|
88 |
)->save;
|
|
87 |
my $part = new_part(partnumber => "$base_partnumber $i",
|
|
88 |
description => "Testpart $i", |
|
89 |
)->save; |
|
89 | 90 |
push( @{$assortment_items}, SL::DB::AssortmentItem->new(parts_id => $part->id, |
90 | 91 |
qty => 1, |
91 | 92 |
position => $i, |
... | ... | |
126 | 127 |
|
127 | 128 |
SL::Dev::Part - create part objects for testing, with minimal defaults |
128 | 129 |
|
130 |
=head1 SYNOPSIS |
|
131 |
|
|
132 |
use SL::DEV::Part qw(new_part new_assembly new_service new_assortment); |
|
133 |
|
|
134 |
# simple default objects |
|
135 |
my $part = new_part()->save; |
|
136 |
my $assembly = new_assembly()->save; |
|
137 |
my $service = new_service()->save; |
|
138 |
my $assortment = new_assortment()->save; |
|
139 |
|
|
140 |
# pass additional params to the generated object |
|
141 |
# see individual functions for special parameters |
|
142 |
my $part = new_part( |
|
143 |
partnumber => 'Test 001', |
|
144 |
warehouse_id => $bin->warehouse->id, |
|
145 |
bin_id => $bin->id, |
|
146 |
); |
|
147 |
|
|
129 | 148 |
=head1 FUNCTIONS |
130 | 149 |
|
131 |
=head2 C<create_part %PARAMS>
|
|
150 |
=head2 C<new_part %PARAMS>
|
|
132 | 151 |
|
133 | 152 |
Creates a new part (part_type = part). |
134 | 153 |
|
135 |
Minimal usage, default values, without saving to database: |
|
154 |
=head2 C<new_service %PARAMS> |
|
155 |
|
|
156 |
Creates a new service (part_type = service). |
|
136 | 157 |
|
137 |
my $part = SL::Dev::Part::create_part();
|
|
158 |
=head2 C<new_assembly %PARAMS>
|
|
138 | 159 |
|
139 |
Create a test part with a default warehouse and bin and save it:
|
|
160 |
Create a new assembly (part_type = assembly).
|
|
140 | 161 |
|
141 |
my $wh = SL::Dev::Inventory::create_warehouse_and_bins()->save; |
|
142 |
my $part1 = SL::Dev::Part::create_part(partnumber => 'a123', |
|
143 |
description => 'Testpart 1', |
|
144 |
warehouse_id => $wh->id, |
|
145 |
bin_id => $wh->bins->[0]->id, |
|
146 |
)->save; |
|
162 |
Special params: |
|
147 | 163 |
|
148 |
=head2 C<create_service %PARAMS>
|
|
164 |
=over 2
|
|
149 | 165 |
|
150 |
Creates a new service (part_type = service).
|
|
166 |
=item * C<number_of_parts>
|
|
151 | 167 |
|
152 |
Minimal usage, default values, without saving to database:
|
|
168 |
The number of automatically created assembly parts.
|
|
153 | 169 |
|
154 |
my $part = SL::Dev::Part::create_service();
|
|
170 |
=item * C<assnumber>
|
|
155 | 171 |
|
156 |
=head2 C<create_assembly %PARAMS>
|
|
172 |
the partnumber of the assembly
|
|
157 | 173 |
|
158 |
Create a new assembly (part_type = assembly).
|
|
174 |
=item * C<partnumber>
|
|
159 | 175 |
|
160 |
Params: assnumber: the partnumber of the assembly |
|
161 |
partnumber: the partnumber of the first assembly part to be created |
|
176 |
the partnumber of the first assembly part to be created |
|
162 | 177 |
|
163 |
By default 3 parts (p1, p2, p3) are created and saved as an assembly (as1).
|
|
178 |
=back
|
|
164 | 179 |
|
165 |
my $assembly = SL::Dev::Part::create_assembly->save;
|
|
180 |
By default 3 parts (p1, p2, p3) are created and saved as an assembly (as1).
|
|
166 | 181 |
|
167 | 182 |
Create a new assembly with 10 parts, the assembly gets partnumber 'Ass1' and the |
168 | 183 |
parts get partnumbers 'Testpart 1' to 'Testpart 10': |
169 | 184 |
|
170 |
my $assembly = SL::Dev::Part::create_assembly(number_of_parts => 10, |
|
171 |
partnumber => 'Testpart', |
|
172 |
assnumber => 'Ass1' |
|
173 |
)->save; |
|
185 |
my $assembly = SL::Dev::Part::new_assembly( |
|
186 |
number_of_parts => 10, |
|
187 |
partnumber => 'Testpart', |
|
188 |
assnumber => 'Ass1' |
|
189 |
)->save; |
|
174 | 190 |
|
175 | 191 |
Create an assembly with specific parts: |
192 |
|
|
176 | 193 |
my $assembly_item_1 = SL::DB::Assembly->new( parts_id => $part1->id, qty => 3, position => 1); |
177 | 194 |
my $assembly_item_2 = SL::DB::Assembly->new( parts_id => $part2->id, qty => 3, position => 2); |
178 |
my $assembly_part = SL::Dev::Part::create_assembly( assnumber => 'Assembly 1', |
|
179 |
description => 'Assembly test', |
|
180 |
sellprice => $part1->sellprice + $part2->sellprice, |
|
181 |
assembly_items => [ $assembly_item_1, $assembly_item_2 ], |
|
182 |
)->save; |
|
195 |
my $assembly_part = new_assembly( |
|
196 |
assnumber => 'Assembly 1', |
|
197 |
description => 'Assembly test', |
|
198 |
sellprice => $part1->sellprice + $part2->sellprice, |
|
199 |
assembly_items => [ $assembly_item_1, $assembly_item_2 ], |
|
200 |
); |
|
183 | 201 |
|
184 |
=head2 C<create_assortment %PARAMS>
|
|
202 |
=head2 C<new_assortment %PARAMS>
|
|
185 | 203 |
|
186 | 204 |
Create a new assortment (part_type = assortment). |
187 | 205 |
|
188 |
By default 3 parts (p1, p2, p3) are created and saved as an assortment. |
|
206 |
Special params: |
|
207 |
|
|
208 |
=over 2 |
|
209 |
|
|
210 |
=item * C<number_of_parts> |
|
211 |
|
|
212 |
The number of automatically created assembly parts. |
|
189 | 213 |
|
190 |
my $assortment = SL::Dev::Part::create_assortment->save; |
|
214 |
=item * C<assnumber> |
|
215 |
|
|
216 |
the partnumber of the assortment |
|
217 |
|
|
218 |
=item * C<partnumber> |
|
219 |
|
|
220 |
the partnumber of the first assembly part to be created |
|
221 |
|
|
222 |
=back |
|
223 |
|
|
224 |
By default 3 parts (p1, p2, p3) are created and saved as an assortment. |
|
191 | 225 |
|
192 | 226 |
Create a new assortment with 10 automatically created parts using the |
193 | 227 |
number_of_parts param: |
194 | 228 |
|
195 |
my $assortment = SL::Dev::Part::create_assortment(number_of_parts => 10)->save;
|
|
229 |
my $assortment = new_assortment(number_of_parts => 10)->save;
|
|
196 | 230 |
|
197 | 231 |
Create an assortment with a certain name and pass some assortment_item Objects |
198 | 232 |
from newly created parts: |
199 | 233 |
|
200 |
my $part1 = SL::Dev::Part::create_part( sellprice => '7.77')->save;
|
|
201 |
my $part2 = SL::Dev::Part::create_part( sellprice => '6.66')->save;
|
|
234 |
my $part1 = new_part(sellprice => 7.77)->save;
|
|
235 |
my $part2 = new_part(sellprice => 6.66)->save;
|
|
202 | 236 |
my $assortment_item_1 = SL::DB::AssortmentItem->new( parts_id => $part1->id, qty => 3, unit => $part1->unit, position => 1); |
203 | 237 |
my $assortment_item_2 = SL::DB::AssortmentItem->new( parts_id => $part2->id, qty => 3, unit => $part2->unit, position => 2); |
204 |
my $assortment_part = SL::Dev::Part::create_assortment( assnumber => 'Assortment 1', |
|
205 |
description => 'assortment test', |
|
206 |
sellprice => (3*$part1->sellprice + 3*$part2->sellprice), |
|
207 |
lastcost => (3*$part1->lastcost + 3*$part2->lastcost), |
|
208 |
assortment_items => [ $assortment_item_1, $assortment_item_2 ], |
|
209 |
)->save; |
|
238 |
my $assortment_part = SL::Dev::Part::new_assortment( |
|
239 |
assnumber => 'Assortment 1', |
|
240 |
description => 'assortment test', |
|
241 |
sellprice => (3*$part1->sellprice + 3*$part2->sellprice), |
|
242 |
lastcost => (3*$part1->lastcost + 3*$part2->lastcost), |
|
243 |
assortment_items => [ $assortment_item_1, $assortment_item_2 ], |
|
244 |
)->save; |
|
210 | 245 |
|
211 | 246 |
=head1 TODO |
212 | 247 |
|
Auch abrufbar als: Unified diff
SL::Dev: EXPORT rewrite und create/new split
- SL::Dev module exportieren nicht mehr ungefragt
- SL::Dev::ALL exportiert jetzt den übergebenen tag aus allen Modulen
- Funktionen nicht nicht speichern (Part/CustomerVendor) heißen jetzt
"new_X" anstatt "create_X"