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

(-)a/Koha/Patron.pm (-3 / +13 lines)
Lines 501-506 sub add_enrolment_fee_if_needed { Link Here
501
    return $enrolment_fee || 0;
501
    return $enrolment_fee || 0;
502
}
502
}
503
503
504
=head3 get_checkouts
505
506
my $issues = $patron->get_checkouts
507
508
=cut
509
510
sub get_checkouts {
511
    my ($self) = @_;
512
    my $issues = $self->_result->issues;
513
    return Koha::Checkouts->_new_from_dbic( $issues );
514
}
515
504
=head3 get_overdues
516
=head3 get_overdues
505
517
506
my $overdue_items = $patron->get_overdues
518
my $overdue_items = $patron->get_overdues
Lines 512-527 Return the overdued items Link Here
512
sub get_overdues {
524
sub get_overdues {
513
    my ($self) = @_;
525
    my ($self) = @_;
514
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
526
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
515
    my $issues = Koha::Checkouts->search(
527
    return $self->get_checkouts->search(
516
        {
528
        {
517
            'me.borrowernumber' => $self->borrowernumber,
518
            'me.date_due' => { '<' => $dtf->format_datetime(dt_from_string) },
529
            'me.date_due' => { '<' => $dtf->format_datetime(dt_from_string) },
519
        },
530
        },
520
        {
531
        {
521
            prefetch => { item => { biblio => 'biblioitems' } },
532
            prefetch => { item => { biblio => 'biblioitems' } },
522
        }
533
        }
523
    );
534
    );
524
    return $issues;
525
}
535
}
526
536
527
=head3 get_age
537
=head3 get_age
(-)a/t/db_dependent/Koha/Patrons.t (-4 / +12 lines)
Lines 412-419 subtest 'add_enrolment_fee_if_needed' => sub { Link Here
412
    $patron->delete;
412
    $patron->delete;
413
};
413
};
414
414
415
subtest 'get_overdues' => sub {
415
subtest 'get_checkouts + get_overdues' => sub {
416
    plan tests => 4;
416
    plan tests => 8;
417
417
418
    my $library = $builder->build( { source => 'Branch' } );
418
    my $library = $builder->build( { source => 'Branch' } );
419
    my ($biblionumber_1) = AddBiblio( MARC::Record->new, '' );
419
    my ($biblionumber_1) = AddBiblio( MARC::Record->new, '' );
Lines 455-462 subtest 'get_overdues' => sub { Link Here
455
        }
455
        }
456
    );
456
    );
457
457
458
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
459
    my $checkouts = $patron->get_checkouts;
460
    is( $checkouts->count, 0, 'get_checkouts should not return any issues for that patron' );
461
    is( ref($checkouts), 'Koha::Checkouts', 'get_checkouts should return a Koha::Checkouts object' );
462
458
    # Not sure how this is useful, but AddIssue pass this variable to different other subroutines
463
    # Not sure how this is useful, but AddIssue pass this variable to different other subroutines
459
    $patron = GetMember( borrowernumber => $patron->{borrowernumber} );
464
    $patron = GetMember( borrowernumber => $patron->borrowernumber );
460
465
461
    my $module = new Test::MockModule('C4::Context');
466
    my $module = new Test::MockModule('C4::Context');
462
    $module->mock( 'userenv', sub { { branch => $library->{branchcode} } } );
467
    $module->mock( 'userenv', sub { { branch => $library->{branchcode} } } );
Lines 466-471 subtest 'get_overdues' => sub { Link Here
466
    AddIssue( $patron, $item_3->{barcode} );
471
    AddIssue( $patron, $item_3->{barcode} );
467
472
468
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
473
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
474
    $checkouts = $patron->get_checkouts;
475
    is( $checkouts->count, 3, 'get_checkouts should return 3 issues for that patron' );
476
    is( ref($checkouts), 'Koha::Checkouts', 'get_checkouts should return a Koha::Checkouts object' );
477
469
    my $overdues = $patron->get_overdues;
478
    my $overdues = $patron->get_overdues;
470
    is( $overdues->count, 2, 'Patron should have 2 overdues');
479
    is( $overdues->count, 2, 'Patron should have 2 overdues');
471
    is( ref($overdues), 'Koha::Checkouts', 'Koha::Patron->get_overdues should return Koha::Checkouts' );
480
    is( ref($overdues), 'Koha::Checkouts', 'Koha::Patron->get_overdues should return Koha::Checkouts' );
472
- 

Return to bug 17584