Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 1b6d09ef

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

  • ID 1b6d09ef1fad3bc7e7b1817b3ed9a55a9463afdd
  • Vorgänger b161d667
  • Nachfolger 3fe6ec98

Bankimport: Tests erweitert

fix Issue #201

Conflicts:
t/bank/bank_transactions.t

Unterschiede anzeigen:

t/bank/bank_transactions.t
87 87
test_bt_rule1();
88 88
test_sepa_export();
89 89

  
90
reset_state();
91
test_two_banktransactions();
90 92
# remove all created data at end of test
91 93
clear_up();
92 94

  
......
157 159

  
158 160
sub test_ar_transaction {
159 161
  my (%params) = @_;
160
  my $netamount = 100;
161
  my $amount    = $params{amount} || $::form->round_amount(100 * 1.19,2);
162
  my $netamount = $params{amount} || 100;
163
  my $amount    = $::form->round_amount($netamount * 1.19,2);
162 164
  my $invoice   = SL::DB::Invoice->new(
163 165
      invoice      => 0,
164 166
      invnumber    => $params{invnumber} || undef, # let it use its own invnumber
......
183 185
  $invoice->save;
184 186

  
185 187
  is($invoice->currency_id , $currency_id , 'currency_id has been saved');
186
  is($invoice->netamount   , 100          , 'ar amount has been converted');
187
  is($invoice->amount      , 119          , 'ar amount has been converted');
188
  is($invoice->netamount   , $netamount   , 'ar amount has been converted');
189
  is($invoice->amount      , $amount      , 'ar amount has been converted');
188 190
  is($invoice->taxincluded , 0            , 'ar transaction doesn\'t have taxincluded');
189 191

  
190
  is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ar_amount_chart->id , trans_id => $invoice->id)->amount , '100.00000'  , $ar_amount_chart->accno . ': has been converted for currency');
191
  is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ar_chart->id        , trans_id => $invoice->id)->amount , '-119.00000' , $ar_chart->accno . ': has been converted for currency');
192

  
192
  if ( $netamount == 100 ) {
193
    is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ar_amount_chart->id , trans_id => $invoice->id)->amount , '100.00000'  , $ar_amount_chart->accno . ': has been converted for currency');
194
    is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ar_chart->id        , trans_id => $invoice->id)->amount , '-119.00000' , $ar_chart->accno . ': has been converted for currency');
195
  }
193 196
  return $invoice;
194 197
};
195 198

  
......
312 315
  $ar_transaction_2->load;
313 316
  $bt->load;
314 317

  
315
  is($ar_transaction_1->paid   , '119.00000' , "$testname: salesinv_1 was paid");
318
  is($ar_transaction_1->paid   , '119.00000' , "$testname: salesinv_1 wcsv_import_reportsas paid");
316 319
  is($ar_transaction_1->closed , 1           , "$testname: salesinv_1 is closed");
317 320
  is($ar_transaction_2->paid   , '119.00000' , "$testname: salesinv_2 was paid");
318 321
  is($ar_transaction_2->closed , 1           , "$testname: salesinv_2 is closed");
......
812 815
  my $bt_controller = SL::Controller::BankTransaction->new;
813 816
  $::form->{dont_render_for_test} = 1;
814 817
  $::form->{filter}{bank_account} = $bank_account->id;
815
  my $bt_transactions = $bt_controller->action_list;
818
  my ( $bt_transactions, $proposals ) = $bt_controller->action_list;
816 819

  
817 820
  is(scalar(@$bt_transactions)         , 1  , "$testname: one bank_transaction");
818 821
  is($bt_transactions->[0]->{agreement}, 20 , "$testname: agreement == 20");
819 822
  my $match = join ( ' ',@{$bt_transactions->[0]->{rule_matches}});
820 823
  #print "rule_matches='".$match."'\n";
821 824
  is($match,
822
     "remote_account_number(3) exact_amount(4) own_invnumber_in_purpose(5) depositor_matches(2) remote_name(2) payment_within_30_days(1) datebonus0(3) ",
825
     "remote_account_number(3) exact_amount(4) own_invoice_in_purpose(5) depositor_matches(2) remote_name(2) payment_within_30_days(1) datebonus0(3) ",
823 826
     "$testname: rule_matches ok");
824 827
  $bt->invoice_amount($bt->amount);
825 828
  $bt->save;
......
865 868
  my $bt_controller = SL::Controller::BankTransaction->new;
866 869
  $::form->{dont_render_for_test} = 1;
867 870
  $::form->{filter}{bank_account} = $bank_account->id;
868
  my $bt_transactions = $bt_controller->action_list;
871
  my ( $bt_transactions, $proposals ) = $bt_controller->action_list;
869 872

  
870 873
  is(scalar(@$bt_transactions)         , 1  , "$testname: one bank_transaction");
871 874
  is($bt_transactions->[0]->{agreement}, 25 , "$testname: agreement == 25");
872 875
  my $match = join ( ' ',@{$bt_transactions->[0]->{rule_matches}});
873 876
  is($match,
874
     "remote_account_number(3) exact_amount(4) own_invnumber_in_purpose(5) depositor_matches(2) remote_name(2) payment_within_30_days(1) datebonus0(3) sepa_export_item(5) ",
877
     "remote_account_number(3) exact_amount(4) own_invoice_in_purpose(5) depositor_matches(2) remote_name(2) payment_within_30_days(1) datebonus0(3) sepa_export_item(5) ",
875 878
     "$testname: rule_matches ok");
876 879
};
877 880

  
881
sub test_two_banktransactions {
882

  
883
  my $testname = 'two_banktransactions';
884

  
885
  my $ar_transaction_1 = test_ar_transaction(invnumber => 'salesinv10000' , amount => 2912.00 );
886
  my $bt1 = create_bank_transaction(record        => $ar_transaction_1,
887
                                    amount        => $ar_transaction_1->amount,
888
                                    purpose       => "Rechnung10000 beinahe",
889
                                    bank_chart_id => $bank->id,
890
                                  ) or die "Couldn't create bank_transaction";
891

  
892
  my $bt2 = create_bank_transaction(record        => $ar_transaction_1,
893
                                    amount        => $ar_transaction_1->amount + 0.01,
894
                                    purpose       => "sicher salesinv20000 vielleicht",
895
                                    bank_chart_id => $bank->id,
896
                                  ) or die "Couldn't create bank_transaction";
897

  
898
  my ($agreement1, $rule_matches1) = $bt1->get_agreement_with_invoice($ar_transaction_1);
899
  is($agreement1, 19, "bt1 19 points for ar_transaction_1 in $testname ok");
900
  #print "rule_matches1=".$rule_matches1."\n";
901
  is($rule_matches1,
902
     "remote_account_number(3) exact_amount(4) own_invnumber_in_purpose(4) depositor_matches(2) remote_name(2) payment_within_30_days(1) datebonus0(3) ",
903
     "$testname: rule_matches ok");
904
  my ($agreement2, $rule_matches2) = $bt2->get_agreement_with_invoice($ar_transaction_1);
905
  is($agreement2, 11, "bt2 11 points for ar_transaction_1 in $testname ok");
906
  is($rule_matches2,
907
     "remote_account_number(3) depositor_matches(2) remote_name(2) payment_within_30_days(1) datebonus0(3) ",
908
     "$testname: rule_matches ok");
909

  
910
  my $ar_transaction_2 = test_ar_transaction(invnumber => 'salesinv20000' , amount => 2912.01 );
911
  my $ar_transaction_3 = test_ar_transaction(invnumber => 'zweitemit10000', amount => 2912.00 );
912
     ($agreement1, $rule_matches1) = $bt1->get_agreement_with_invoice($ar_transaction_2);
913

  
914
  is($agreement1, 11, "bt1 11 points for ar_transaction_2 in $testname ok");
915

  
916
     ($agreement2, $rule_matches2) = $bt2->get_agreement_with_invoice($ar_transaction_2);
917
  is($agreement2, 20, "bt2 20 points for ar_transaction_2 in $testname ok");
918

  
919
     ($agreement2, $rule_matches2) = $bt2->get_agreement_with_invoice($ar_transaction_1);
920
  is($agreement2, 11, "bt2 11 points for ar_transaction_1 in $testname ok");
921

  
922
  my $bt3 = create_bank_transaction(record        => $ar_transaction_3,
923
                                    amount        => $ar_transaction_3->amount,
924
                                    purpose       => "sicher Rechnung10000 vielleicht",
925
                                    bank_chart_id => $bank->id,
926
                                  ) or die "Couldn't create bank_transaction";
927

  
928
  my ($agreement3, $rule_matches3) = $bt3->get_agreement_with_invoice($ar_transaction_3);
929
  is($agreement3, 19, "bt3 19 points for ar_transaction_3 in $testname ok");
930

  
931
  $bt2->delete;
932
  $ar_transaction_2->delete;
933

  
934
  #nun sollten zwei gleichwertige Rechnungen $ar_transaction_1 und $ar_transaction_3 für $bt1 gefunden werden
935
  #aber es darf keine Proposals geben mit mehreren Rechnungen
936
  my $bt_controller = SL::Controller::BankTransaction->new;
937
  $::form->{dont_render_for_test} = 1;
938
  $::form->{filter}{bank_account} = $bank_account->id;
939
  my ( $bt_transactions, $proposals ) = $bt_controller->action_list;
940

  
941
  is(scalar(@$bt_transactions)   , 2  , "$testname: two bank_transaction");
942
  is(scalar(@$proposals)         , 0  , "$testname: no proposals");
943

  
944
  $ar_transaction_3->delete;
945

  
946
  # Jetzt gibt es zwei Kontobewegungen mit gleichen Punkten für eine Rechnung.
947
  # hier darf es auch keine Proposals geben
948

  
949
  my ( $bt_transactions, $proposals ) = $bt_controller->action_list;
950

  
951
  is(scalar(@$bt_transactions)   , 2  , "$testname: two bank_transaction");
952
  is(scalar(@$proposals)         , 0  , "$testname: no proposals");
953

  
954
  # Jetzt gibt es zwei Kontobewegungen für eine Rechnung.
955
  # eine Bewegung bekommt mehr Punkte
956
  # hier darf es auch keine Proposals geben
957
  $bt3->update_attributes( purpose => "fuer Rechnung salesinv10000");
958

  
959
  my ( $bt_transactions, $proposals ) = $bt_controller->action_list;
960

  
961
  is(scalar(@$bt_transactions)   , 2  , "$testname: two bank_transaction");
962
  is(scalar(@$proposals)         , 1  , "$testname: one proposal");
963

  
964
};
965

  
878 966

  
879 967
1;

Auch abrufbar als: Unified diff