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

(-)a/Koha/Patron.pm (+31 lines)
Lines 523-528 sub checkouts { Link Here
523
    return Koha::Checkouts->_new_from_dbic( $checkouts );
523
    return Koha::Checkouts->_new_from_dbic( $checkouts );
524
}
524
}
525
525
526
=head3 pending_checkouts
527
528
my $pending_checkouts = $patron->pending_checkouts
529
530
This method will return the same as $self->checkouts, but with a prefetch on
531
items, biblio and biblioitems.
532
533
It has been introduced to replaced the C4::Members::GetPendingIssues subroutine
534
535
It should not be used directly, prefer to access fields you need instead of
536
retrieving all these fields in one go.
537
538
539
=cut
540
541
sub pending_checkouts {
542
    my( $self ) = @_;
543
    my $checkouts = $self->_result->issues->search(
544
        {},
545
        {
546
            order_by => [
547
                { -desc => 'me.timestamp' },
548
                { -desc => 'issuedate' },
549
                { -desc => 'issue_id' }, # Sort by issue_id should be enough
550
            ],
551
            prefetch => { item => { biblio => 'biblioitems' } },
552
        }
553
    );
554
    return Koha::Checkouts->_new_from_dbic( $checkouts );
555
}
556
526
=head3 old_checkouts
557
=head3 old_checkouts
527
558
528
my $old_checkouts = $patron->old_checkouts
559
my $old_checkouts = $patron->old_checkouts
(-)a/t/db_dependent/Koha/Patrons.t (-3 / +11 lines)
Lines 428-435 subtest 'add_enrolment_fee_if_needed' => sub { Link Here
428
    $patron->delete;
428
    $patron->delete;
429
};
429
};
430
430
431
subtest 'checkouts + get_overdues + old_checkouts' => sub {
431
subtest 'checkouts + pending_checkouts + get_overdues + old_checkouts' => sub {
432
    plan tests => 12;
432
    plan tests => 17;
433
433
434
    my $library = $builder->build( { source => 'Branch' } );
434
    my $library = $builder->build( { source => 'Branch' } );
435
    my ($biblionumber_1) = AddBiblio( MARC::Record->new, '' );
435
    my ($biblionumber_1) = AddBiblio( MARC::Record->new, '' );
Lines 481-486 subtest 'checkouts + get_overdues + old_checkouts' => sub { Link Here
481
    my $checkouts = $patron->checkouts;
481
    my $checkouts = $patron->checkouts;
482
    is( $checkouts->count, 0, 'checkouts should not return any issues for that patron' );
482
    is( $checkouts->count, 0, 'checkouts should not return any issues for that patron' );
483
    is( ref($checkouts), 'Koha::Checkouts', 'checkouts should return a Koha::Checkouts object' );
483
    is( ref($checkouts), 'Koha::Checkouts', 'checkouts should return a Koha::Checkouts object' );
484
    my $pending_checkouts = $patron->pending_checkouts;
485
    is( $pending_checkouts->count, 0, 'pending_checkouts should not return any issues for that patron' );
486
    is( ref($pending_checkouts), 'Koha::Checkouts', 'pending_checkouts should return a Koha::Checkouts object' );
484
    my $old_checkouts = $patron->old_checkouts;
487
    my $old_checkouts = $patron->old_checkouts;
485
    is( $old_checkouts->count, 0, 'old_checkouts should not return any issues for that patron' );
488
    is( $old_checkouts->count, 0, 'old_checkouts should not return any issues for that patron' );
486
    is( ref($old_checkouts), 'Koha::Old::Checkouts', 'old_checkouts should return a Koha::Old::Checkouts object' );
489
    is( ref($old_checkouts), 'Koha::Old::Checkouts', 'old_checkouts should return a Koha::Old::Checkouts object' );
Lines 499-504 subtest 'checkouts + get_overdues + old_checkouts' => sub { Link Here
499
    $checkouts = $patron->checkouts;
502
    $checkouts = $patron->checkouts;
500
    is( $checkouts->count, 3, 'checkouts should return 3 issues for that patron' );
503
    is( $checkouts->count, 3, 'checkouts should return 3 issues for that patron' );
501
    is( ref($checkouts), 'Koha::Checkouts', 'checkouts should return a Koha::Checkouts object' );
504
    is( ref($checkouts), 'Koha::Checkouts', 'checkouts should return a Koha::Checkouts object' );
505
    $pending_checkouts = $patron->pending_checkouts;
506
    is( $pending_checkouts->count, 3, 'pending_checkouts should return 3 issues for that patron' );
507
    is( ref($pending_checkouts), 'Koha::Checkouts', 'pending_checkouts should return a Koha::Checkouts object' );
508
509
    my $first_checkout = $pending_checkouts->next;
510
    is( $first_checkout->unblessed_all_relateds->{biblionumber}, $item_3->{biblionumber}, 'pending_checkouts should prefetch values from other tables (here biblio)' );
502
511
503
    my $overdues = $patron->get_overdues;
512
    my $overdues = $patron->get_overdues;
504
    is( $overdues->count, 2, 'Patron should have 2 overdues');
513
    is( $overdues->count, 2, 'Patron should have 2 overdues');
505
- 

Return to bug 19935