Bug 19935: Add Koha::Patron->pending_checkouts

To move this subroutine out of the C4 namespace we face the same
problematic as bug 17553 (with GetOverduesForPatron).
We need to provide an equivalent method and so return all the related
value for a given checkout.
We can acchieve the easily using Koha::Object->unblessed_all_relateds,
but we need to keep in mind that it is a temporary move.
Indeed we will want to use our API to only access/retrive values we really need.
The whole trick could be removed when the current syntax for notices
will be deprecated and removed.

Note: this method returns the same number of elements than ->checkouts
They indeed returns the same things, but it sounds better to me to have a
different method to highlight (from the callers) where does it come
from (C4::Members::GetPendingIssues).

Signed-off-by: Benjamin Rokseth <benjamin.rokseth@deichman.no>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2018-01-08 15:49:03 -03:00
parent ac7ea9e10e
commit 98d0c990bf
2 changed files with 42 additions and 2 deletions

View File

@ -523,6 +523,37 @@ sub checkouts {
return Koha::Checkouts->_new_from_dbic( $checkouts );
}
=head3 pending_checkouts
my $pending_checkouts = $patron->pending_checkouts
This method will return the same as $self->checkouts, but with a prefetch on
items, biblio and biblioitems.
It has been introduced to replaced the C4::Members::GetPendingIssues subroutine
It should not be used directly, prefer to access fields you need instead of
retrieving all these fields in one go.
=cut
sub pending_checkouts {
my( $self ) = @_;
my $checkouts = $self->_result->issues->search(
{},
{
order_by => [
{ -desc => 'me.timestamp' },
{ -desc => 'issuedate' },
{ -desc => 'issue_id' }, # Sort by issue_id should be enough
],
prefetch => { item => { biblio => 'biblioitems' } },
}
);
return Koha::Checkouts->_new_from_dbic( $checkouts );
}
=head3 old_checkouts
my $old_checkouts = $patron->old_checkouts

View File

@ -429,8 +429,8 @@ subtest 'add_enrolment_fee_if_needed' => sub {
$patron->delete;
};
subtest 'checkouts + get_overdues + old_checkouts' => sub {
plan tests => 12;
subtest 'checkouts + pending_checkouts + get_overdues + old_checkouts' => sub {
plan tests => 17;
my $library = $builder->build( { source => 'Branch' } );
my ($biblionumber_1) = AddBiblio( MARC::Record->new, '' );
@ -482,6 +482,9 @@ subtest 'checkouts + get_overdues + old_checkouts' => sub {
my $checkouts = $patron->checkouts;
is( $checkouts->count, 0, 'checkouts should not return any issues for that patron' );
is( ref($checkouts), 'Koha::Checkouts', 'checkouts should return a Koha::Checkouts object' );
my $pending_checkouts = $patron->pending_checkouts;
is( $pending_checkouts->count, 0, 'pending_checkouts should not return any issues for that patron' );
is( ref($pending_checkouts), 'Koha::Checkouts', 'pending_checkouts should return a Koha::Checkouts object' );
my $old_checkouts = $patron->old_checkouts;
is( $old_checkouts->count, 0, 'old_checkouts should not return any issues for that patron' );
is( ref($old_checkouts), 'Koha::Old::Checkouts', 'old_checkouts should return a Koha::Old::Checkouts object' );
@ -500,6 +503,12 @@ subtest 'checkouts + get_overdues + old_checkouts' => sub {
$checkouts = $patron->checkouts;
is( $checkouts->count, 3, 'checkouts should return 3 issues for that patron' );
is( ref($checkouts), 'Koha::Checkouts', 'checkouts should return a Koha::Checkouts object' );
$pending_checkouts = $patron->pending_checkouts;
is( $pending_checkouts->count, 3, 'pending_checkouts should return 3 issues for that patron' );
is( ref($pending_checkouts), 'Koha::Checkouts', 'pending_checkouts should return a Koha::Checkouts object' );
my $first_checkout = $pending_checkouts->next;
is( $first_checkout->unblessed_all_relateds->{biblionumber}, $item_3->{biblionumber}, 'pending_checkouts should prefetch values from other tables (here biblio)' );
my $overdues = $patron->get_overdues;
is( $overdues->count, 2, 'Patron should have 2 overdues');