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

(-)a/Koha/Item.pm (-3 / +3 lines)
Lines 927-939 sub get_transfers { Link Here
927
    return Koha::Item::Transfers->_new_from_dbic($transfers_rs);
927
    return Koha::Item::Transfers->_new_from_dbic($transfers_rs);
928
}
928
}
929
929
930
=head3 last_returned_by_all
930
=head3 last_borrowers
931
931
932
Returns all patrons who have returned this item, ordered by most recent first.
932
Returns all patrons who have returned this item, ordered by most recent first.
933
933
934
=cut
934
=cut
935
935
936
sub last_returned_by_all {
936
sub last_borrowers {
937
    my ($self) = @_;
937
    my ($self) = @_;
938
938
939
    my $max_stored_borrowers = C4::Context->preference('StoreLastBorrower') || 0;
939
    my $max_stored_borrowers = C4::Context->preference('StoreLastBorrower') || 0;
Lines 977-983 sub last_returned_by { Link Here
977
977
978
                # If StoreLastBorrower is 0 or disabled, bail without storing anything. Also delete any remaining rows from the table.
978
                # If StoreLastBorrower is 0 or disabled, bail without storing anything. Also delete any remaining rows from the table.
979
                if ( $max_stored_borrowers == 0 ) {
979
                if ( $max_stored_borrowers == 0 ) {
980
                    $self->last_returned_by_all->delete;
980
                    $self->last_borrowers->delete;
981
                    return $self;
981
                    return $self;
982
                }
982
                }
983
983
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt (-1 / +1 lines)
Lines 495-501 Link Here
495
                                </li>
495
                                </li>
496
496
497
                                [% IF Koha.Preference('StoreLastBorrower') && Koha.Preference('StoreLastBorrower') > 0 %]
497
                                [% IF Koha.Preference('StoreLastBorrower') && Koha.Preference('StoreLastBorrower') > 0 %]
498
                                    [% SET all_borrowers = ITEM_DAT.object.last_returned_by_all %]
498
                                    [% SET all_borrowers = ITEM_DAT.object.last_borrowers %]
499
                                    [% IF all_borrowers.count > 0 %]
499
                                    [% IF all_borrowers.count > 0 %]
500
                                        <li>
500
                                        <li>
501
                                            <span class="label">Last returned by:</span>
501
                                            <span class="label">Last returned by:</span>
(-)a/t/db_dependent/Circulation/StoreLastBorrower.t (-11 / +10 lines)
Lines 150-159 subtest 'Test StoreLastBorrower with multiple borrowers' => sub { Link Here
150
    my $item    = $builder->build_sample_item;
150
    my $item    = $builder->build_sample_item;
151
    t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode } );
151
    t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode } );
152
152
153
    # Test last_returned_by_all with no borrowers
153
    # Test last_borrowers with no borrowers
154
    t::lib::Mocks::mock_preference( 'StoreLastBorrower', '3' );
154
    t::lib::Mocks::mock_preference( 'StoreLastBorrower', '3' );
155
    my $borrowers = $item->last_returned_by_all();
155
    my $borrowers = $item->last_borrowers();
156
    is( $borrowers->count, 0, 'last_returned_by_all returns empty set when no borrowers stored' );
156
    is( $borrowers->count, 0, 'last_borrowers returns empty set when no borrowers stored' );
157
157
158
    # Add 3 borrowers for testing, checkout/check in
158
    # Add 3 borrowers for testing, checkout/check in
159
    my @patrons;
159
    my @patrons;
Lines 182-189 subtest 'Test StoreLastBorrower with multiple borrowers' => sub { Link Here
182
182
183
    $item = $item->get_from_storage;
183
    $item = $item->get_from_storage;
184
184
185
    # Test last_returned_by_all returns all borrowers
185
    # Test last_borrowers returns all borrowers
186
    $borrowers = $item->last_returned_by_all();
186
    $borrowers = $item->last_borrowers();
187
    is( $borrowers->count, 3, 'Correctly returns 3 borrowers' );
187
    is( $borrowers->count, 3, 'Correctly returns 3 borrowers' );
188
188
189
    # Test ordering
189
    # Test ordering
Lines 217-223 subtest 'Test StoreLastBorrower with multiple borrowers' => sub { Link Here
217
    }
217
    }
218
218
219
    $item      = $item->get_from_storage;
219
    $item      = $item->get_from_storage;
220
    $borrowers = $item->last_returned_by_all();
220
    $borrowers = $item->last_borrowers();
221
    is(
221
    is(
222
        $borrowers->count, 3,
222
        $borrowers->count, 3,
223
        'We only retain 3 borrowers when the sys pref is set to 3, even though there are 5 checkouts/checkins'
223
        'We only retain 3 borrowers when the sys pref is set to 3, even though there are 5 checkouts/checkins'
Lines 251-257 subtest 'Test StoreLastBorrower with multiple borrowers' => sub { Link Here
251
    );
251
    );
252
252
253
    $item      = $item->get_from_storage;
253
    $item      = $item->get_from_storage;
254
    $borrowers = $item->last_returned_by_all();
254
    $borrowers = $item->last_borrowers();
255
    is( $borrowers->count, 2, 'StoreLastBorrower was reduced to 2, we should now only keep 2 in the table' );
255
    is( $borrowers->count, 2, 'StoreLastBorrower was reduced to 2, we should now only keep 2 in the table' );
256
    @borrowers_array = $borrowers->as_list;
256
    @borrowers_array = $borrowers->as_list;
257
    is(
257
    is(
Lines 286-293 subtest 'Test StoreLastBorrower with multiple borrowers' => sub { Link Here
286
    );
286
    );
287
287
288
    $item      = $item->get_from_storage;
288
    $item      = $item->get_from_storage;
289
    $borrowers = $item->last_returned_by_all();
289
    $borrowers = $item->last_borrowers();
290
    is( $borrowers->count, 0, 'last_returned_by_all respects preference value 0' );
290
    is( $borrowers->count, 0, 'last_borrowers respects preference value 0' );
291
291
292
    my $cleanup_patron = $builder->build(
292
    my $cleanup_patron = $builder->build(
293
        {
293
        {
Lines 312-318 subtest 'Test StoreLastBorrower with multiple borrowers' => sub { Link Here
312
    );
312
    );
313
313
314
    $item      = $item->get_from_storage;
314
    $item      = $item->get_from_storage;
315
    $borrowers = $item->last_returned_by_all();
315
    $borrowers = $item->last_borrowers();
316
    is( $borrowers->count,       0,     'All entries cleared when preference is 0' );
316
    is( $borrowers->count,       0,     'All entries cleared when preference is 0' );
317
    is( $item->last_returned_by, undef, 'last_returned_by returns undef when no records' );
317
    is( $item->last_returned_by, undef, 'last_returned_by returns undef when no records' );
318
318
319
- 

Return to bug 26993