SL::Dev::* - neue Helpermodule für Testcases und console
[kivitendo-erp.git] / SL / Dev / CustomerVendor.pm
1 package SL::Dev::CustomerVendor;
2
3 use base qw(Exporter);
4 @EXPORT = qw(create_customer);
5
6 use SL::DB::TaxZone;
7 use SL::DB::Currency;
8 use SL::DB::Customer;
9
10 sub create_customer {
11   my (%params) = @_;
12
13   my ($taxzone, $currency);
14
15   if ( my $taxzone_id = delete $params{taxzone_id} ) {
16     $taxzone = SL::DB::Manager::TaxZone->find_by( id => $taxzone_id ) || die "Can't find taxzone_id";
17   } else {
18     $taxzone = SL::DB::Manager::TaxZone->find_by( description => 'Inland') || die "No taxzone 'Inland'";
19   }
20
21   if ( my $currency_id = delete $params{currency_id} ) {
22     $currency = SL::DB::Manager::Currency->find_by( id => $currency_id ) || die "Can't find currency_id";
23   } else {
24     $currency = SL::DB::Manager::Currency->find_by( id => $::instance_conf->get_currency_id );
25   }
26
27   my $customer = SL::DB::Customer->new( name        => delete $params{name} || 'Testkunde',
28                                         currency_id => $currency->id,
29                                         taxzone_id  => $taxzone->id,
30                                       );
31   $customer->assign_attributes( %params );
32   return $customer;
33 }
34
35 1;
36
37 __END__
38
39 =head1 NAME
40
41 SL::Dev::CustomerVendor - create customer and vendor objects for testing, with minimal defaults
42
43 =head1 FUNCTIONS
44
45 =head2 C<create_customer %PARAMS>
46
47 Creates a new customer.
48
49 Minimal usage, default values, without saving to database:
50
51   my $customer = SL::Dev::CustomerVendor::create_customer();
52
53 Complex usage, overwriting some defaults, and save to database:
54   SL::Dev::CustomerVendor::create_customer(name        => 'Test customer',
55                                            hourly_rate => 50,
56                                            taxzone_id  => 2,
57                                           )->save;
58
59
60 =head1 BUGS
61
62 Nothing here yet.
63
64 =head1 AUTHOR
65
66 G. Richardson E<lt>grichardson@kivitendo-premium.deE<gt>
67
68 =cut
69 1;