SL::Dev::* - neue Helpermodule für Testcases und console
[kivitendo-erp.git] / SL / Dev / Part.pm
1 package SL::Dev::Part;
2
3 use base qw(Exporter);
4 @EXPORT = qw(create_part create_service);
5
6 use SL::DB::Part;
7 use SL::DB::Unit;
8 use SL::DB::Buchungsgruppe;
9
10 sub create_part {
11   my (%params) = @_;
12
13   my ($buchungsgruppe, $unit);
14   $buchungsgruppe  = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 19%') || die "No accounting group";
15   $unit            = SL::DB::Manager::Unit->find_by(name => 'Stck')                          || die "No unit";
16
17   my $part = SL::DB::Part->new_part(
18     description        => 'Test part',
19     sellprice          => '10',
20     lastcost           => '5',
21     buchungsgruppen_id => $buchungsgruppe->id,
22     unit               => $unit->name,
23   );
24   $part->assign_attributes( %params );
25   return $part;
26 }
27
28 sub create_service {
29   my (%params) = @_;
30
31   my ($buchungsgruppe, $unit);
32   $buchungsgruppe  = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 19%') || die "No accounting group";
33   $unit            = SL::DB::Manager::Unit->find_by(name => 'Stck')                          || die "No unit";
34
35   my $part = SL::DB::Part->new_service(
36     description        => 'Test service',
37     sellprice          => '10',
38     lastcost           => '5',
39     buchungsgruppen_id => $buchungsgruppe->id,
40     unit               => $unit->name,
41   );
42   $part->assign_attributes( %params );
43   return $part;
44 }
45
46 1;
47
48 __END__
49
50 =head1 NAME
51
52 SL::Dev::Part - create part objects for testing, with minimal defaults
53
54 =head1 FUNCTIONS
55
56 =head2 C<create_part %PARAMS>
57
58 Creates a new part (part_type = part).
59
60 Minimal usage, default values, without saving to database:
61
62   my $part = SL::Dev::Part::create_part();
63
64 Create a test part with a default warehouse and bin and save it:
65
66   my $wh    = SL::Dev::Inventory::create_warehouse_and_bins()->save;
67   my $part1 = SL::Dev::Part::create_part(partnumber   => 'a123',
68                                          description  => 'Testpart 1',
69                                          warehouse_id => $wh->id,
70                                          bin_id       => $wh->bins->[0]->id,
71                                         )->save;
72
73 =head1 TODO
74
75 =over 2
76
77 =item * create_assembly
78
79 =back
80
81 =head1 BUGS
82
83 Nothing here yet.
84
85 =head1 AUTHOR
86
87 G. Richardson E<lt>grichardson@kivitendo-premium.deE<gt>
88
89 =cut