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 427-434 subtest 'add_enrolment_fee_if_needed' => sub { Link Here
427
    $patron->delete;
427
    $patron->delete;
428
};
428
};
429
429
430
subtest 'checkouts + get_overdues + old_checkouts' => sub {
430
subtest 'checkouts + pending_checkouts + get_overdues + old_checkouts' => sub {
431
    plan tests => 12;
431
    plan tests => 17;
432
432
433
    my $library = $builder->build( { source => 'Branch' } );
433
    my $library = $builder->build( { source => 'Branch' } );
434
    my ($biblionumber_1) = AddBiblio( MARC::Record->new, '' );
434
    my ($biblionumber_1) = AddBiblio( MARC::Record->new, '' );
Lines 480-485 subtest 'checkouts + get_overdues + old_checkouts' => sub { Link Here
480
    my $checkouts = $patron->checkouts;
480
    my $checkouts = $patron->checkouts;
481
    is( $checkouts->count, 0, 'checkouts should not return any issues for that patron' );
481
    is( $checkouts->count, 0, 'checkouts should not return any issues for that patron' );
482
    is( ref($checkouts), 'Koha::Checkouts', 'checkouts should return a Koha::Checkouts object' );
482
    is( ref($checkouts), 'Koha::Checkouts', 'checkouts should return a Koha::Checkouts object' );
483
    my $pending_checkouts = $patron->pending_checkouts;
484
    is( $pending_checkouts->count, 0, 'pending_checkouts should not return any issues for that patron' );
485
    is( ref($pending_checkouts), 'Koha::Checkouts', 'pending_checkouts should return a Koha::Checkouts object' );
483
    my $old_checkouts = $patron->old_checkouts;
486
    my $old_checkouts = $patron->old_checkouts;
484
    is( $old_checkouts->count, 0, 'old_checkouts should not return any issues for that patron' );
487
    is( $old_checkouts->count, 0, 'old_checkouts should not return any issues for that patron' );
485
    is( ref($old_checkouts), 'Koha::Old::Checkouts', 'old_checkouts should return a Koha::Old::Checkouts object' );
488
    is( ref($old_checkouts), 'Koha::Old::Checkouts', 'old_checkouts should return a Koha::Old::Checkouts object' );
Lines 498-503 subtest 'checkouts + get_overdues + old_checkouts' => sub { Link Here
498
    $checkouts = $patron->checkouts;
501
    $checkouts = $patron->checkouts;
499
    is( $checkouts->count, 3, 'checkouts should return 3 issues for that patron' );
502
    is( $checkouts->count, 3, 'checkouts should return 3 issues for that patron' );
500
    is( ref($checkouts), 'Koha::Checkouts', 'checkouts should return a Koha::Checkouts object' );
503
    is( ref($checkouts), 'Koha::Checkouts', 'checkouts should return a Koha::Checkouts object' );
504
    $pending_checkouts = $patron->pending_checkouts;
505
    is( $pending_checkouts->count, 3, 'pending_checkouts should return 3 issues for that patron' );
506
    is( ref($pending_checkouts), 'Koha::Checkouts', 'pending_checkouts should return a Koha::Checkouts object' );
507
508
    my $first_checkout = $pending_checkouts->next;
509
    is( $first_checkout->unblessed_all_relateds->{biblionumber}, $item_3->{biblionumber}, 'pending_checkouts should prefetch values from other tables (here biblio)' );
501
510
502
    my $overdues = $patron->get_overdues;
511
    my $overdues = $patron->get_overdues;
503
    is( $overdues->count, 2, 'Patron should have 2 overdues');
512
    is( $overdues->count, 2, 'Patron should have 2 overdues');
504
- 

Return to bug 19935