Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision f12c42cf

Von Kivitendo Admin vor etwa 8 Jahren hinzugefügt

  • ID f12c42cfc9a7ac4ac6d1402eaec1658e186b18e0
  • Vorgänger 96593e93
  • Nachfolger 6e0fe1dc

payment.t Test nutzt SL::Dev::* zur Datengenerierung

Unterschiede anzeigen:

t/db_helper/payment.t
10 10
use Test::Exception;
11 11
use List::Util qw(sum);
12 12

  
13
use SL::Dev::Record;
14
use SL::Dev::CustomerVendor;
15
use SL::Dev::Part;
13 16
use SL::DB::Buchungsgruppe;
14 17
use SL::DB::Currency;
15 18
use SL::DB::Exchangerate;
......
106 109
                                             currency_id => $currency->id,
107 110
                                            )->save;
108 111

  
109
  $customer     = SL::DB::Customer->new(
112
  $customer     = SL::Dev::CustomerVendor::create_customer(
110 113
    name        => 'Test Customer',
111 114
    currency_id => $currency_id,
112 115
    taxzone_id  => $taxzone->id,
113
    %{ $params{customer} }
114 116
  )->save;
115 117

  
116 118
  $bank_account     =  SL::DB::BankAccount->new(
......
132 134
    auto_calculation => 1,
133 135
  )->save;
134 136

  
135
  $vendor       = SL::DB::Vendor->new(
137
  $vendor       = SL::Dev::CustomerVendor::create_vendor(
136 138
    name        => 'Test Vendor',
137 139
    currency_id => $currency_id,
138 140
    taxzone_id  => $taxzone->id,
139 141
    payment_id  => $payment_terms->id,
140
    %{ $params{vendor} }
141 142
  )->save;
142 143

  
143 144

  
144 145
  @parts = ();
145
  push @parts, SL::DB::Part->new(
146
  push @parts, SL::Dev::Part::create_part(
146 147
    partnumber         => 'T4254',
147 148
    description        => 'Fourty-two fifty-four',
148 149
    lastcost           => 1.93,
149 150
    sellprice          => 2.34,
150
    part_type          => 'part',
151 151
    buchungsgruppen_id => $buchungsgruppe->id,
152 152
    unit               => $unit->name,
153 153
    %{ $params{part1} }
154 154
  )->save;
155 155

  
156
  push @parts, SL::DB::Part->new(
156
  push @parts, SL::Dev::Part::create_part(
157 157
    partnumber         => 'T0815',
158 158
    description        => 'Zero EIGHT fifteeN @ 7%',
159 159
    lastcost           => 5.473,
160 160
    sellprice          => 9.714,
161
    part_type          => 'part',
162 161
    buchungsgruppen_id => $buchungsgruppe7->id,
163 162
    unit               => $unit->name,
164 163
    %{ $params{part2} }
165 164
  )->save;
166
  push @parts, SL::DB::Part->new(
165
  push @parts, SL::Dev::Part::create_part(
167 166
    partnumber         => '19%',
168 167
    description        => 'Testware 19%',
169 168
    lastcost           => 0,
170 169
    sellprice          => 50,
171
    part_type          => 'part',
172 170
    buchungsgruppen_id => $buchungsgruppe->id,
173 171
    unit               => $unit->name,
174 172
    %{ $params{part3} }
175 173
  )->save;
176
  push @parts, SL::DB::Part->new(
174
  push @parts, SL::Dev::Part::create_part(
177 175
    partnumber         => '7%',
178 176
    description        => 'Testware 7%',
179 177
    lastcost           => 0,
180 178
    sellprice          => 50,
181
    part_type          => 'part',
182 179
    buchungsgruppen_id => $buchungsgruppe7->id,
183 180
    unit               => $unit->name,
184 181
    %{ $params{part4} }
......
193 190
  $reset_state_counter++;
194 191
}
195 192

  
196
sub new_invoice {
197
  my %params  = @_;
198

  
199
  return SL::DB::Invoice->new(
200
    customer_id => $customer->id,
201
    currency_id => $currency_id,
202
    employee_id => $employee->id,
203
    salesman_id => $employee->id,
204
    gldate      => $transdate1,
205
    taxzone_id  => $taxzone->id,
206
    transdate   => $transdate1,
207
    invoice     => 1,
208
    type        => 'invoice',
209
    %params,
210
  );
211

  
212
}
213

  
214 193
sub new_purchase_invoice {
215 194
  # my %params  = @_;
216 195
  # manually create a Kreditorenbuchung from scratch, ap + acc_trans bookings, as no helper exists yet, like $invoice->post.
......
295 274
  return $purchase_invoice;
296 275
}
297 276

  
298
sub new_item {
299
  my (%params) = @_;
300

  
301
  my $part = delete($params{part}) || $parts[0];
302

  
303
  return SL::DB::InvoiceItem->new(
304
    parts_id    => $part->id,
305
    lastcost    => $part->lastcost,
306
    sellprice   => $part->sellprice,
307
    description => $part->description,
308
    unit        => $part->unit,
309
    %params,
310
  );
311
}
312

  
313 277
sub number_of_payments {
314 278
  my $invoice = shift;
315 279

  
......
338 302
sub test_default_invoice_one_item_19_without_skonto() {
339 303
  reset_state() if $ALWAYS_RESET;
340 304

  
341
  my $item    = new_item(qty => 2.5);
342
  my $invoice = new_invoice(
305
  my $item    = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5);
306
  my $invoice = SL::Dev::Record::create_sales_invoice(
343 307
    taxincluded  => 0,
344 308
    invoiceitems => [ $item ],
345 309
    payment_id   => $payment_terms->id,
346 310
  );
347
  $invoice->post;
348 311

  
349 312
  my $purchase_invoice = new_purchase_invoice();
350 313

  
351

  
352 314
  # default values
353 315
  my %params = ( chart_id => $bank_account->chart_id,
354 316
                 transdate => DateTime->today_local->to_kivitendo
......
376 338
sub test_default_invoice_one_item_19_without_skonto_overpaid() {
377 339
  reset_state() if $ALWAYS_RESET;
378 340

  
379
  my $item    = new_item(qty => 2.5);
380
  my $invoice = new_invoice(
341
  my $item    = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5);
342
  my $invoice = SL::Dev::Record::create_sales_invoice(
381 343
    taxincluded  => 0,
382 344
    invoiceitems => [ $item ],
383 345
    payment_id   => $payment_terms->id,
384 346
  );
385
  $invoice->post;
386 347

  
387 348
  my $purchase_invoice = new_purchase_invoice();
388 349

  
......
418 379
sub test_default_invoice_two_items_19_7_tax_with_skonto() {
419 380
  reset_state() if $ALWAYS_RESET;
420 381

  
421
  my $item1   = new_item(qty => 2.5);
422
  my $item2   = new_item(qty => 1.2, part => $parts[1]);
423
  my $invoice = new_invoice(
382
  my $item1   = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5);
383
  my $item2   = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 1.2);
384
  my $invoice = SL::Dev::Record::create_sales_invoice(
424 385
    taxincluded  => 0,
425 386
    invoiceitems => [ $item1, $item2 ],
426
    payment_id  => $payment_terms->id,
387
    payment_id   => $payment_terms->id,
427 388
  );
428
  $invoice->post;
429 389

  
430 390
  # default values
431 391
  my %params = ( chart_id => $bank_account->chart_id,
......
453 413
sub test_default_invoice_two_items_19_7_tax_with_skonto_tax_included() {
454 414
  reset_state() if $ALWAYS_RESET;
455 415

  
456
  my $item1   = new_item(qty => 2.5);
457
  my $item2   = new_item(qty => 1.2, part => $parts[1]);
458
  my $invoice = new_invoice(
416
  my $item1   = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5);
417
  my $item2   = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 1.2);
418
  my $invoice = SL::Dev::Record::create_sales_invoice(
459 419
    taxincluded  => 1,
460 420
    invoiceitems => [ $item1, $item2 ],
461
    payment_id  => $payment_terms->id,
421
    payment_id   => $payment_terms->id,
462 422
  );
463
  $invoice->post;
464 423

  
465 424
  # default values
466 425
  my %params = ( chart_id => $bank_account->chart_id,
......
491 450
sub test_default_invoice_two_items_19_7_without_skonto() {
492 451
  reset_state() if $ALWAYS_RESET;
493 452

  
494
  my $item1   = new_item(qty => 2.5);
495
  my $item2   = new_item(qty => 1.2, part => $parts[1]);
496
  my $invoice = new_invoice(
453
  my $item1   = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5);
454
  my $item2   = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 1.2);
455
  my $invoice = SL::Dev::Record::create_sales_invoice(
497 456
    taxincluded  => 0,
498 457
    invoiceitems => [ $item1, $item2 ],
499
    payment_id  => $payment_terms->id,
458
    payment_id   => $payment_terms->id,
500 459
  );
501
  $invoice->post;
502 460

  
503 461
  # default values
504 462
  my %params = ( chart_id => $bank_account->chart_id,
......
527 485
sub test_default_invoice_two_items_19_7_without_skonto_incomplete_payment() {
528 486
  reset_state() if $ALWAYS_RESET;
529 487

  
530
  my $item1   = new_item(qty => 2.5);
531
  my $item2   = new_item(qty => 1.2, part => $parts[1]);
532
  my $invoice = new_invoice(
488
  my $item1   = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5);
489
  my $item2   = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 1.2);
490
  my $invoice = SL::Dev::Record::create_sales_invoice(
533 491
    taxincluded  => 0,
534 492
    invoiceitems => [ $item1, $item2 ],
535
    payment_id  => $payment_terms->id,
493
    payment_id   => $payment_terms->id,
536 494
  );
537
  $invoice->post;
538 495

  
539 496
  $invoice->pay_invoice( amount       => '9.44',
540 497
                         payment_type => 'without_skonto',
......
559 516
sub test_default_invoice_two_items_19_7_tax_without_skonto_multiple_payments() {
560 517
  reset_state() if $ALWAYS_RESET;
561 518

  
562
  my $item1   = new_item(qty => 2.5);
563
  my $item2   = new_item(qty => 1.2, part => $parts[1]);
564
  my $invoice = new_invoice(
519
  my $item1   = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5);
520
  my $item2   = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 1.2);
521
  my $invoice = SL::Dev::Record::create_sales_invoice(
565 522
    taxincluded  => 0,
566 523
    invoiceitems => [ $item1, $item2 ],
567
    payment_id  => $payment_terms->id,
524
    payment_id   => $payment_terms->id,
568 525
  );
569
  $invoice->post;
570 526

  
571 527
  $invoice->pay_invoice( amount       => '9.44',
572 528
                         payment_type => 'without_skonto',
......
596 552
sub test_default_invoice_two_items_19_7_tax_without_skonto_multiple_payments_final_difference_as_skonto() {
597 553
  reset_state() if $ALWAYS_RESET;
598 554

  
599
  my $item1   = new_item(qty => 2.5);
600
  my $item2   = new_item(qty => 1.2, part => $parts[1]);
601
  my $invoice = new_invoice(
555
  my $item1   = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5);
556
  my $item2   = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 1.2);
557
  my $invoice = SL::Dev::Record::create_sales_invoice(
602 558
    taxincluded  => 0,
603 559
    invoiceitems => [ $item1, $item2 ],
604
    payment_id  => $payment_terms->id,
560
    payment_id   => $payment_terms->id,
605 561
  );
606
  $invoice->post;
607 562

  
608 563
  $invoice->pay_invoice( amount       => '9.44',
609 564
                         payment_type => 'without_skonto',
......
643 598
  # (11.66) rather than the 19% account (5.85).  The actual tax amount is
644 599
  # higher for the 19% case, though (1.11 compared to 0.82)
645 600

  
646
  my $item1   = new_item(qty => 2.5);
647
  my $item2   = new_item(qty => 1.2, part => $parts[1]);
648
  my $invoice = new_invoice(
601
  my $item1   = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5);
602
  my $item2   = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 1.2);
603
  my $invoice = SL::Dev::Record::create_sales_invoice(
649 604
    taxincluded  => 0,
650 605
    invoiceitems => [ $item1, $item2 ],
651
    payment_id  => $payment_terms->id,
606
    payment_id   => $payment_terms->id,
652 607
  );
653
  $invoice->post;
654 608

  
655 609
  $invoice->pay_invoice( amount       => '19.42',
656 610
                         payment_type => 'without_skonto',
......
681 635
  reset_state() if $ALWAYS_RESET;
682 636

  
683 637
  # if there are two cents left there will be two skonto bookings, 1 cent each
684
  my $item1   = new_item(qty => 2.5);
685
  my $item2   = new_item(qty => 1.2, part => $parts[1]);
686
  my $invoice = new_invoice(
638
  my $item1   = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5);
639
  my $item2   = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 1.2);
640
  my $invoice = SL::Dev::Record::create_sales_invoice(
687 641
    taxincluded  => 0,
688 642
    invoiceitems => [ $item1, $item2 ],
689
    payment_id  => $payment_terms->id,
643
    payment_id   => $payment_terms->id,
690 644
  );
691
  $invoice->post;
692 645

  
693 646
  $invoice->pay_invoice( amount       => '19.42',
694 647
                         payment_type => 'without_skonto',
......
718 671
sub test_default_invoice_one_item_19_multiple_payment_final_difference_as_skonto() {
719 672
  reset_state() if $ALWAYS_RESET;
720 673

  
721
  my $item    = new_item(qty => 2.5);
722
  my $invoice = new_invoice(
674
  my $item    = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5);
675
  my $invoice = SL::Dev::Record::create_sales_invoice(
723 676
    taxincluded  => 0,
724 677
    invoiceitems => [ $item ],
725 678
    payment_id   => $payment_terms->id,
726 679
  );
727
  $invoice->post;
728 680

  
729 681
  # default values
730 682
  my %params = ( chart_id  => $bank_account->chart_id,
......
760 712
sub test_default_invoice_one_item_19_multiple_payment_final_difference_as_skonto_1cent() {
761 713
  reset_state() if $ALWAYS_RESET;
762 714

  
763
  my $item    = new_item(qty => 2.5);
764
  my $invoice = new_invoice(
715
  my $item    = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5);
716
  my $invoice = SL::Dev::Record::create_sales_invoice(
765 717
    taxincluded  => 0,
766 718
    invoiceitems => [ $item ],
767 719
    payment_id   => $payment_terms->id,
768 720
  );
769
  $invoice->post;
770 721

  
771 722
  # default values
772 723
  my %params = ( chart_id  => $bank_account->chart_id,
......
906 857
sub test_default_invoice_two_items_19_7_tax_with_skonto_50_50() {
907 858
  reset_state() if $ALWAYS_RESET;
908 859

  
909
  my $item1   = new_item(qty => 1, part => $parts[2]);
910
  my $item2   = new_item(qty => 1, part => $parts[3]);
911
  my $invoice = new_invoice(
860
  my $item1   = SL::Dev::Record::create_invoice_item(part => $parts[2], qty => 1);
861
  my $item2   = SL::Dev::Record::create_invoice_item(part => $parts[3], qty => 1);
862
  my $invoice = SL::Dev::Record::create_sales_invoice(
912 863
    taxincluded  => 0,
913 864
    invoiceitems => [ $item1, $item2 ],
914
    payment_id  => $payment_terms->id,
865
    payment_id   => $payment_terms->id,
915 866
  );
916
  $invoice->post;
917 867

  
918 868
  # default values
919 869
  my %params = ( chart_id => $bank_account->chart_id,
......
942 892
sub test_default_invoice_four_items_19_7_tax_with_skonto_4x_25() {
943 893
  reset_state() if $ALWAYS_RESET;
944 894

  
945
  my $item1   = new_item(qty => 0.5, part => $parts[2]);
946
  my $item2   = new_item(qty => 0.5, part => $parts[3]);
947
  my $item3   = new_item(qty => 0.5, part => $parts[2]);
948
  my $item4   = new_item(qty => 0.5, part => $parts[3]);
949
  my $invoice = new_invoice(
895
  my $item1   = SL::Dev::Record::create_invoice_item(part => $parts[2], qty => 0.5);
896
  my $item2   = SL::Dev::Record::create_invoice_item(part => $parts[3], qty => 0.5);
897
  my $item3   = SL::Dev::Record::create_invoice_item(part => $parts[2], qty => 0.5);
898
  my $item4   = SL::Dev::Record::create_invoice_item(part => $parts[3], qty => 0.5);
899
  my $invoice = SL::Dev::Record::create_sales_invoice(
950 900
    taxincluded  => 0,
951 901
    invoiceitems => [ $item1, $item2, $item3, $item4 ],
952
    payment_id  => $payment_terms->id,
902
    payment_id   => $payment_terms->id,
953 903
  );
954
  $invoice->post;
955 904

  
956 905
  # default values
957 906
  my %params = ( chart_id => $bank_account->chart_id,
......
979 928
sub test_default_invoice_four_items_19_7_tax_with_skonto_4x_25_tax_included() {
980 929
  reset_state() if $ALWAYS_RESET;
981 930

  
982
  my $item1   = new_item(qty => 0.5, part => $parts[2]);
983
  my $item2   = new_item(qty => 0.5, part => $parts[3]);
984
  my $item3   = new_item(qty => 0.5, part => $parts[2]);
985
  my $item4   = new_item(qty => 0.5, part => $parts[3]);
986
  my $invoice = new_invoice(
931
  my $item1   = SL::Dev::Record::create_invoice_item(part => $parts[2], qty => 0.5);
932
  my $item2   = SL::Dev::Record::create_invoice_item(part => $parts[3], qty => 0.5);
933
  my $item3   = SL::Dev::Record::create_invoice_item(part => $parts[2], qty => 0.5);
934
  my $item4   = SL::Dev::Record::create_invoice_item(part => $parts[3], qty => 0.5);
935
  my $invoice = SL::Dev::Record::create_sales_invoice(
987 936
    taxincluded  => 1,
988 937
    invoiceitems => [ $item1, $item2, $item3, $item4 ],
989
    payment_id  => $payment_terms->id,
938
    payment_id   => $payment_terms->id,
990 939
  );
991
  $invoice->post;
992 940

  
993 941
  # default values
994 942
  my %params = ( chart_id => $bank_account->chart_id,
......
1018 966
sub test_default_invoice_four_items_19_7_tax_with_skonto_4x_25_multiple() {
1019 967
  reset_state() if $ALWAYS_RESET;
1020 968

  
1021
  my $item1   = new_item(qty => 0.5, part => $parts[2]);
1022
  my $item2   = new_item(qty => 0.5, part => $parts[3]);
1023
  my $item3   = new_item(qty => 0.5, part => $parts[2]);
1024
  my $item4   = new_item(qty => 0.5, part => $parts[3]);
1025
  my $invoice = new_invoice(
969
  my $item1   = SL::Dev::Record::create_invoice_item(part => $parts[2], qty => 0.5);
970
  my $item2   = SL::Dev::Record::create_invoice_item(part => $parts[3], qty => 0.5);
971
  my $item3   = SL::Dev::Record::create_invoice_item(part => $parts[2], qty => 0.5);
972
  my $item4   = SL::Dev::Record::create_invoice_item(part => $parts[3], qty => 0.5);
973
  my $invoice = SL::Dev::Record::create_sales_invoice(
1026 974
    taxincluded  => 0,
1027 975
    invoiceitems => [ $item1, $item2, $item3, $item4 ],
1028
    payment_id  => $payment_terms->id,
976
    payment_id   => $payment_terms->id,
1029 977
  );
1030
  $invoice->post;
1031 978

  
1032 979
  $invoice->pay_invoice( amount       => '90',
1033 980
                         payment_type => 'without_skonto',

Auch abrufbar als: Unified diff