X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=t%2Fbank%2Fbank_transactions.t;h=36fc04d95ce599e0f23a3fc6f8db36644f72cc71;hb=f72a365d3988ad682f853764fdbfb39aa92ac089;hp=1219ceec28ae0e045a83812309fd45dfbdfb4275;hpb=1b6d09ef1fad3bc7e7b1817b3ed9a55a9463afdd;p=kivitendo-erp.git diff --git a/t/bank/bank_transactions.t b/t/bank/bank_transactions.t index 1219ceec2..36fc04d95 100644 --- a/t/bank/bank_transactions.t +++ b/t/bank/bank_transactions.t @@ -1,4 +1,4 @@ -use Test::More tests => 176; +use Test::More tests => 210; use strict; @@ -27,7 +27,7 @@ use SL::Controller::BankTransaction; use SL::Dev::ALL qw(:ALL); use Data::Dumper; -my ($customer, $vendor, $currency_id, $unit, $tax, $tax7, $tax_9, $payment_terms, $bank_account); +my ($customer, $vendor, $currency_id, $unit, $tax, $tax0, $tax7, $tax_9, $payment_terms, $bank_account); my ($transdate1, $transdate2, $currency); my ($ar_chart,$bank,$ar_amount_chart, $ap_chart, $ap_amount_chart); my ($ar_transaction, $ap_transaction); @@ -49,12 +49,14 @@ sub clear_up { SL::DB::Manager::Currency->delete_all(where => [ name => 'CUR' ]); }; +my $bt_controller; + sub save_btcontroller_to_string { my $output; open(my $outputFH, '>', \$output) or die; my $oldFH = select $outputFH; - my $bt_controller = SL::Controller::BankTransaction->new; + $bt_controller = SL::Controller::BankTransaction->new; $bt_controller->action_save_invoices; select $oldFH; @@ -72,6 +74,7 @@ test1(); test_overpayment_with_partialpayment(); test_overpayment(); +reset_state(); test_skonto_exact(); test_two_invoices(); test_partial_payment(); @@ -84,9 +87,13 @@ test_ap_payment_part_transaction(); test_neg_sales_invoice(); test_two_neg_ap_transaction(); test_one_inv_and_two_invoices_with_skonto_exact(); -test_bt_rule1(); +test_bt_error(); + +reset_state(); test_sepa_export(); +reset_state(); +test_bt_rule1(); reset_state(); test_two_banktransactions(); # remove all created data at end of test @@ -108,7 +115,8 @@ sub reset_state { $tax = SL::DB::Manager::Tax->find_by(taxkey => 3, rate => 0.19, %{ $params{tax} }) || croak "No tax"; $tax7 = SL::DB::Manager::Tax->find_by(taxkey => 2, rate => 0.07) || croak "No tax for 7\%"; - $tax_9 = SL::DB::Manager::Tax->find_by(taxkey => 9, rate => 0.19, %{ $params{tax} }) || croak "No tax"; + $tax_9 = SL::DB::Manager::Tax->find_by(taxkey => 9, rate => 0.19, %{ $params{tax} }) || croak "No tax for 19\%"; + $tax0 = SL::DB::Manager::Tax->find_by(taxkey => 0, rate => 0.0) || croak "No tax for 0\%"; $currency_id = $::instance_conf->get_currency_id; @@ -167,7 +175,7 @@ sub test_ar_transaction { amount => $amount, netamount => $netamount, transdate => $transdate1, - taxincluded => 0, + taxincluded => $params{taxincluded } || 0, customer_id => $customer->id, taxzone_id => $customer->taxzone_id, currency_id => $currency_id, @@ -178,7 +186,7 @@ sub test_ar_transaction { $invoice->add_ar_amount_row( amount => $invoice->netamount, chart => $ar_amount_chart, - tax_id => $tax->id, + tax_id => $params{tax_id} || $tax->id, ); $invoice->create_ar_row(chart => $ar_chart); @@ -218,7 +226,7 @@ sub test_ap_transaction { $invoice->add_ap_amount_row( amount => $invoice->netamount, chart => $ap_amount_chart, - tax_id => $tax_9->id, + tax_id => $params{tax_id} || $tax_9->id, ); $invoice->create_ap_row(chart => $ap_chart); @@ -289,6 +297,50 @@ sub test_skonto_exact { }; +sub test_bt_error { + + my $testname = 'test_rollback_error'; + # without type with_free_skonto the helper function (Payment.pm) looks ugly but not + # breakable + + $ar_transaction = test_ar_transaction(invnumber => 'salesinv skonto', + payment_id => $payment_terms->id, + taxincluded => 0, + amount => 168.58 / 1.19, + ); + + my $bt = create_bank_transaction(record => $ar_transaction, + bank_chart_id => $bank->id, + amount => 160.15, + ) or die "Couldn't create bank_transaction"; + $::form->{invoice_ids} = { + $bt->id => [ $ar_transaction->id ] + }; + $::form->{invoice_skontos} = { + $bt->id => [ 'with_skonto_pt' ] + }; + + is($ar_transaction->paid , '0' , "$testname: salesinv is not paid"); + + # generate an error for testing rollback mechanism + my $saved_skonto_sales_chart_id = $tax->skonto_sales_chart_id; + $tax->skonto_sales_chart_id(undef); + $tax->save; + + save_btcontroller_to_string(); + my @bt_errors = @{ $bt_controller->problems }; + is(substr($bt_errors[0]->{message},0,38), 'Kein Skontokonto für Steuerschlüssel 3', "$testname: Fehlermeldung ok"); + # set original value + $tax->skonto_sales_chart_id($saved_skonto_sales_chart_id); + $tax->save; + + $ar_transaction->load; + $bt->load; + is($ar_transaction->paid , '0.00000' , "$testname: salesinv was not paid"); + is($bt->invoice_amount , '0.00000' , "$testname: bt invoice amount was not assigned"); + +}; + sub test_two_invoices { my $testname = 'test_two_invoices'; @@ -946,7 +998,7 @@ sub test_two_banktransactions { # Jetzt gibt es zwei Kontobewegungen mit gleichen Punkten für eine Rechnung. # hier darf es auch keine Proposals geben - my ( $bt_transactions, $proposals ) = $bt_controller->action_list; + ( $bt_transactions, $proposals ) = $bt_controller->action_list; is(scalar(@$bt_transactions) , 2 , "$testname: two bank_transaction"); is(scalar(@$proposals) , 0 , "$testname: no proposals"); @@ -956,7 +1008,7 @@ sub test_two_banktransactions { # hier darf es auch keine Proposals geben $bt3->update_attributes( purpose => "fuer Rechnung salesinv10000"); - my ( $bt_transactions, $proposals ) = $bt_controller->action_list; + ( $bt_transactions, $proposals ) = $bt_controller->action_list; is(scalar(@$bt_transactions) , 2 , "$testname: two bank_transaction"); is(scalar(@$proposals) , 1 , "$testname: one proposal");