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