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

(-)a/Koha/Patron.pm (-3 / +13 lines)
Lines 496-501 sub add_enrolment_fee_if_needed { Link Here
496
    return $enrolment_fee || 0;
496
    return $enrolment_fee || 0;
497
}
497
}
498
498
499
=head3 get_issues
500
501
my $issues = $patron->get_issues
502
503
=cut
504
505
sub get_issues {
506
    my ($self) = @_;
507
    my $issues = $self->_result->issues;
508
    return Koha::Issues->_new_from_dbic( $issues );
509
}
510
499
=head3 get_overdues
511
=head3 get_overdues
500
512
501
my $overdue_items = $patron->get_overdues
513
my $overdue_items = $patron->get_overdues
Lines 507-522 Return the overdued items Link Here
507
sub get_overdues {
519
sub get_overdues {
508
    my ($self) = @_;
520
    my ($self) = @_;
509
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
521
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
510
    my $issues = Koha::Issues->search(
522
    return $self->get_issues->search(
511
        {
523
        {
512
            'me.borrowernumber' => $self->borrowernumber,
513
            'me.date_due' => { '<' => $dtf->format_datetime(dt_from_string) },
524
            'me.date_due' => { '<' => $dtf->format_datetime(dt_from_string) },
514
        },
525
        },
515
        {
526
        {
516
            prefetch => { item => { biblio => 'biblioitems' } },
527
            prefetch => { item => { biblio => 'biblioitems' } },
517
        }
528
        }
518
    );
529
    );
519
    return $issues;
520
}
530
}
521
531
522
=head3 type
532
=head3 type
(-)a/t/db_dependent/Koha/Patrons.t (-5 / +13 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 14;
22
use Test::More tests => 15;
23
use Test::Warn;
23
use Test::Warn;
24
use DateTime;
24
use DateTime;
25
25
Lines 406-413 subtest 'add_enrolment_fee_if_needed' => sub { Link Here
406
    $patron->delete;
406
    $patron->delete;
407
};
407
};
408
408
409
subtest 'get_overdues' => sub {
409
subtest 'get_issues + get_overdues' => sub {
410
    plan tests => 4;
410
    plan tests => 8;
411
411
412
    my $library = $builder->build( { source => 'Branch' } );
412
    my $library = $builder->build( { source => 'Branch' } );
413
    my ($biblionumber_1) = AddBiblio( MARC::Record->new, '' );
413
    my ($biblionumber_1) = AddBiblio( MARC::Record->new, '' );
Lines 449-456 subtest 'get_overdues' => sub { Link Here
449
        }
449
        }
450
    );
450
    );
451
451
452
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
453
    my $issues = $patron->get_issues;
454
    is( $issues->count, 0, 'get_issues should not return any issues for that patron' );
455
    is( ref($issues), 'Koha::Issues', 'get_issues should return a Koha::Issues object' );
456
452
    # Not sure how this is useful, but AddIssue pass this variable to different other subroutines
457
    # Not sure how this is useful, but AddIssue pass this variable to different other subroutines
453
    $patron = GetMember( borrowernumber => $patron->{borrowernumber} );
458
    $patron = GetMember( borrowernumber => $patron->borrowernumber );
454
459
455
    my $module = new Test::MockModule('C4::Context');
460
    my $module = new Test::MockModule('C4::Context');
456
    $module->mock( 'userenv', sub { { branch => $library->{branchcode} } } );
461
    $module->mock( 'userenv', sub { { branch => $library->{branchcode} } } );
Lines 460-465 subtest 'get_overdues' => sub { Link Here
460
    AddIssue( $patron, $item_3->{barcode} );
465
    AddIssue( $patron, $item_3->{barcode} );
461
466
462
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
467
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
468
    $issues = $patron->get_issues;
469
    is( $issues->count, 3, 'get_issues should return 3 issues for that patron' );
470
    is( ref($issues), 'Koha::Issues', 'get_issues should return a Koha::Issues object' );
471
463
    my $overdues = $patron->get_overdues;
472
    my $overdues = $patron->get_overdues;
464
    is( $overdues->count, 2, 'Patron should have 2 overdues');
473
    is( $overdues->count, 2, 'Patron should have 2 overdues');
465
    is( ref($overdues), 'Koha::Issues', 'Koha::Patron->get_overdues should return Koha::Issues' );
474
    is( ref($overdues), 'Koha::Issues', 'Koha::Patron->get_overdues should return Koha::Issues' );
466
- 

Return to bug 17584