X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDev%2FCustomerVendor.pm;h=849bbda3bdf803b7b1feb618ada64ef0b01e20b6;hb=577042c61c5e1fffb8747079b4f9826e51532ee8;hp=4a59662b09406d5aa30166abb209a94c60a5f0e3;hpb=8d4130edfb562ddf4068ad88d37051396e8523c6;p=kivitendo-erp.git diff --git a/SL/Dev/CustomerVendor.pm b/SL/Dev/CustomerVendor.pm index 4a59662b0..849bbda3b 100644 --- a/SL/Dev/CustomerVendor.pm +++ b/SL/Dev/CustomerVendor.pm @@ -2,35 +2,62 @@ package SL::Dev::CustomerVendor; use strict; use base qw(Exporter); -our @EXPORT = qw(create_customer); +our @EXPORT_OK = qw(new_customer new_vendor); +our %EXPORT_TAGS = (ALL => \@EXPORT_OK); use SL::DB::TaxZone; use SL::DB::Currency; use SL::DB::Customer; -sub create_customer { +sub new_customer { my (%params) = @_; - my ($taxzone, $currency); + my $taxzone = _check_taxzone(delete $params{taxzone_id}); + my $currency = _check_currency(delete $params{currency_id}); - if ( my $taxzone_id = delete $params{taxzone_id} ) { + my $customer = SL::DB::Customer->new( name => delete $params{name} || 'Testkunde', + currency_id => $currency->id, + taxzone_id => $taxzone->id, + ); + $customer->assign_attributes( %params ); + return $customer; +} + +sub new_vendor { + my (%params) = @_; + + my $taxzone = _check_taxzone(delete $params{taxzone_id}); + my $currency = _check_currency(delete $params{currency_id}); + + my $vendor = SL::DB::Vendor->new( name => delete $params{name} || 'Testlieferant', + currency_id => $currency->id, + taxzone_id => $taxzone->id, + ); + $vendor->assign_attributes( %params ); + return $vendor; +} + +sub _check_taxzone { + my ($taxzone_id) = @_; + # check that taxzone_id exists or if no taxzone_id passed use 'Inland' + my $taxzone; + if ( $taxzone_id ) { $taxzone = SL::DB::Manager::TaxZone->find_by( id => $taxzone_id ) || die "Can't find taxzone_id"; } else { $taxzone = SL::DB::Manager::TaxZone->find_by( description => 'Inland') || die "No taxzone 'Inland'"; } + return $taxzone; +} - if ( my $currency_id = delete $params{currency_id} ) { +sub _check_currency { + my ($currency_id) = @_; + my $currency; + if ( $currency_id ) { $currency = SL::DB::Manager::Currency->find_by( id => $currency_id ) || die "Can't find currency_id"; } else { $currency = SL::DB::Manager::Currency->find_by( id => $::instance_conf->get_currency_id ); } - - my $customer = SL::DB::Customer->new( name => delete $params{name} || 'Testkunde', - currency_id => $currency->id, - taxzone_id => $taxzone->id, - ); - $customer->assign_attributes( %params ); - return $customer; + return $currency; } 1; @@ -43,20 +70,39 @@ SL::Dev::CustomerVendor - create customer and vendor objects for testing, with m =head1 FUNCTIONS -=head2 C +=head2 C Creates a new customer. Minimal usage, default values, without saving to database: - my $customer = SL::Dev::CustomerVendor::create_customer(); + my $customer = SL::Dev::CustomerVendor::new_customer(); Complex usage, overwriting some defaults, and save to database: - SL::Dev::CustomerVendor::create_customer(name => 'Test customer', + + SL::Dev::CustomerVendor::new_customer(name => 'Test customer', hourly_rate => 50, taxzone_id => 2, )->save; +If neither taxzone_id or currency_id (both are NOT NULL) are passed as params +then default values are used. + +=head2 C + +Creates a new vendor. + +Minimal usage, default values, without saving to database: + + my $vendor = SL::Dev::CustomerVendor::new_vendor(); + +Complex usage, overwriting some defaults, and save to database: + + SL::Dev::CustomerVendor::new_vendor(name => 'Test vendor', + taxzone_id => 2, + notes => "Order for 100$ for free delivery", + payment_id => 5, + )->save; =head1 BUGS @@ -67,4 +113,3 @@ Nothing here yet. G. Richardson Egrichardson@kivitendo-premium.deE =cut -1;