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

(-)a/t/db_dependent/Circulation.t (-33 / +10 lines)
Lines 1652-1659 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
1652
      ;    # Add another overdue
1652
      ;    # Add another overdue
1653
1653
1654
    t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '0' );
1654
    t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '0' );
1655
    AddReturn( $item_1->{barcode}, $library->{branchcode},
1655
    AddReturn( $item_1->{barcode}, $library->{branchcode}, undef, dt_from_string );
1656
        undef, undef, dt_from_string );
1657
    my $debarments = Koha::Patron::Debarments::GetDebarments(
1656
    my $debarments = Koha::Patron::Debarments::GetDebarments(
1658
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1657
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1659
    is( scalar(@$debarments), 1 );
1658
    is( scalar(@$debarments), 1 );
Lines 1669-1676 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
1669
    );
1668
    );
1670
    is( $debarments->[0]->{expiration}, $expected_expiration );
1669
    is( $debarments->[0]->{expiration}, $expected_expiration );
1671
1670
1672
    AddReturn( $item_2->{barcode}, $library->{branchcode},
1671
    AddReturn( $item_2->{barcode}, $library->{branchcode}, undef, dt_from_string );
1673
        undef, undef, dt_from_string );
1674
    $debarments = Koha::Patron::Debarments::GetDebarments(
1672
    $debarments = Koha::Patron::Debarments::GetDebarments(
1675
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1673
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1676
    is( scalar(@$debarments), 1 );
1674
    is( scalar(@$debarments), 1 );
Lines 1690-1697 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
1690
    AddIssue( $patron, $item_1->{barcode}, $five_days_ago );    # Add an overdue
1688
    AddIssue( $patron, $item_1->{barcode}, $five_days_ago );    # Add an overdue
1691
    AddIssue( $patron, $item_2->{barcode}, $ten_days_ago )
1689
    AddIssue( $patron, $item_2->{barcode}, $ten_days_ago )
1692
      ;    # Add another overdue
1690
      ;    # Add another overdue
1693
    AddReturn( $item_1->{barcode}, $library->{branchcode},
1691
    AddReturn( $item_1->{barcode}, $library->{branchcode}, undef, dt_from_string );
1694
        undef, undef, dt_from_string );
1695
    $debarments = Koha::Patron::Debarments::GetDebarments(
1692
    $debarments = Koha::Patron::Debarments::GetDebarments(
1696
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1693
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1697
    is( scalar(@$debarments), 1 );
1694
    is( scalar(@$debarments), 1 );
Lines 1704-1711 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
1704
    );
1701
    );
1705
    is( $debarments->[0]->{expiration}, $expected_expiration );
1702
    is( $debarments->[0]->{expiration}, $expected_expiration );
1706
1703
1707
    AddReturn( $item_2->{barcode}, $library->{branchcode},
1704
    AddReturn( $item_2->{barcode}, $library->{branchcode}, undef, dt_from_string );
1708
        undef, undef, dt_from_string );
1709
    $debarments = Koha::Patron::Debarments::GetDebarments(
1705
    $debarments = Koha::Patron::Debarments::GetDebarments(
1710
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1706
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1711
    is( scalar(@$debarments), 1 );
1707
    is( scalar(@$debarments), 1 );
Lines 1934-1958 subtest 'AddReturn | is_overdue' => sub { Link Here
1934
1930
1935
    # specify return date 5 days before => no overdue
1931
    # specify return date 5 days before => no overdue
1936
    AddIssue( $patron->unblessed, $item->{barcode}, $five_days_ago ); # date due was 5d ago
1932
    AddIssue( $patron->unblessed, $item->{barcode}, $five_days_ago ); # date due was 5d ago
1937
    AddReturn( $item->{barcode}, $library->{branchcode}, undef, undef, $ten_days_ago );
1933
    AddReturn( $item->{barcode}, $library->{branchcode}, undef, $ten_days_ago );
1938
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
1934
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
1939
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
1935
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
1940
1936
1941
    # specify return date 5 days later => overdue
1937
    # specify return date 5 days later => overdue
1942
    AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago
1938
    AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago
1943
    AddReturn( $item->{barcode}, $library->{branchcode}, undef, undef, $five_days_ago );
1939
    AddReturn( $item->{barcode}, $library->{branchcode}, undef, $five_days_ago );
1944
    is( int($patron->account->balance()), 5, 'AddReturn: pass return_date => overdue' );
1940
    is( int($patron->account->balance()), 5, 'AddReturn: pass return_date => overdue' );
1945
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
1941
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
1946
1942
1947
    # specify dropbox date 5 days before => no overdue
1943
    # specify dropbox date 5 days before => no overdue
1948
    AddIssue( $patron->unblessed, $item->{barcode}, $five_days_ago ); # date due was 5d ago
1944
    AddIssue( $patron->unblessed, $item->{barcode}, $five_days_ago ); # date due was 5d ago
1949
    AddReturn( $item->{barcode}, $library->{branchcode}, undef, 1, undef, $ten_days_ago );
1945
    AddReturn( $item->{barcode}, $library->{branchcode}, $ten_days_ago );
1950
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
1946
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
1951
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
1947
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
1952
1948
1953
    # specify dropbox date 5 days later => overdue, or... not
1949
    # specify dropbox date 5 days later => overdue, or... not
1954
    AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago
1950
    AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago
1955
    AddReturn( $item->{barcode}, $library->{branchcode}, undef, 1, undef, $five_days_ago );
1951
    AddReturn( $item->{barcode}, $library->{branchcode}, $five_days_ago );
1956
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue in dropbox mode' ); # FIXME? This is weird, the FU fine is created ( _CalculateAndUpdateFine > C4::Overdues::UpdateFine ) then remove later (in _FixOverduesOnReturn). Looks like it is a feature
1952
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue in dropbox mode' ); # FIXME? This is weird, the FU fine is created ( _CalculateAndUpdateFine > C4::Overdues::UpdateFine ) then remove later (in _FixOverduesOnReturn). Looks like it is a feature
1957
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
1953
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
1958
};
1954
};
Lines 2335-2341 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2335
};
2331
};
2336
2332
2337
subtest '_FixOverduesOnReturn' => sub {
2333
subtest '_FixOverduesOnReturn' => sub {
2338
    plan tests => 10;
2334
    plan tests => 6;
2339
2335
2340
    my $biblio = $builder->build_sample_biblio({ author => 'Hall, Kylie' });
2336
    my $biblio = $builder->build_sample_biblio({ author => 'Hall, Kylie' });
2341
2337
Lines 2389-2412 subtest '_FixOverduesOnReturn' => sub { Link Here
2389
    is( $accountline->accounttype, 'FFOR', 'Open fine ( account type FU ) has been set to fine forgiven ( account type FFOR )');
2385
    is( $accountline->accounttype, 'FFOR', 'Open fine ( account type FU ) has been set to fine forgiven ( account type FFOR )');
2390
    is( ref $offset, "Koha::Account::Offset", "Found matching offset for fine reduction via forgiveness" );
2386
    is( ref $offset, "Koha::Account::Offset", "Found matching offset for fine reduction via forgiveness" );
2391
    is( $offset->amount, '-99.000000', "Amount of offset is correct" );
2387
    is( $offset->amount, '-99.000000', "Amount of offset is correct" );
2392
2393
    ## Run again, with dropbox mode enabled
2394
    $accountline->set(
2395
        {
2396
            accounttype    => 'FU',
2397
            amountoutstanding => 99.00,
2398
        }
2399
    )->store();
2400
2401
    C4::Circulation::_FixOverduesOnReturn( $patron->{borrowernumber}, $item->itemnumber, 0, 1 );
2402
2403
    $accountline->_result()->discard_changes();
2404
    $offset = Koha::Account::Offsets->search({ debit_id => $accountline->id, type => 'Dropbox' })->next();
2405
2406
    is( $accountline->amountoutstanding + 0, 90, 'Fine has been reduced to 90' );
2407
    is( $accountline->accounttype, 'F', 'Open fine ( account type FU ) has been closed out ( account type F )');
2408
    is( ref $offset, "Koha::Account::Offset", "Found matching offset for fine reduction via dropbox" );
2409
    is( $offset->amount, '-9.000000', "Amount of offset is correct" );
2410
};
2388
};
2411
2389
2412
subtest 'Set waiting flag' => sub {
2390
subtest 'Set waiting flag' => sub {
Lines 3007-3014 sub test_debarment_on_checkout { Link Here
3007
    my $line_number = $caller[2];
2985
    my $line_number = $caller[2];
3008
    AddIssue( $patron, $item->{barcode}, $due_date );
2986
    AddIssue( $patron, $item->{barcode}, $due_date );
3009
2987
3010
    my ( undef, $message ) = AddReturn( $item->{barcode}, $library->{branchcode},
2988
    my ( undef, $message ) = AddReturn( $item->{barcode}, $library->{branchcode}, undef, $return_date );
3011
        undef, undef, $return_date );
3012
    is( $message->{WasReturned} && exists $message->{Debarred}, 1, 'AddReturn must have debarred the patron' )
2989
    is( $message->{WasReturned} && exists $message->{Debarred}, 1, 'AddReturn must have debarred the patron' )
3013
        or diag('AddReturn returned message ' . Dumper $message );
2990
        or diag('AddReturn returned message ' . Dumper $message );
3014
    my $debarments = Koha::Patron::Debarments::GetDebarments(
2991
    my $debarments = Koha::Patron::Debarments::GetDebarments(
(-)a/t/db_dependent/Circulation/StoreLastBorrower.t (-5 / +5 lines)
Lines 19-28 use Modern::Perl; Link Here
19
19
20
use Test::More tests => 1;
20
use Test::More tests => 1;
21
21
22
use C4::Context;
23
use C4::Circulation;
22
use C4::Circulation;
24
23
use C4::Context;
25
use Koha::Database;
24
use Koha::Database;
25
use Koha::DateUtils;
26
use Koha::Items;
26
use Koha::Items;
27
27
28
use t::lib::Mocks;
28
use t::lib::Mocks;
Lines 69-75 subtest 'Test StoreLastBorrower' => sub { Link Here
69
    my $patron_object = $item_object->last_returned_by();
69
    my $patron_object = $item_object->last_returned_by();
70
    is( $patron_object, undef, 'Koha::Item::last_returned_by returned undef' );
70
    is( $patron_object, undef, 'Koha::Item::last_returned_by returned undef' );
71
71
72
    my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, $patron->{branchcode}, undef, undef, '2010-10-10' );
72
    my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, $patron->{branchcode},  undef, dt_from_string('2010-10-10') );
73
73
74
    $item_object   = Koha::Items->find( $item->{itemnumber} );
74
    $item_object   = Koha::Items->find( $item->{itemnumber} );
75
    $patron_object = $item_object->last_returned_by();
75
    $patron_object = $item_object->last_returned_by();
Lines 92-98 subtest 'Test StoreLastBorrower' => sub { Link Here
92
        }
92
        }
93
    );
93
    );
94
94
95
    ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, $patron->{branchcode}, undef, undef, '2010-10-10' );
95
    ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, $patron->{branchcode}, undef, dt_from_string('2010-10-10') );
96
96
97
    $item_object   = Koha::Items->find( $item->{itemnumber} );
97
    $item_object   = Koha::Items->find( $item->{itemnumber} );
98
    $patron_object = $item_object->last_returned_by();
98
    $patron_object = $item_object->last_returned_by();
Lines 133-139 subtest 'Test StoreLastBorrower' => sub { Link Here
133
            },
133
            },
134
        }
134
        }
135
    );
135
    );
136
    ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, $patron->{branchcode}, undef, undef, '2010-10-10' );
136
    ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, $patron->{branchcode}, undef, dt_from_string('2010-10-10') );
137
137
138
    $item_object   = Koha::Items->find( $item->{itemnumber} );
138
    $item_object   = Koha::Items->find( $item->{itemnumber} );
139
    is( $item_object->last_returned_by, undef, 'Last patron to return item should not be stored if StoreLastBorrower if off' );
139
    is( $item_object->last_returned_by, undef, 'Last patron to return item should not be stored if StoreLastBorrower if off' );
(-)a/t/db_dependent/Koha/Patrons.t (-6 / +5 lines)
Lines 868-875 subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { Link Here
868
            }
868
            }
869
        );
869
        );
870
870
871
        my ( $returned_1, undef, undef ) = C4::Circulation::AddReturn( $item_1->{barcode}, undef, undef, undef, '2010-10-10' );
871
        my ( $returned_1, undef, undef ) = C4::Circulation::AddReturn( $item_1->{barcode}, undef, undef, dt_from_string('2010-10-10') );
872
        my ( $returned_2, undef, undef ) = C4::Circulation::AddReturn( $item_2->{barcode}, undef, undef, undef, '2011-11-11' );
872
        my ( $returned_2, undef, undef ) = C4::Circulation::AddReturn( $item_2->{barcode}, undef, undef, dt_from_string('2011-11-11') );
873
        is( $returned_1 && $returned_2, 1, 'The items should have been returned' );
873
        is( $returned_1 && $returned_2, 1, 'The items should have been returned' );
874
874
875
        my $patrons_to_anonymise = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->search( { 'me.borrowernumber' => $patron->{borrowernumber} } );
875
        my $patrons_to_anonymise = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->search( { 'me.borrowernumber' => $patron->{borrowernumber} } );
Lines 932-938 subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { Link Here
932
            }
932
            }
933
        );
933
        );
934
934
935
        my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' );
935
        my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, dt_from_string('2010-10-10') );
936
        is( $returned, 1, 'The item should have been returned' );
936
        is( $returned, 1, 'The item should have been returned' );
937
        my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->anonymise_issue_history( { before => '2010-10-11' } );
937
        my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->anonymise_issue_history( { before => '2010-10-11' } );
938
        ok( $rows_affected > 0, 'AnonymiseIssueHistory should not return any error if success' );
938
        ok( $rows_affected > 0, 'AnonymiseIssueHistory should not return any error if success' );
Lines 973-979 subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { Link Here
973
            }
973
            }
974
        );
974
        );
975
975
976
        my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' );
976
        my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, dt_from_string('2010-10-10') );
977
        is( $returned, 1, 'The item should have been returned' );
977
        is( $returned, 1, 'The item should have been returned' );
978
        my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->anonymise_issue_history( { before => '2010-10-11' } );
978
        my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->anonymise_issue_history( { before => '2010-10-11' } );
979
        ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' );
979
        ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' );
Lines 1011-1017 subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { Link Here
1011
            }
1011
            }
1012
        );
1012
        );
1013
1013
1014
        my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' );
1014
        my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, dt_from_string('2010-10-10') );
1015
        is( Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->count, 0 );
1015
        is( Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->count, 0 );
1016
        Koha::Patrons->find( $patron->{borrowernumber})->delete;
1016
        Koha::Patrons->find( $patron->{borrowernumber})->delete;
1017
    };
1017
    };
1018
- 

Return to bug 14591