View | Details | Raw Unified | Return to bug 22982
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Account.t (-2 / +145 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 8;
22
use Test::More tests => 10;
23
use Test::MockModule;
23
use Test::MockModule;
24
use Test::Exception;
24
use Test::Exception;
25
25
Lines 586-588 subtest 'pay() tests' => sub { Link Here
586
586
587
    $schema->storage->txn_rollback;
587
    $schema->storage->txn_rollback;
588
};
588
};
589
- 
589
590
subtest 'pay() handles lost items when paying a specific lost fee' => sub {
591
592
    plan tests => 4;
593
594
    $schema->storage->txn_begin;
595
596
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
597
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
598
    my $account = $patron->account;
599
600
    my $context = Test::MockModule->new('C4::Context');
601
    $context->mock( 'userenv', { branch => $library->id } );
602
603
    my $biblio = $builder->build_sample_biblio();
604
    my $item =
605
      $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
606
607
    my $checkout = Koha::Checkout->new(
608
        {
609
            borrowernumber => $patron->id,
610
            itemnumber     => $item->id,
611
            date_due       => \'NOW()',
612
            branchcode     => $patron->branchcode,
613
            issuedate      => \'NOW()',
614
        }
615
    )->store();
616
617
    $item->itemlost('1')->store();
618
619
    my $accountline = Koha::Account::Line->new(
620
        {
621
            issue_id       => $checkout->id,
622
            borrowernumber => $patron->id,
623
            itemnumber     => $item->id,
624
            date           => \'NOW()',
625
            accounttype    => 'L',
626
            interface      => 'cli',
627
            amount => '1',
628
            amountoutstanding => '1',
629
        }
630
    )->store();
631
632
    $account->pay(
633
        {
634
            amount     => "0.500000",
635
            library_id => $library->id,
636
            lines      => [$accountline],
637
        }
638
    );
639
640
    $accountline = Koha::Account::Lines->find( $accountline->id );
641
    is( $accountline->amountoutstanding, '0.500000', 'Account line was paid down by half' );
642
643
    $checkout = Koha::Checkouts->find( $checkout->id );
644
    ok( $checkout, 'Item still checked out to patron' );
645
646
    $account->pay(
647
        {
648
            amount     => "0.500000",
649
            library_id => $library->id,
650
            lines      => [$accountline],
651
        }
652
    );
653
654
    $accountline = Koha::Account::Lines->find( $accountline->id );
655
    is( $accountline->amountoutstanding, '0.000000', 'Account line was paid down by half' );
656
657
    $checkout = Koha::Checkouts->find( $checkout->id );
658
    ok( !$checkout, 'Item was removed from patron account' );
659
660
    $schema->storage->txn_rollback;
661
};
662
663
subtest 'pay() handles lost items when paying by amount ( not specifying the lost fee )' => sub {
664
665
    plan tests => 4;
666
667
    $schema->storage->txn_begin;
668
669
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
670
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
671
    my $account = $patron->account;
672
673
    my $context = Test::MockModule->new('C4::Context');
674
    $context->mock( 'userenv', { branch => $library->id } );
675
676
    my $biblio = $builder->build_sample_biblio();
677
    my $item =
678
      $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
679
680
    my $checkout = Koha::Checkout->new(
681
        {
682
            borrowernumber => $patron->id,
683
            itemnumber     => $item->id,
684
            date_due       => \'NOW()',
685
            branchcode     => $patron->branchcode,
686
            issuedate      => \'NOW()',
687
        }
688
    )->store();
689
690
    $item->itemlost('1')->store();
691
692
    my $accountline = Koha::Account::Line->new(
693
        {
694
            issue_id       => $checkout->id,
695
            borrowernumber => $patron->id,
696
            itemnumber     => $item->id,
697
            date           => \'NOW()',
698
            accounttype    => 'L',
699
            interface      => 'cli',
700
            amount => '1',
701
            amountoutstanding => '1',
702
        }
703
    )->store();
704
705
    $account->pay(
706
        {
707
            amount     => "0.500000",
708
            library_id => $library->id,
709
        }
710
    );
711
712
    $accountline = Koha::Account::Lines->find( $accountline->id );
713
    is( $accountline->amountoutstanding, '0.500000', 'Account line was paid down by half' );
714
715
    $checkout = Koha::Checkouts->find( $checkout->id );
716
    ok( $checkout, 'Item still checked out to patron' );
717
718
    $account->pay(
719
        {
720
            amount     => "0.500000",
721
            library_id => $library->id,
722
        }
723
    );
724
725
    $accountline = Koha::Account::Lines->find( $accountline->id );
726
    is( $accountline->amountoutstanding, '0.000000', 'Account line was paid down by half' );
727
728
    $checkout = Koha::Checkouts->find( $checkout->id );
729
    ok( !$checkout, 'Item was removed from patron account' );
730
731
    $schema->storage->txn_rollback;
732
};

Return to bug 22982