Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision b8741ec3

Von Martin Helmling martin.helmling@octosoft.eu vor fast 8 Jahren hinzugefügt

  • ID b8741ec3f7f9723d1226fcdee60635ccb992f41e
  • Vorgänger 55e3ae55
  • Nachfolger 7b7a7bcc

Kontoauszug verbuchen: Lieferantengutschrift buchen

Nun wird eine negativen Kreditorenbuchung (Lieferantengutschrift) richtig verbucht.

t/bank/bank_transactions.t um einen Test erweitert
und Stdout des Controllers (HTML) in String umgelenkt.

Unterschiede anzeigen:

SL/Controller/BankTransaction.pm
599 599

  
600 600
    if (   $payment_sent
601 601
        && any {    ( $_->is_sales && ($_->amount > 0))
602
                 || (!$_->is_sales && ($_->amount < 0))
602
                 || (!$_->is_sales && ($_->amount < 0) && ($_->invoice_type eq 'purchase_invoice'))
603 603
               } @{ $data{invoices} }) {
604 604
      return {
605 605
        %data,
......
662 662
                              source       => $source,
663 663
                              memo         => $memo,
664 664
                              transdate    => $bank_transaction->transdate->to_kivitendo);
665
      } elsif ( $invoice->is_sales && $invoice->invoice_type eq 'credit_note' ) {
665
      } elsif (( $invoice->is_sales && $invoice->invoice_type eq 'credit_note' ) ||
666
               (!$invoice->is_sales && $invoice->invoice_type eq 'ap_transaction' )) {
666 667
        # no check for overpayment/multiple payments
667 668
        $invoice->pay_invoice(chart_id     => $bank_transaction->local_bank_account->chart_id,
668 669
                              trans_id     => $invoice->id,
t/bank/bank_transactions.t
1
use Test::More;
1
use Test::More tests => 74;
2 2

  
3 3
use strict;
4 4

  
......
46 46
  SL::DB::Manager::Currency->delete_all(where => [ name => 'CUR' ]);
47 47
};
48 48

  
49
sub save_btcontroller_to_string {
50
  my $output;
51
  open(my $outputFH, '>', \$output) or die;
52
  my $oldFH = select $outputFH;
53

  
54
  my $bt_controller = SL::Controller::BankTransaction->new;
55
  $bt_controller->action_save_invoices;
56

  
57
  select $oldFH;
58
  close $outputFH;
59
  return $output;
60
}
49 61

  
50 62
# starting test:
51 63
Support::TestSetup::login();
52 64

  
65
clear_up();
53 66
reset_state(); # initialise customers/vendors/bank/currency/...
54 67

  
55 68
test1();
......
59 72
test_two_invoices();
60 73
test_partial_payment();
61 74
test_credit_note();
75
test_neg_ap_transaction();
62 76

  
63 77
# remove all created data at end of test
64 78
clear_up();
......
215 229
          $bt->id => [ $ar_transaction->id ]
216 230
        };
217 231

  
218
  my $bt_controller = SL::Controller::BankTransaction->new;
219
  $bt_controller->action_save_invoices;
232
  save_btcontroller_to_string();
220 233

  
221 234
  $ar_transaction->load;
222 235
  $bt->load;
......
246 259
          $bt->id => [ 'with_skonto_pt' ]
247 260
        };
248 261

  
249
  my $bt_controller = SL::Controller::BankTransaction->new;
250
  $bt_controller->action_save_invoices;
262
  save_btcontroller_to_string();
251 263

  
252 264
  $ar_transaction->load;
253 265
  $bt->load;
......
277 289
          $bt->id => [ $ar_transaction_1->id, $ar_transaction_2->id ]
278 290
        };
279 291

  
280
  my $bt_controller = SL::Controller::BankTransaction->new;
281
  $bt_controller->action_save_invoices;
292
  save_btcontroller_to_string();
282 293

  
283 294
  $ar_transaction_1->load;
284 295
  $ar_transaction_2->load;
......
308 319
          $bt->id => [ $ar_transaction->id ]
309 320
        };
310 321

  
311
  my $bt_controller = SL::Controller::BankTransaction->new;
312
  $bt_controller->action_save_invoices;
322
  save_btcontroller_to_string();
313 323

  
314 324
  $ar_transaction->load;
315 325
  $bt->load;
......
343 353
  $::form->{invoice_ids} = {
344 354
          $bt_1->id => [ $ar_transaction->id ]
345 355
        };
346
  my $bt_controller_1 = SL::Controller::BankTransaction->new;
347
  $bt_controller_1->action_save_invoices;
356
  save_btcontroller_to_string();
348 357

  
349 358
  $::form->{invoice_ids} = {
350 359
          $bt_2->id => [ $ar_transaction->id ]
351 360
        };
352
  my $bt_controller_2 = SL::Controller::BankTransaction->new;
353
  $bt_controller_2->action_save_invoices;
361
  save_btcontroller_to_string();
354 362

  
355 363
  $ar_transaction->load;
356 364
  $bt_1->load;
......
378 386
          $bt->id => [ $ar_transaction->id ]
379 387
        };
380 388

  
381
  my $bt_controller = SL::Controller::BankTransaction->new;
382
  $bt_controller->action_save_invoices;
389
  save_btcontroller_to_string();
383 390

  
384 391
  $ar_transaction->load;
385 392
  $bt->load;
......
416 423
          $bt->id => [ $credit_note->id ]
417 424
  };
418 425

  
419
  my $bt_controller = SL::Controller::BankTransaction->new;
420
  $bt_controller->action_save_invoices;
426
  save_btcontroller_to_string();
421 427

  
422 428
  $credit_note->load;
423 429
  $bt->load;
......
426 432
  is($credit_note->paid     , '-844.90000', "$testname: paid ok");
427 433
}
428 434

  
435
sub test_neg_ap_transaction {
436
  my (%params) = @_;
437
  my $testname = 'test_neg_ap_transaction';
438
  my $netamount = -20;
439
  my $amount    = $::form->round_amount($netamount * 1.19,2);
440
  my $invoice   = SL::DB::PurchaseInvoice->new(
441
      invoice      => 0,
442
      invnumber    => $params{invnumber} || 'test_neg_ap_transaction',
443
      amount       => $amount,
444
      netamount    => $netamount,
445
      transdate    => $transdate1,
446
      taxincluded  => 0,
447
      vendor_id    => $vendor->id,
448
      taxzone_id   => $vendor->taxzone_id,
449
      currency_id  => $currency_id,
450
      transactions => [],
451
      notes        => 'test_neg_ap_transaction',
452
  );
453
  $invoice->add_ap_amount_row(
454
    amount     => $invoice->netamount,
455
    chart      => $ap_amount_chart,
456
    tax_id     => $tax_9->id,
457
  );
458

  
459
  $invoice->create_ap_row(chart => $ap_chart);
460
  $invoice->save;
461

  
462
  is($invoice->netamount   , -20          , "$testname: netamount ok");
463
  is($invoice->amount      , -23.8        , "$testname: amount ok");
464

  
465
  my $bt            = SL::Dev::Payment::create_bank_transaction(record        => $invoice,
466
                                                                amount        => $invoice->amount,
467
                                                                bank_chart_id => $bank->id,
468
                                                                transdate     => DateTime->today->add(days => 10),
469
                                                               );
470
  my ($agreement, $rule_matches) = $bt->get_agreement_with_invoice($invoice);
471
  is($agreement, 15, "points for negative ap transaction ok");
472

  
473
  $::form->{invoice_ids} = {
474
          $bt->id => [ $invoice->id ]
475
  };
476

  
477
  save_btcontroller_to_string();
478

  
479
  $invoice->load;
480

  
481
  is($invoice->amount   , '-23.80000', "$testname: amount ok");
482
  is($invoice->netamount, '-20.00000', "$testname: netamount ok");
483
  is($invoice->paid     , '-23.80000', "$testname: paid ok");
484

  
485
  return $invoice;
486
};
487

  
488

  
429 489
1;

Auch abrufbar als: Unified diff