Bug 17584: Add the Koha::Patron->get_checkouts method
Test plan: prove t/db_dependent/Koha/Patrons.t should return green Signed-off-by: Josef Moravec <josef.moravec@gmail.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
parent
0b9dcc9ac4
commit
6eab0b9424
|
|
@ -501,6 +501,18 @@ sub add_enrolment_fee_if_needed {
|
|||
return $enrolment_fee || 0;
|
||||
}
|
||||
|
||||
=head3 get_checkouts
|
||||
|
||||
my $issues = $patron->get_checkouts
|
||||
|
||||
=cut
|
||||
|
||||
sub get_checkouts {
|
||||
my ($self) = @_;
|
||||
my $issues = $self->_result->issues;
|
||||
return Koha::Checkouts->_new_from_dbic( $issues );
|
||||
}
|
||||
|
||||
=head3 get_overdues
|
||||
|
||||
my $overdue_items = $patron->get_overdues
|
||||
|
|
@ -512,16 +524,14 @@ Return the overdued items
|
|||
sub get_overdues {
|
||||
my ($self) = @_;
|
||||
my $dtf = Koha::Database->new->schema->storage->datetime_parser;
|
||||
my $issues = Koha::Checkouts->search(
|
||||
return $self->get_checkouts->search(
|
||||
{
|
||||
'me.borrowernumber' => $self->borrowernumber,
|
||||
'me.date_due' => { '<' => $dtf->format_datetime(dt_from_string) },
|
||||
},
|
||||
{
|
||||
prefetch => { item => { biblio => 'biblioitems' } },
|
||||
}
|
||||
);
|
||||
return $issues;
|
||||
}
|
||||
|
||||
=head3 get_age
|
||||
|
|
|
|||
|
|
@ -412,8 +412,8 @@ subtest 'add_enrolment_fee_if_needed' => sub {
|
|||
$patron->delete;
|
||||
};
|
||||
|
||||
subtest 'get_overdues' => sub {
|
||||
plan tests => 4;
|
||||
subtest 'get_checkouts + get_overdues' => sub {
|
||||
plan tests => 8;
|
||||
|
||||
my $library = $builder->build( { source => 'Branch' } );
|
||||
my ($biblionumber_1) = AddBiblio( MARC::Record->new, '' );
|
||||
|
|
@ -455,8 +455,13 @@ subtest 'get_overdues' => sub {
|
|||
}
|
||||
);
|
||||
|
||||
$patron = Koha::Patrons->find( $patron->{borrowernumber} );
|
||||
my $checkouts = $patron->get_checkouts;
|
||||
is( $checkouts->count, 0, 'get_checkouts should not return any issues for that patron' );
|
||||
is( ref($checkouts), 'Koha::Checkouts', 'get_checkouts should return a Koha::Checkouts object' );
|
||||
|
||||
# Not sure how this is useful, but AddIssue pass this variable to different other subroutines
|
||||
$patron = GetMember( borrowernumber => $patron->{borrowernumber} );
|
||||
$patron = GetMember( borrowernumber => $patron->borrowernumber );
|
||||
|
||||
my $module = new Test::MockModule('C4::Context');
|
||||
$module->mock( 'userenv', sub { { branch => $library->{branchcode} } } );
|
||||
|
|
@ -466,6 +471,10 @@ subtest 'get_overdues' => sub {
|
|||
AddIssue( $patron, $item_3->{barcode} );
|
||||
|
||||
$patron = Koha::Patrons->find( $patron->{borrowernumber} );
|
||||
$checkouts = $patron->get_checkouts;
|
||||
is( $checkouts->count, 3, 'get_checkouts should return 3 issues for that patron' );
|
||||
is( ref($checkouts), 'Koha::Checkouts', 'get_checkouts should return a Koha::Checkouts object' );
|
||||
|
||||
my $overdues = $patron->get_overdues;
|
||||
is( $overdues->count, 2, 'Patron should have 2 overdues');
|
||||
is( ref($overdues), 'Koha::Checkouts', 'Koha::Patron->get_overdues should return Koha::Checkouts' );
|
||||
|
|
|
|||
Loading…
Reference in New Issue