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

(-)a/C4/Circulation.pm (+2 lines)
Lines 1530-1535 sub AddIssue { Link Here
1530
                  );
1530
                  );
1531
1531
1532
                if ($lostreturn_policy) {
1532
                if ($lostreturn_policy) {
1533
1533
                    if ( $lostreturn_policy eq 'charge' ) {
1534
                    if ( $lostreturn_policy eq 'charge' ) {
1534
                        $actualissue //= Koha::Old::Checkouts->search(
1535
                        $actualissue //= Koha::Old::Checkouts->search(
1535
                            { itemnumber => $item_unblessed->{itemnumber} },
1536
                            { itemnumber => $item_unblessed->{itemnumber} },
Lines 2076-2081 sub AddReturn { Link Here
2076
              );
2077
              );
2077
2078
2078
            if ($lostreturn_policy) {
2079
            if ($lostreturn_policy) {
2080
2079
                if ( $lostreturn_policy eq 'charge' ) {
2081
                if ( $lostreturn_policy eq 'charge' ) {
2080
                    $issue //= Koha::Old::Checkouts->search(
2082
                    $issue //= Koha::Old::Checkouts->search(
2081
                        { itemnumber => $item->itemnumber },
2083
                        { itemnumber => $item->itemnumber },
(-)a/t/db_dependent/Circulation.t (-3 / +68 lines)
Lines 22-27 use Test::More tests => 48; Link Here
22
use Test::Exception;
22
use Test::Exception;
23
use Test::MockModule;
23
use Test::MockModule;
24
use Test::Deep qw( cmp_deeply );
24
use Test::Deep qw( cmp_deeply );
25
use Test::Warn;
25
26
26
use Data::Dumper;
27
use Data::Dumper;
27
use DateTime;
28
use DateTime;
Lines 2419-2425 subtest 'AddReturn | is_overdue' => sub { Link Here
2419
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
2420
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
2420
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2421
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2421
2422
2422
    subtest 'bug 22877' => sub {
2423
    subtest 'bug 22877 | Lost item return' => sub {
2423
2424
2424
        plan tests => 3;
2425
        plan tests => 3;
2425
2426
Lines 2669-2674 subtest 'AddReturn | is_overdue' => sub { Link Here
2669
    };
2670
    };
2670
};
2671
};
2671
2672
2673
subtest '_RestoreOverdueForLostAndFound' => sub {
2674
2675
    plan tests => 7;
2676
2677
    my $manager = $builder->build_object( { class => "Koha::Patrons" } );
2678
    t::lib::Mocks::mock_userenv(
2679
        { patron => $manager, branchcode => $manager->branchcode } );
2680
2681
    my $patron = $builder->build_object( { class => "Koha::Patrons" } );
2682
    my $item = $builder->build_sample_item();
2683
2684
    # No fine found
2685
    my $result = C4::Circulation::_RestoreOverdueForLostAndFound( $item->itemnumber);
2686
    is($result, 0, "0 returned when no overdue found");
2687
2688
    # Fine not forgiven
2689
    my $account = $patron->account;
2690
    my $overdue = $account->add_debit(
2691
        {
2692
            amount     => 30.00,
2693
            user_id    => $manager->borrowernumber,
2694
            library_id => $library2->{branchcode},
2695
            interface  => 'test',
2696
            item_id    => $item->itemnumber,
2697
            type       => 'OVERDUE',
2698
        }
2699
    )->store();
2700
    $overdue->status('LOST')->store();
2701
2702
    $result = C4::Circulation::_RestoreOverdueForLostAndFound( $item->itemnumber);
2703
    is($result, 0, "0 returned when overdue found without forgival");
2704
    $overdue->discard_changes;
2705
    is($overdue->status, 'RETURNED', 'Overdue status updated to RETURNED');
2706
2707
    # Reset status
2708
    $overdue->status('LOST')->store();
2709
2710
    # Fine forgiven
2711
    my $credit = $account->add_credit(
2712
        {
2713
            amount     => 30.00,
2714
            user_id    => $manager->borrowernumber,
2715
            library_id => $library2->{branchcode},
2716
            interface  => 'test',
2717
            type       => 'FORGIVEN',
2718
            item_id    => $item->itemnumber
2719
        }
2720
    );
2721
    $credit->apply( { debits => [$overdue], offset_type => 'Forgiven' } );
2722
2723
    $result = C4::Circulation::_RestoreOverdueForLostAndFound( $item->itemnumber);
2724
2725
    is( ref($result), 'Koha::Account::Line', 'Return a Koha::Account::Line object on sucess');
2726
    $overdue->discard_changes;
2727
    is($overdue->status, 'RETURNED', 'Overdue status updated to RETURNED');
2728
    is($overdue->amountoutstanding, $overdue->amount, 'Overdue outstanding restored');
2729
2730
    # Missing parameters
2731
    warning_like {
2732
        C4::Circulation::_RestoreOverdueForLostAndFound( undef )
2733
    }
2734
    qr/_RestoreOverdueForLostAndFound\(\) not supplied valid itemnumber/,
2735
      "parameter warning received for missing itemnumbernumber";
2736
};
2737
2672
subtest '_FixOverduesOnReturn' => sub {
2738
subtest '_FixOverduesOnReturn' => sub {
2673
    plan tests => 14;
2739
    plan tests => 14;
2674
2740
Lines 2727-2733 subtest '_FixOverduesOnReturn' => sub { Link Here
2727
2793
2728
    is( $accountline->amountoutstanding + 0, 0, 'Fine amountoutstanding has been reduced to 0' );
2794
    is( $accountline->amountoutstanding + 0, 0, 'Fine amountoutstanding has been reduced to 0' );
2729
    isnt( $accountline->status, 'UNRETURNED', 'Open fine ( account type OVERDUE ) has been closed out ( status not UNRETURNED )');
2795
    isnt( $accountline->status, 'UNRETURNED', 'Open fine ( account type OVERDUE ) has been closed out ( status not UNRETURNED )');
2730
    is( $accountline->status, 'FORGIVEN', 'Open fine ( account type OVERDUE ) has been set to fine forgiven ( status FORGIVEN )');
2796
    is( $accountline->status, 'RETURNED', 'Open fine ( account type OVERDUE ) has been set to returned ( status RETURNED )');
2731
    is( ref $offset, "Koha::Account::Offset", "Found matching offset for fine reduction via forgiveness" );
2797
    is( ref $offset, "Koha::Account::Offset", "Found matching offset for fine reduction via forgiveness" );
2732
    is( $offset->amount + 0, -99, "Amount of offset is correct" );
2798
    is( $offset->amount + 0, -99, "Amount of offset is correct" );
2733
    my $credit = $offset->credit;
2799
    my $credit = $offset->credit;
2734
- 

Return to bug 23091