5 our @EXPORT_OK = qw(new_part new_service new_assembly new_assortment);
6 our %EXPORT_TAGS = (ALL => \@EXPORT_OK);
10 use SL::DB::Buchungsgruppe;
15 my $part = SL::DB::Part->new_part(
16 description => 'Test part',
19 buchungsgruppen_id => _default_buchungsgruppe()->id,
20 unit => _default_unit()->name
22 $part->assign_attributes( %params );
29 my $part = SL::DB::Part->new_service(
30 description => 'Test service',
33 buchungsgruppen_id => _default_buchungsgruppe()->id,
34 unit => _default_unit()->name
36 $part->assign_attributes( %params );
43 my $assnumber = delete $params{assnumber};
44 my $base_partnumber = delete $params{partnumber} || 'ap';
46 my $assembly_items = [];
48 if ( $params{assembly_items} ) {
49 $assembly_items = delete $params{assembly_items};
51 for my $i ( 1 .. delete $params{number_of_parts} || 3) {
52 my $part = new_part(partnumber => "$base_partnumber $i",
53 description => "Testpart $i",
55 push( @{$assembly_items}, SL::DB::Assembly->new(parts_id => $part->id,
62 my $assembly = SL::DB::Part->new_assembly(
63 partnumber => $assnumber,
64 description => 'Test Assembly',
67 assemblies => $assembly_items,
68 buchungsgruppen_id => _default_buchungsgruppe()->id,
69 unit => _default_unit()->name
71 $assembly->assign_attributes( %params );
78 my $assnumber = delete $params{assnumber};
79 my $base_partnumber = delete $params{partnumber} || 'ap';
81 my $assortment_items = [];
83 if ( $params{assortment_items} ) {
84 $assortment_items = delete $params{assortment_items};
86 for my $i ( 1 .. delete $params{number_of_parts} || 3) {
87 my $part = new_part(partnumber => "$base_partnumber $i",
88 description => "Testpart $i",
90 push( @{$assortment_items}, SL::DB::AssortmentItem->new(parts_id => $part->id,
98 my $assortment = SL::DB::Part->new_assortment(
99 partnumber => $assnumber,
100 description => 'Test Assortment',
103 assortment_items => $assortment_items,
104 buchungsgruppen_id => _default_buchungsgruppe()->id,
105 unit => _default_unit()->name
108 $assortment->assign_attributes( %params );
113 sub _default_buchungsgruppe {
114 return SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 19%') || die "No accounting group";
118 return SL::DB::Manager::Unit->find_by(name => 'Stck') || die "No unit";
128 SL::Dev::Part - create part objects for testing, with minimal defaults
132 use SL::Dev::Part qw(new_part new_assembly new_service new_assortment);
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;
140 # pass additional params to the generated object
141 # see individual functions for special parameters
143 partnumber => 'Test 001',
144 warehouse_id => $bin->warehouse->id,
150 =head2 C<new_part %PARAMS>
152 Creates a new part (part_type = part).
154 =head2 C<new_service %PARAMS>
156 Creates a new service (part_type = service).
158 =head2 C<new_assembly %PARAMS>
160 Create a new assembly (part_type = assembly).
166 =item * C<number_of_parts>
168 The number of automatically created assembly parts.
172 the partnumber of the assembly
174 =item * C<partnumber>
176 the partnumber of the first assembly part to be created
180 By default 3 parts (p1, p2, p3) are created and saved as an assembly (as1).
182 Create a new assembly with 10 parts, the assembly gets partnumber 'Ass1' and the
183 parts get partnumbers 'Testpart 1' to 'Testpart 10':
185 my $assembly = SL::Dev::Part::new_assembly(
186 number_of_parts => 10,
187 partnumber => 'Testpart',
191 Create an assembly with specific parts:
193 my $assembly_item_1 = SL::DB::Assembly->new( parts_id => $part1->id, qty => 3, position => 1);
194 my $assembly_item_2 = SL::DB::Assembly->new( parts_id => $part2->id, qty => 3, position => 2);
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 ],
202 =head2 C<new_assortment %PARAMS>
204 Create a new assortment (part_type = assortment).
210 =item * C<number_of_parts>
212 The number of automatically created assembly parts.
216 the partnumber of the assortment
218 =item * C<partnumber>
220 the partnumber of the first assembly part to be created
224 By default 3 parts (p1, p2, p3) are created and saved as an assortment.
226 Create a new assortment with 10 automatically created parts using the
227 number_of_parts param:
229 my $assortment = new_assortment(number_of_parts => 10)->save;
231 Create an assortment with a certain name and pass some assortment_item Objects
232 from newly created parts:
234 my $part1 = new_part(sellprice => 7.77)->save;
235 my $part2 = new_part(sellprice => 6.66)->save;
236 my $assortment_item_1 = SL::DB::AssortmentItem->new( parts_id => $part1->id, qty => 3, unit => $part1->unit, position => 1);
237 my $assortment_item_2 = SL::DB::AssortmentItem->new( parts_id => $part2->id, qty => 3, unit => $part2->unit, position => 2);
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 ],
256 G. Richardson E<lt>grichardson@kivitendo-premium.deE<gt>