X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDev%2FCustomerVendor.pm;h=fc41d85ef86b92351aa9ad296e1b86d446aa1247;hb=a34bdbf789c735db56009ce6c61566ac30792abe;hp=4a59662b09406d5aa30166abb209a94c60a5f0e3;hpb=8d4130edfb562ddf4068ad88d37051396e8523c6;p=kivitendo-erp.git diff --git a/SL/Dev/CustomerVendor.pm b/SL/Dev/CustomerVendor.pm index 4a59662b0..fc41d85ef 100644 --- a/SL/Dev/CustomerVendor.pm +++ b/SL/Dev/CustomerVendor.pm @@ -11,26 +11,52 @@ use SL::DB::Customer; sub create_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 create_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; @@ -52,11 +78,29 @@ Minimal usage, default values, without saving to database: my $customer = SL::Dev::CustomerVendor::create_customer(); Complex usage, overwriting some defaults, and save to database: + SL::Dev::CustomerVendor::create_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::create_vendor(); + +Complex usage, overwriting some defaults, and save to database: + + SL::Dev::CustomerVendor::create_vendor(name => 'Test vendor', + taxzone_id => 2, + notes => "Order for 100$ for free delivery", + )->save; =head1 BUGS @@ -67,4 +111,3 @@ Nothing here yet. G. Richardson Egrichardson@kivitendo-premium.deE =cut -1;