Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision f942d1f6

Von Martin Helmling vor mehr als 6 Jahren hinzugefügt

  • ID f942d1f60514c34a3d1f93fb9e17edfd12dadc94
  • Vorgänger 1ef37ef3
  • Nachfolger b0d3ad92

Bankimport: Fehler beim Verbuchen von Teilzahlungen: Rollback bei Fehler

Falls ein Fehler auftritt wird kein Rollback von der bereits gemachten Zahlung und dem neuen Recordlink gemacht,
lediglich die Banktransaktion wird nicht verändert

Erweiterung durch ein Test test_bt_error

-> liefert erstmal kein rollback fehler, test dennoch von odyn übernommen (jb)

Conflicts:
t/bank/bank_transactions.t

Unterschiede anzeigen:

SL/Controller/BankTransaction.pm
740 740

  
741 741
    # Rollback Fehler nicht weiterreichen
742 742
    # die if $error;
743
    # aber einen rollback von hand
744
    $::lxdebug->message(LXDebug->DEBUG2(),"finish worker with ". ($error ? $error->{result} : '-'));
745
    $data{bank_transaction}->db->dbh->rollback if $error && $error->{result} eq 'error';
743 746
  });
744 747

  
745 748
  return grep { $_ } ($error, @warnings);
t/bank/bank_transactions.t
27 27
use SL::Dev::ALL qw(:ALL);
28 28
use Data::Dumper;
29 29

  
30
my ($customer, $vendor, $currency_id, $unit, $tax, $tax7, $tax_9, $payment_terms, $bank_account);
30
my ($customer, $vendor, $currency_id, $unit, $tax, $tax0, $tax7, $tax_9, $payment_terms, $bank_account);
31 31
my ($transdate1, $transdate2, $currency);
32 32
my ($ar_chart,$bank,$ar_amount_chart, $ap_chart, $ap_amount_chart);
33 33
my ($ar_transaction, $ap_transaction);
......
49 49
  SL::DB::Manager::Currency->delete_all(where => [ name => 'CUR' ]);
50 50
};
51 51

  
52
my $bt_controller;
53

  
52 54
sub save_btcontroller_to_string {
53 55
  my $output;
54 56
  open(my $outputFH, '>', \$output) or die;
55 57
  my $oldFH = select $outputFH;
56 58

  
57
  my $bt_controller = SL::Controller::BankTransaction->new;
59
  $bt_controller = SL::Controller::BankTransaction->new;
58 60
  $bt_controller->action_save_invoices;
59 61

  
60 62
  select $oldFH;
......
72 74

  
73 75
test_overpayment_with_partialpayment();
74 76
test_overpayment();
77
reset_state();
75 78
test_skonto_exact();
76 79
test_two_invoices();
77 80
test_partial_payment();
......
84 87
test_neg_sales_invoice();
85 88
test_two_neg_ap_transaction();
86 89
test_one_inv_and_two_invoices_with_skonto_exact();
87
test_bt_rule1();
90
test_bt_error();
91

  
92
reset_state();
88 93
test_sepa_export();
89 94

  
95
reset_state();
96
test_bt_rule1();
90 97
reset_state();
91 98
test_two_banktransactions();
92 99
# remove all created data at end of test
......
108 115

  
109 116
  $tax             = SL::DB::Manager::Tax->find_by(taxkey => 3, rate => 0.19, %{ $params{tax} }) || croak "No tax";
110 117
  $tax7            = SL::DB::Manager::Tax->find_by(taxkey => 2, rate => 0.07)                    || croak "No tax for 7\%";
111
  $tax_9           = SL::DB::Manager::Tax->find_by(taxkey => 9, rate => 0.19, %{ $params{tax} }) || croak "No tax";
118
  $tax_9           = SL::DB::Manager::Tax->find_by(taxkey => 9, rate => 0.19, %{ $params{tax} }) || croak "No tax for 19\%";
119
  $tax0            = SL::DB::Manager::Tax->find_by(taxkey => 0, rate => 0.0)                     || croak "No tax for 0\%";
112 120

  
113 121
  $currency_id     = $::instance_conf->get_currency_id;
114 122

  
......
167 175
      amount       => $amount,
168 176
      netamount    => $netamount,
169 177
      transdate    => $transdate1,
170
      taxincluded  => 0,
178
      taxincluded  => $params{taxincluded } || 0,
171 179
      customer_id  => $customer->id,
172 180
      taxzone_id   => $customer->taxzone_id,
173 181
      currency_id  => $currency_id,
......
178 186
  $invoice->add_ar_amount_row(
179 187
    amount => $invoice->netamount,
180 188
    chart  => $ar_amount_chart,
181
    tax_id => $tax->id,
189
    tax_id => $params{tax_id} || $tax->id,
182 190
  );
183 191

  
184 192
  $invoice->create_ar_row(chart => $ar_chart);
......
218 226
  $invoice->add_ap_amount_row(
219 227
    amount     => $invoice->netamount,
220 228
    chart      => $ap_amount_chart,
221
    tax_id     => $tax_9->id,
229
    tax_id     => $params{tax_id} || $tax_9->id,
222 230
  );
223 231

  
224 232
  $invoice->create_ap_row(chart => $ap_chart);
......
289 297

  
290 298
};
291 299

  
300
sub test_bt_error {
301

  
302
  my $testname = 'test_free_skonto';
303

  
304
  $ar_transaction = test_ar_transaction(invnumber   => 'salesinv skonto',
305
                                        payment_id  => $payment_terms->id,
306
                                        taxincluded => 0,
307
                                        amount      => 168.58 / 1.19,
308
                                       );
309

  
310
  my $bt = create_bank_transaction(record        => $ar_transaction,
311
                                   bank_chart_id => $bank->id,
312
                                   amount        => 158.58,
313
                                  ) or die "Couldn't create bank_transaction";
314

  
315
  $::form->{invoice_ids} = {
316
    $bt->id => [ $ar_transaction->id ]
317
  };
318
  $::form->{invoice_skontos} = {
319
    $bt->id => [ 'with_free_skonto' ]
320
  };
321

  
322
  is($ar_transaction->paid   , '0' , "$testname: salesinv is not paid");
323

  
324
  # generate an error for testing rollback mechanism
325
  my $saved_skonto_sales_chart_id = $tax->skonto_sales_chart_id;
326
  $tax->skonto_sales_chart_id(undef);
327
  $tax->save;
328

  
329
  save_btcontroller_to_string();
330
  my @bt_errors = @{ $bt_controller->problems };
331
  is(substr($bt_errors[0]->{message},0,38), 'Kein Skontokonto für Steuerschlüssel 3', "$testname: Fehlermeldung ok");
332
  # set original value
333
  $tax->skonto_sales_chart_id($saved_skonto_sales_chart_id);
334
  $tax->save;
335

  
336
  $ar_transaction->load;
337
  $bt->load;
338
  is($ar_transaction->paid   , '0.00000' , "$testname: salesinv was not paid");
339
  is($bt->invoice_amount     , '0.00000' , "$testname: bt invoice amount was not assigned");
340

  
341
};
342

  
292 343
sub test_two_invoices {
293 344

  
294 345
  my $testname = 'test_two_invoices';

Auch abrufbar als: Unified diff