From c7b929c6f876f0f93dec8cf2dc3dc0595f0551c7 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Tue, 15 Feb 2022 07:55:36 +1300 Subject: [PATCH] Bug 19532: (follow-up) Fixes along recall workflow --- C4/Circulation.pm | 2 +- C4/Reserves.pm | 2 +- Koha/Biblio.pm | 17 ++++++++++------- Koha/Item.pm | 6 +++--- Koha/Recall.pm | 2 +- circ/returns.pl | 4 ++-- .../bootstrap/en/includes/title-actions-menu.inc | 2 +- koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt | 8 +------- misc/cronjobs/recalls/expire_recalls.pl | 2 +- misc/cronjobs/recalls/overdue_recalls.pl | 2 +- opac/opac-recall.pl | 4 ++-- 11 files changed, 24 insertions(+), 27 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 462b95e663..06e3f2c1f2 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1125,7 +1125,7 @@ sub CanBookBeIssued { # Only bother doing this if UseRecalls is enabled and the item is recallable # Don't look at recalls that are in transit if ( C4::Context->preference('UseRecalls') and $item_object->can_be_waiting_recall ) { - my @recalls = $biblio->recalls; + my @recalls = $biblio->recalls->as_list; foreach my $r ( @recalls ) { if ( $r->itemnumber and diff --git a/C4/Reserves.pm b/C4/Reserves.pm index cb6381ca2b..93d834df24 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -413,7 +413,7 @@ sub CanItemBeReserved { # check if a recall exists on this item from this borrower return { status => 'recall' } - if Koha::Recalls->search({ borrowernumber => $borrowernumber, itemnumber => $itemnumber, old => undef })->count; + if Koha::Recalls->search({ borrowernumber => $patron->borrowernumber, itemnumber => $item->itemnumber, old => undef })->count; my $controlbranch = C4::Context->preference('ReservesControlBranch'); diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 32d14cae1f..6a9e177c39 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -1172,12 +1172,15 @@ Return all active recalls attached to this biblio, sorted by oldest first sub recalls { my ( $self, $params ) = @_; - if ( $params->{borrowernumber} ) { - my @recalls_rs = Koha::Recalls->search({ biblionumber => $self->biblionumber, old => undef, borrowernumber => $params->{borrowernumber} }, { order_by => { -asc => 'recalldate' } }); - return @recalls_rs; - } - my @recalls_rs = Koha::Recalls->search({ biblionumber => $self->biblionumber, old => undef }, { order_by => { -asc => 'recalldate' } }); - return @recalls_rs; + + my $args = { + biblionumber => $self->biblionumber, + old => undef, + }; + $args->{ borrowernumber } = $params->{ borrowernumber } if $params->{ borrowernumber }; + + my $recalls_rs = $self->_result->recalls->search( $args, { order_by => { -asc => 'recalldate' } }); + return Koha::Recalls->_new_from_dbic( $recalls_rs ); } =head3 can_be_recalled @@ -1200,7 +1203,7 @@ sub can_be_recalled { $branchcode = $patron->branchcode; } - my @all_items = Koha::Items->search({ biblionumber => $self->biblionumber }); + my @all_items = Koha::Items->search({ biblionumber => $self->biblionumber })->as_list; # if there are no available items at all, no recall can be placed return 0 if ( scalar @all_items == 0 ); diff --git a/Koha/Item.pm b/Koha/Item.pm index f079b11f6e..8cdc3d0408 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -1444,7 +1444,7 @@ Return the relevant recall for this item sub recall { my ( $self ) = @_; - my @recalls = Koha::Recalls->search({ biblionumber => $self->biblionumber, old => undef }, { order_by => { -asc => 'recalldate' } }); + my @recalls = Koha::Recalls->search({ biblionumber => $self->biblionumber, old => undef }, { order_by => { -asc => 'recalldate' } })->as_list; foreach my $recall (@recalls) { if ( $recall->item_level_recall and $recall->itemnumber == $self->itemnumber ){ return $recall; @@ -1517,7 +1517,7 @@ sub can_be_recalled { # check item availability # items are unavailable for recall if they are lost, withdrawn or notforloan - my @items = Koha::Items->search({ biblionumber => $self->biblionumber, itemlost => 0, withdrawn => 0, notforloan => 0 }); + my @items = Koha::Items->search({ biblionumber => $self->biblionumber, itemlost => 0, withdrawn => 0, notforloan => 0 })->as_list; # if there are no available items at all, no recall can be placed return 0 if ( scalar @items == 0 ); @@ -1591,7 +1591,7 @@ Get the most relevant recall for this item. sub check_recalls { my ( $self ) = @_; - my @recalls = Koha::Recalls->search({ biblionumber => $self->biblionumber, itemnumber => [ $self->itemnumber, undef ], status => [ 'R','O','W','T' ] }, { order_by => { -asc => 'recalldate' } }); + my @recalls = Koha::Recalls->search({ biblionumber => $self->biblionumber, itemnumber => [ $self->itemnumber, undef ], status => [ 'R','O','W','T' ] }, { order_by => { -asc => 'recalldate' } })->as_list; my $recall; # iterate through relevant recalls to find the best one. diff --git a/Koha/Recall.pm b/Koha/Recall.pm index 03c6167683..0ea8c1c36d 100644 --- a/Koha/Recall.pm +++ b/Koha/Recall.pm @@ -110,7 +110,7 @@ sub checkout { unless ( $self->item_level_recall ) { # Only look at checkouts of items that are allowed to be recalled, and get the oldest one - my @items = Koha::Items->search({ biblionumber => $self->biblionumber }); + my @items = Koha::Items->search({ biblionumber => $self->biblionumber })->as_list; my @itemnumbers; foreach (@items) { my $recalls_allowed = Koha::CirculationRules->get_effective_rule({ diff --git a/circ/returns.pl b/circ/returns.pl index 8042250a38..8d93da4525 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -178,7 +178,6 @@ if ( $query->param('recall_id') ) { my $itemnumber = $query->param('itemnumber'); my $return_branch = $query->param('returnbranch'); - my $expirationdate = $recall->calc_expirationdate; my $item; if ( !$recall->item_level_recall ) { $item = Koha::Items->find( $itemnumber ); @@ -187,7 +186,8 @@ if ( $query->param('recall_id') ) { if ( $recall->branchcode ne $return_branch ) { $recall->start_transfer({ item => $item }) if !$recall->in_transit; } else { - $recall->set_waiting({ item => $item }) if !$recall->waiting; + my $expirationdate = $recall->calc_expirationdate; + $recall->set_waiting({ item => $item, expirationdate => $expirationdate }) if !$recall->waiting; } } diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/title-actions-menu.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/title-actions-menu.inc index 7470ab831d..9f1fb2015e 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/title-actions-menu.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/title-actions-menu.inc @@ -18,7 +18,7 @@ [% END # / OPACHoldRequests %] [% IF Koha.Preference('UseRecalls') %] - Place recall + Place recall [% END %] [% IF ( Koha.Preference( 'opacuserlogin' ) == 1 ) %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt index 105d238fc2..7a923572e1 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt @@ -767,13 +767,7 @@ [% FOREACH RECALL IN RECALLS %] - - [% RECALL.biblio.title | html %] - [% FOREACH s IN RECALL.biblio.subtitle %] - [% s | html %] - [% END %] - - [% RECALL.biblio.author | html %] + [% INCLUDE 'biblio-title.inc' biblio=RECALL.biblio %] [% IF RECALL.item_level_recall %]

Item recalled: [% RECALL.item.barcode | html %]

[% END %] diff --git a/misc/cronjobs/recalls/expire_recalls.pl b/misc/cronjobs/recalls/expire_recalls.pl index 38408e66da..4e4ee006eb 100755 --- a/misc/cronjobs/recalls/expire_recalls.pl +++ b/misc/cronjobs/recalls/expire_recalls.pl @@ -37,7 +37,7 @@ use C4::Log; cronlogaction(); -my @recalls = Koha::Recalls->search({ old => undef }); +my @recalls = Koha::Recalls->search({ old => undef })->as_list; foreach my $recall (@recalls) { if ( ( $recall->requested or $recall->overdue ) and $recall->expirationdate and dt_from_string( $recall->expirationdate ) < dt_from_string() ){ # recall is requested or overdue and has surpassed the specified expiration date diff --git a/misc/cronjobs/recalls/overdue_recalls.pl b/misc/cronjobs/recalls/overdue_recalls.pl index 70f0ea9596..4910335536 100755 --- a/misc/cronjobs/recalls/overdue_recalls.pl +++ b/misc/cronjobs/recalls/overdue_recalls.pl @@ -36,7 +36,7 @@ use C4::Log; cronlogaction(); -my @recalls = Koha::Recalls->search({ status => 'R' }); +my @recalls = Koha::Recalls->search({ status => 'R' })->as_list; foreach my $recall (@recalls){ if ( $recall->should_be_overdue ){ $recall->set_overdue({ interface => 'COMMANDLINE' }); diff --git a/opac/opac-recall.pl b/opac/opac-recall.pl index 9a01607f46..0e071dea78 100755 --- a/opac/opac-recall.pl +++ b/opac/opac-recall.pl @@ -43,10 +43,10 @@ if ( C4::Context->preference('UseRecalls') ) { unless ( $biblio->can_be_recalled({ patron => $patron }) ) { $error = 'unavailable'; } - my $items = Koha::Items->search({ biblionumber => $biblionumber }); + my $items = Koha::Items->search({ biblionumber => $biblionumber })->as_list; # check if already recalled - my $recalled = scalar $biblio->recalls({ borrowernumber => $borrowernumber }); + my $recalled = $biblio->recalls({ borrowernumber => $borrowernumber })->count; if ( defined $recalled and $recalled > 0 ) { my $recalls_per_record = Koha::CirculationRules->get_effective_rule({ categorycode => $patron->categorycode, -- 2.11.0