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