Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision b11c7ad5

Von Jan Büren vor etwa 5 Jahren hinzugefügt

  • ID b11c7ad55b4a6445860e4494e550cb3ff8d09eac
  • Vorgänger cecc0509
  • Nachfolger 2eaabab4

BankTransaction: want a whole lotta test

neuer Test full_workflow in bank_transactions
1.
Verbucht drei Verkaufsrechnungen nacheinander, davon
eine mit Zahlungsbedingung Skonto nach ZB. Zusätzlich
zu den Nebenbücher werden acc_trans Einträge kontrolliert,
sowie der gesetzte RecordLink.
2.
Da die Bankbewegung komplett aufgeht, wird diese abgeglichen
und die Zustände danach kontrolliert.
3.
Leider war die Verbuchung komplett Murks, weswegen die
Ursprungszustand vor 1. wiederhergestellt (neues Funktion
Kontoauszug-Verbuchung rückgängig machen)

Bonus-Level:
Damit andere Anwendungen / Schnittstellen, DB-Admins nicht
auf die Idee kommen an der Hilfstabelle bank_transaction_acc_trans
zu schrauben, entsprechend einen weiteren SelfTest geschrieben

Unterschiede anzeigen:

t/bank/bank_transactions.t
1
use Test::More tests => 211;
1
use Test::More tests => 282;
2 2

  
3 3
use strict;
4 4

  
......
25 25
use SL::DB::PurchaseInvoice;
26 26
use SL::DB::BankTransaction;
27 27
use SL::Controller::BankTransaction;
28
use SL::Controller::Reconciliation;
28 29
use SL::Dev::ALL qw(:ALL);
29 30
use Data::Dumper;
30 31

  
......
90 91
test_two_neg_ap_transaction();
91 92
test_one_inv_and_two_invoices_with_skonto_exact();
92 93
test_bt_error();
94
test_full_workflow_ar_multiple_inv_skonto_reconciliate_and_undo();
93 95

  
94 96
reset_state();
95 97
test_sepa_export();
......
518 520

  
519 521
};
520 522

  
523
sub test_full_workflow_ar_multiple_inv_skonto_reconciliate_and_undo {
524

  
525
  my $testname = 'test_partial_payment';
526

  
527
  $ar_transaction = test_ar_transaction(invnumber => 'salesinv partial payment two');
528
  my $ar_transaction_2 = test_ar_transaction(invnumber => 'salesinv 2 22d2', amount => 22);
529

  
530
  # amount 299.29 > 119
531
  my $bt = create_bank_transaction(record        => $ar_transaction,
532
                                   bank_chart_id => $bank->id,
533
                                   amount        => 299.29
534
                                  ) or die "Couldn't create bank_transaction";
535

  
536
  $::form->{invoice_ids} = {
537
    $bt->id => [ $ar_transaction->id ]
538
  };
539

  
540
  save_btcontroller_to_string();
541

  
542
  $ar_transaction->load;
543
  $bt->load;
544

  
545
  is($ar_transaction->paid , '119.00000' , "$testname: 'salesinv partial payment' was fully paid");
546
  is($bt->invoice_amount   , '119.00000' , "$testname: bt invoice amount was assigned partially paid amount");
547
  is($bt->amount           , '299.29000' , "$testname: bt amount is stil there");
548
  # next invoice, same bank transaction
549
  $::form->{invoice_ids} = {
550
    $bt->id => [ $ar_transaction_2->id ]
551
  };
552

  
553
  save_btcontroller_to_string();
554

  
555
  $ar_transaction_2->load;
556
  $bt->load;
557
  is($ar_transaction_2->paid , '26.18000' , "$testname: 'salesinv partial payment' was fully paid");
558
  is($bt->invoice_amount   , '145.18000' , "$testname: bt invoice amount was assigned partially paid amount");
559
  is($bt->amount           , '299.29000' , "$testname: bt amount is stil there");
560
  is(scalar @{ SL::DB::Manager::BankTransactionAccTrans->get_all(where => [bank_transaction_id => $bt->id ] )}, 4, "$testname 4 acc_trans entries created");
561

  
562
  #  now check all 4 entries done so far and save paid acc_trans_ids for later use with reconcile
563
  foreach my $acc_trans_id_entry (@{ SL::DB::Manager::BankTransactionAccTrans->get_all(where => [bank_transaction_id => $bt->id ] )}) {
564
    isnt($acc_trans_id_entry->ar_id, undef, "$testname: bt linked with acc_trans and trans_id set");
565
    my $rl = SL::DB::Manager::RecordLink->get_all(where => [ from_id => $bt->id, from_table => 'bank_transactions', to_id => $acc_trans_id_entry->ar_id ]);
566
    is (ref $rl->[0], 'SL::DB::RecordLink', "$testname record link created");
567
    my $acc_trans = SL::DB::Manager::AccTransaction->get_all(where => [acc_trans_id => $acc_trans_id_entry->acc_trans_id]);
568
    foreach my $entry (@{ $acc_trans }) {
569
      like(abs($entry->amount), qr/(119|26.18)/, "$testname: abs amount correct");
570
      like($entry->chart_link, qr/(paid|AR)/, "$testname chart_link correct");
571
      push @{ $::form->{bb_ids} }, $entry->acc_trans_id if $entry->chart_link =~ m/paid/;
572
    }
573
  }
574
  # great we need one last booking to clear the whole bank transaction - we include skonto
575
  my $ar_transaction_skonto = test_ar_transaction(invnumber  => 'salesinv skonto last case',
576
                                                  payment_id => $payment_terms->id,
577
                                                  amount     => 136.32,
578
                                                 );
579

  
580
  $::form->{invoice_ids} = {
581
    $bt->id => [ $ar_transaction_skonto->id ]
582
  };
583
  $::form->{invoice_skontos} = {
584
    $bt->id => [ 'with_skonto_pt' ]
585
  };
586

  
587
  save_btcontroller_to_string();
588

  
589
  $ar_transaction_skonto->load;
590
  $bt->load;
591
  is($ar_transaction_skonto->paid , '162.22000' , "$testname: 'salesinv skonto fully paid");
592
  is($bt->invoice_amount   , '299.29000' , "$testname: bt invoice amount was assigned partially paid amount");
593
  is($bt->amount           , '299.29000' , "$testname: bt amount is stil there");
594
  is(scalar @{ SL::DB::Manager::BankTransactionAccTrans->get_all(where => [bank_transaction_id => $bt->id ] )},
595
       7, "$testname 7 acc_trans entries created");
596

  
597
  # same loop as above, but only for the 3rd ar_id
598
  foreach my $acc_trans_id_entry (@{ SL::DB::Manager::BankTransactionAccTrans->get_all(where => [ar_id => $ar_transaction_skonto->id ] )}) {
599
    isnt($acc_trans_id_entry->ar_id, '', "$testname: bt linked with acc_trans and trans_id set");
600
    my $rl = SL::DB::Manager::RecordLink->get_all(where => [ from_id => $bt->id, from_table => 'bank_transactions', to_id => $acc_trans_id_entry->ar_id ]);
601
    is (ref $rl->[0], 'SL::DB::RecordLink', "$testname record link created");
602
    my $acc_trans = SL::DB::Manager::AccTransaction->get_all(where => [acc_trans_id => $acc_trans_id_entry->acc_trans_id]);
603
    foreach my $entry (@{ $acc_trans }) {
604
      like($entry->chart_link, qr/(paid|AR)/, "$testname chart_link correct");
605
      is ($entry->amount, '162.22000', "$testname full amont") if $entry->chart_link eq 'AR'; # full amount
606
      like(abs($entry->amount), qr/(154.11|8.11)/, "$testname: abs amount correct") if $entry->chart_link =~ m/paid/;
607
      push @{ $::form->{bb_ids} }, $entry->acc_trans_id if ($entry->chart_link =~ m/paid/ && $entry->amount == -154.11);
608
    }
609
  }
610
  # done, now reconciliate all bookings
611
  $::form->{bt_ids} = [ $bt->id ];
612
  my $rec_controller = SL::Controller::Reconciliation->new;
613
  my @errors = $rec_controller->_get_elements_and_validate;
614

  
615
  is (scalar @errors, 0, "$testname unsuccesfull reconciliation with error: " . Dumper(@errors));
616
  $rec_controller->_reconcile;
617
  $bt->load;
618

  
619
  # and check the cleared state of bt and the acc_transactions
620
  is($bt->cleared, '1' , "$testname: bt cleared");
621
  foreach (@{ $::form->{bb_ids} }) {
622
    my $acc_trans = SL::DB::Manager::AccTransaction->find_by(acc_trans_id => $_);
623
    is($acc_trans->cleared, '1' , "$testname: acc_trans entry cleared");
624
  }
625
  # now, this was a really bad idea and in general a major mistake. better undo and redo the whole bank transactions
626

  
627
  $::form->{ids} = [ $bt->id ];
628
  $bt_controller = SL::Controller::BankTransaction->new;
629
  $bt_controller->action_unlink_bank_transaction('testcase' => 1);
630

  
631
  $bt->load;
632

  
633
  # and check the cleared state of bt and the acc_transactions
634
  is($bt->cleared, '0' , "$testname: bt undo cleared");
635
  is($bt->invoice_amount, '0.00000' , "$testname: bt undo invoice amount");
636
  foreach (@{ $::form->{bb_ids} }) {
637
    my $acc_trans = SL::DB::Manager::AccTransaction->find_by(acc_trans_id => $_);
638
    is($acc_trans, undef , "$testname: cleared acc_trans entry completely removed");
639
  }
640
  # this was for data integrity for reconcile, now all the other options
641
  is(scalar @{ SL::DB::Manager::BankTransactionAccTrans->get_all(where => [bank_transaction_id => $bt->id ] )},
642
       0, "$testname 7 acc_trans entries deleted");
643
  my $rl = SL::DB::Manager::RecordLink->get_all(where => [ from_id => $bt->id, from_table => 'bank_transactions' ]);
644
  is (ref $rl->[0], '', "$testname record link removed");
645
  # double safety and check ar.paid
646
  # load all three invoices and check for paid-link via acc_trans and paid in general
647

  
648
  $ar_transaction->load;
649
  $ar_transaction_2->load;
650
  $ar_transaction_skonto->load;
651

  
652
  is(scalar @{ SL::DB::Manager::AccTransaction->get_all(
653
     where => [ trans_id => $ar_transaction->id, chart_link => { like => '%paid%' } ])},
654
     0, "$testname no more paid entries in acc_trans for ar_transaction");
655
  is(scalar @{ SL::DB::Manager::AccTransaction->get_all(
656
     where => [ trans_id => $ar_transaction_2->id, chart_link => { like => '%paid%' } ])},
657
     0, "$testname no more paid entries in acc_trans for ar_transaction_2");
658
  is(scalar @{ SL::DB::Manager::AccTransaction->get_all(
659
     where => [ trans_id => $ar_transaction_skonto->id, chart_link => { like => '%paid%' } ])},
660
     0, "$testname no more paid entries in acc_trans for ar_transaction_skonto");
661

  
662
  is($ar_transaction->paid , '0.00000' , "$testname: 'salesinv fully unpaid");
663
  is($ar_transaction_2->paid , '0.00000' , "$testname: 'salesinv 2 fully unpaid");
664
  is($ar_transaction_skonto->paid , '0.00000' , "$testname: 'salesinv skonto fully unpaid");
665

  
666
  # whew. w(h)a(n)t a whole lotta test
667
}
668

  
669

  
521 670
sub test_credit_note {
522 671

  
523 672
  my $testname = 'test_credit_note';
......
743 892

  
744 893
  is($invoice->amount   , '136.85000', "$testname: amount ok");
745 894
  is($invoice->netamount, '115.00000', "$testname: netamount ok");
746
  is($bt->amount, '-136.85000', "$testname: bt amount ok");
895
  is($bt->amount,         '-136.85000', "$testname: bt amount ok");
747 896
  is($invoice->paid     , '136.85000', "$testname: paid ok");
748 897
  is($bt->invoice_amount, '-136.85000', "$testname: bt invoice amount for ap was assigned");
749 898

  

Auch abrufbar als: Unified diff