X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=t%2Fbackground_job%2Fcreate_periodic_invoices.t;h=1ce5fe60049d935a7546c72871fb7c012daba572;hb=1b032ef45d886922f1fe347ec234c9b0c8c50efd;hp=8d1c17076475e9c0653643900d30717f61573bf0;hpb=2097c966df5150a7b933772fc4c162e06f14bfb8;p=kivitendo-erp.git diff --git a/t/background_job/create_periodic_invoices.t b/t/background_job/create_periodic_invoices.t index 8d1c17076..1ce5fe600 100644 --- a/t/background_job/create_periodic_invoices.t +++ b/t/background_job/create_periodic_invoices.t @@ -14,7 +14,7 @@ sub today_local { package main; -use Test::More tests => 80; +use Test::More tests => 56; use lib 't'; use strict; @@ -22,6 +22,7 @@ use utf8; use Carp; use Support::TestSetup; +use SL::Dev::ALL qw(:ALL); use_ok 'SL::BackgroundJob::CreatePeriodicInvoices'; use_ok 'SL::DB::Chart'; @@ -34,57 +35,50 @@ use_ok 'SL::DB::TaxZone'; Support::TestSetup::login(); -our ($ar_chart, $buchungsgruppe, $currency_id, $customer, $employee, $order, $part, $tax_zone, $unit, @invoices); +our ($ar_chart, $customer, $order, $part, $unit, @invoices); sub init_common_state { - $ar_chart = SL::DB::Manager::Chart->find_by(accno => '1400') || croak "No AR chart"; - $buchungsgruppe = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 19%') || croak "No accounting group"; - $currency_id = SL::DB::Default->get->currency_id; - $employee = SL::DB::Manager::Employee->current || croak "No employee"; - $tax_zone = SL::DB::Manager::TaxZone->find_by( description => 'Inland') || croak "No taxzone"; - $unit = SL::DB::Manager::Unit->find_by(name => 'psch') || croak "No unit"; + $ar_chart = SL::DB::Manager::Chart->find_by(accno => '1400') || croak "No AR chart"; + $unit = SL::DB::Manager::Unit->find_by(name => 'psch') || croak "No unit"; } +sub clear_up { + "SL::DB::Manager::${_}"->delete_all(all => 1) for qw(InvoiceItem Invoice OrderItem Order Customer Part); +}; + sub create_invoices { my %params = @_; $params{$_} ||= {} for qw(customer part tax order orderitem periodic_invoices_config); # Clean up: remove invoices, orders, parts and customers - "SL::DB::Manager::${_}"->delete_all(all => 1) for qw(InvoiceItem Invoice OrderItem Order Customer Part); + clear_up(); - $customer = SL::DB::Customer->new( - name => 'Test Customer', - currency_id => $currency_id, - taxzone_id => $tax_zone->id, + $customer = new_customer( + name => 'Test Customer', %{ $params{customer} } )->save; - $part = SL::DB::Part->new( - partnumber => 'T4254', - description => 'Fourty-two fifty-four', - lastcost => 222.22, - sellprice => 333.33, - buchungsgruppen_id => $buchungsgruppe->id, - unit => $unit->name, + $part = new_part( + partnumber => 'T4254', + description => 'Fourty-two fifty-four', + lastcost => 222.22, + sellprice => 333.33, + unit => $unit->name, %{ $params{part} } )->save; - $part->load; - $order = SL::DB::Order->new( - customer_id => $customer->id, - currency_id => $currency_id, - taxzone_id => $tax_zone->id, + $order = create_sales_order( + save => 1, + customer => $customer, transaction_description => '<%period_start_date%>', orderitems => [ - { parts_id => $part->id, - description => $part->description, - lastcost => $part->lastcost, - sellprice => $part->sellprice, - qty => 1, - unit => $unit->name, + SL::Dev::Record::create_order_item( + part => $part, + qty => 1, + unit => $unit->name, %{ $params{orderitem} }, - }, + ), ], periodic_invoices_config => { active => 1, @@ -94,10 +88,6 @@ sub create_invoices { %{ $params{order} }, ); - $order->calculate_prices_and_taxes; - - ok($order->save(cascade => 1)); - SL::BackgroundJob::CreatePeriodicInvoices->new->run(SL::DB::BackgroundJob->new); @invoices = @{ SL::DB::Manager::Invoice->get_all(sort_by => [ qw(id) ]) }; @@ -237,4 +227,6 @@ are_invoices 'p=b ovp=5',[ '01.01.2009', 33.33 ], [ '01.07.2009', 33.33 ], create_invoices(periodic_invoices_config => { periodicity => 'y', order_value_periodicity => '5', start_date => DateTime->from_kivitendo('01.01.2009') }); are_invoices 'p=y ovp=5',[ '01.01.2009', 66.67 ], [ '01.01.2010', 66.67 ], [ '01.01.2011', 66.67 ], [ '01.01.2012', 66.67 ], [ '01.01.2013', 66.65 ], [ '01.01.2014', 66.67 ]; +clear_up(); + done_testing();