+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");
+
+};
+