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

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

Return to bug 19935