Bug 17736: Replace GetReservesFromBiblionumber with Koha::Biblio->holds
The C4::Reserve::GetReservesFromBiblionumber took 3 parameters, the biblionumber, an optional itemnumber and a "all_dates" flag. If set, the subroutine returned all the holds placed on a given bibliographic record, even the ones placed in the future. Almost all of the calls had this flag set, they will be replaced with a call to Koha::Biblio->holds. But 5 did not have it: - C4::Biblio::DelBiblio -tools/batch_delete_records.pl => These 2 were wrong, we want to retrieve the holds to cancel them before deleting the record. We need to get all the holds, even the ones placed in the future /!\ CHANGE IN THE BEHAVIOR - acqui/parcel.pl => 1 call per item were made to this subroutine. They have been replaced with only 1 call to the new method Koha::Biblios->holds_placed_before_today Then we filter on the itemnumbers. I think this is wrong: we need the number of holds to know if the record can be deleted, so even if future holds exist, the deletion should not be possible. - serials/routing-preview.pl - C4::ILSDI::Services::GetRecords - C4::SIP::ILS::Item->new => Seems ok, we just one to display holds placed before today Test plan: I would suggest to test this patch with patches from bug 17737 and bug 17738, to place different kind of holds (biblio and item level, future and past). Then do a whole workflow to detect bug, view a record, delete record, order, place a hold on an item which has been ordered, etc. The hold's informations should always be the same without or without these patches. Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
parent
42d110a774
commit
87afa5142b
|
|
@ -43,6 +43,7 @@ use Koha::Authority::Types;
|
|||
use Koha::Acquisition::Currencies;
|
||||
use Koha::Biblio::Metadata;
|
||||
use Koha::Biblio::Metadatas;
|
||||
use Koha::Holds;
|
||||
use Koha::SearchEngine;
|
||||
use Koha::Libraries;
|
||||
|
||||
|
|
@ -406,10 +407,11 @@ sub DelBiblio {
|
|||
}
|
||||
|
||||
# We delete any existing holds
|
||||
my $biblio = Koha::Biblios->find( $biblionumber );
|
||||
my $holds = $biblio->holds;
|
||||
require C4::Reserves;
|
||||
my $reserves = C4::Reserves::GetReservesFromBiblionumber({ biblionumber => $biblionumber });
|
||||
foreach my $res ( @$reserves ) {
|
||||
C4::Reserves::CancelReserve({ reserve_id => $res->{'reserve_id'} });
|
||||
while ( my $hold = $holds->next ) {
|
||||
C4::Reserves::CancelReserve({ reserve_id => $hold->reserve_id }); # TODO Replace with $hold->cancel
|
||||
}
|
||||
|
||||
# Delete in Zebra. Be careful NOT to move this line after _koha_delete_biblio
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ use C4::Items;
|
|||
use C4::Circulation;
|
||||
use C4::Accounts;
|
||||
use C4::Biblio;
|
||||
use C4::Reserves qw(AddReserve GetReservesFromBiblionumber GetReservesFromBorrowernumber CanBookBeReserved CanItemBeReserved IsAvailableForItemLevelRequest);
|
||||
use C4::Reserves qw(AddReserve GetReservesFromBorrowernumber CanBookBeReserved CanItemBeReserved IsAvailableForItemLevelRequest);
|
||||
use C4::Context;
|
||||
use C4::AuthoritiesMarc;
|
||||
use XML::Simple;
|
||||
|
|
@ -35,6 +35,7 @@ use DateTime;
|
|||
use C4::Auth;
|
||||
use C4::Members::Attributes qw(GetBorrowerAttributes);
|
||||
|
||||
use Koha::Biblios;
|
||||
use Koha::Libraries;
|
||||
|
||||
=head1 NAME
|
||||
|
|
@ -217,7 +218,8 @@ sub GetRecords {
|
|||
|
||||
# Get most of the needed data
|
||||
my $biblioitemnumber = $biblioitem->{'biblioitemnumber'};
|
||||
my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblionumber });
|
||||
my $biblio = Koha::Biblios->find( $biblionumber );
|
||||
my $holds = $biblio->holds_placed_before_today->unblessed;
|
||||
my $issues = GetBiblioIssues($biblionumber);
|
||||
my $items = GetItemsByBiblioitemnumber($biblioitemnumber);
|
||||
|
||||
|
|
@ -236,7 +238,7 @@ sub GetRecords {
|
|||
|
||||
# Hashref building...
|
||||
$biblioitem->{'items'}->{'item'} = $items;
|
||||
$biblioitem->{'reserves'}->{'reserve'} = $reserves;
|
||||
$biblioitem->{'reserves'}->{'reserve'} = $holds;
|
||||
$biblioitem->{'issues'}->{'issue'} = $issues;
|
||||
|
||||
push @records, $biblioitem;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ use C4::Circulation;
|
|||
use C4::Members;
|
||||
use C4::Reserves;
|
||||
use Koha::Database;
|
||||
use Koha::Biblios;
|
||||
|
||||
|
||||
=encoding UTF-8
|
||||
|
|
@ -65,12 +66,6 @@ use Koha::Database;
|
|||
);
|
||||
=cut
|
||||
|
||||
sub priority_sort {
|
||||
defined $a->{priority} or return -1;
|
||||
defined $b->{priority} or return 1;
|
||||
return $a->{priority} <=> $b->{priority};
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, $item_id) = @_;
|
||||
my $type = ref($class) || $class;
|
||||
|
|
@ -99,8 +94,9 @@ sub new {
|
|||
}
|
||||
my $borrower = GetMember(borrowernumber=>$issue->{'borrowernumber'});
|
||||
$item->{patron} = $borrower->{'cardnumber'};
|
||||
my $reserves = GetReservesFromBiblionumber({ biblionumber => $item->{biblionumber} });
|
||||
$item->{hold_queue} = [ sort priority_sort @$reserves ];
|
||||
my $biblio = Koha::Biblios->find( $item->{biblionumber } );
|
||||
my $holds = $biblio->holds_placed_before_today->unblessed;
|
||||
$item->{hold_queue} = $holds;
|
||||
$item->{hold_shelf} = [( grep { defined $_->{found} and $_->{found} eq 'W' } @{$item->{hold_queue}} )];
|
||||
$item->{pending_queue} = [( grep {(! defined $_->{found}) or $_->{found} ne 'W' } @{$item->{hold_queue}} )];
|
||||
$self = $item;
|
||||
|
|
|
|||
|
|
@ -65,11 +65,11 @@ use C4::Items;
|
|||
use CGI qw ( -utf8 );
|
||||
use C4::Output;
|
||||
use C4::Suggestions;
|
||||
use C4::Reserves qw/GetReservesFromBiblionumber/;
|
||||
|
||||
use Koha::Acquisition::Bookseller;
|
||||
use Koha::Biblios;
|
||||
use Koha::DateUtils;
|
||||
use Koha::Biblios;
|
||||
|
||||
use JSON;
|
||||
|
||||
|
|
@ -140,10 +140,12 @@ for my $order ( @orders ) {
|
|||
$line{invoice} = $invoice->{invoicenumber};
|
||||
$line{holds} = 0;
|
||||
my @itemnumbers = GetItemnumbersFromOrder( $order->{ordernumber} );
|
||||
for my $itemnumber ( @itemnumbers ) {
|
||||
my $holds = GetReservesFromBiblionumber({ biblionumber => $line{biblionumber}, itemnumber => $itemnumber });
|
||||
$line{holds} += scalar( @$holds );
|
||||
}
|
||||
my $biblio = Koha::Biblios->find( $order->{ordernumber} );
|
||||
$line{holds} = $biblio->holds_placed_before_today->search(
|
||||
{
|
||||
itemnumber => { -in => \@itemnumbers },
|
||||
}
|
||||
)->count;
|
||||
$line{budget} = GetBudgetByOrderNumber( $line{ordernumber} );
|
||||
|
||||
$line{tax_value} = $line{tax_value_on_receiving};
|
||||
|
|
|
|||
|
|
@ -168,9 +168,9 @@ $template->param (countorders => $count_orders_using_biblio);
|
|||
my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
|
||||
$template->param (countdeletedorders => $count_deletedorders_using_biblio);
|
||||
|
||||
my $holds = C4::Reserves::GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
|
||||
my $holdcount = scalar( @$holds );
|
||||
$template->param( holdcount => scalar ( @$holds ) );
|
||||
my $biblio = Koha::Biblios->find( $biblionumber );
|
||||
my $holds = $biblio->holds;
|
||||
$template->param( holdcount => $holds->count );
|
||||
|
||||
output_html_with_http_headers $query, $cookie, $template->output;
|
||||
|
||||
|
|
|
|||
|
|
@ -343,8 +343,8 @@ $template->param (countorders => $count_orders_using_biblio);
|
|||
my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
|
||||
$template->param (countdeletedorders => $count_deletedorders_using_biblio);
|
||||
|
||||
my $holds = C4::Reserves::GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
|
||||
my $holdcount = scalar( @$holds );
|
||||
$template->param( holdcount => scalar ( @$holds ) );
|
||||
$biblio = Koha::Biblios->find( $biblionumber );
|
||||
my $holds = $biblio->holds;
|
||||
$template->param( holdcount => $holds->count );
|
||||
|
||||
output_html_with_http_headers $query, $cookie, $template->output;
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ use C4::HTML5Media;
|
|||
use C4::CourseReserves qw(GetItemCourseReservesInfo);
|
||||
use C4::Acquisition qw(GetOrdersByBiblionumber);
|
||||
use Koha::AuthorisedValues;
|
||||
use Koha::Biblios;
|
||||
use Koha::Patrons;
|
||||
use Koha::Virtualshelves;
|
||||
|
||||
|
|
@ -461,8 +462,9 @@ if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->pref
|
|||
}
|
||||
|
||||
#we only need to pass the number of holds to the template
|
||||
my $holds = C4::Reserves::GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
|
||||
$template->param( holdcount => scalar ( @$holds ) );
|
||||
my $biblio = Koha::Biblios->find( $biblionumber );
|
||||
my $holds = $biblio->holds;
|
||||
$template->param( holdcount => $holds->count );
|
||||
|
||||
my $StaffDetailItemSelection = C4::Context->preference('StaffDetailItemSelection');
|
||||
if ($StaffDetailItemSelection) {
|
||||
|
|
|
|||
|
|
@ -110,8 +110,8 @@ $template->param (countorders => $count_orders_using_biblio);
|
|||
my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
|
||||
$template->param (countdeletedorders => $count_deletedorders_using_biblio);
|
||||
|
||||
my $holds= C4::Reserves::GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
|
||||
my $holdcount = scalar( @$holds );
|
||||
$template->param( holdcount => scalar ( @$holds ) );
|
||||
$biblio = Koha::Biblios->find( $biblionumber );
|
||||
my $holds = $biblio->holds;
|
||||
$template->param( holdcount => $holds->count );
|
||||
|
||||
output_html_with_http_headers $query, $cookie, $template->output;
|
||||
|
|
|
|||
|
|
@ -153,8 +153,8 @@ $template->param (countorders => $count_orders_using_biblio);
|
|||
my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
|
||||
$template->param (countdeletedorders => $count_deletedorders_using_biblio);
|
||||
|
||||
my $holds= C4::Reserves::GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
|
||||
my $holdcount = scalar( @$holds );
|
||||
$template->param( holdcount => scalar ( @$holds ) );
|
||||
$biblio = Koha::Biblios->find( $biblionumber );
|
||||
my $holds = $biblio->holds;
|
||||
$template->param( holdcount => $holds->count );
|
||||
|
||||
output_html_with_http_headers $query, $cookie, $template->output;
|
||||
|
|
|
|||
|
|
@ -32,10 +32,10 @@ use C4::Auth;
|
|||
use C4::Serials;
|
||||
use C4::Members; # to use GetMember
|
||||
use C4::Search; # enabled_staff_search_views
|
||||
use C4::Reserves qw(GetReservesFromBiblionumber);
|
||||
|
||||
use Koha::Acquisition::Booksellers;
|
||||
use Koha::AuthorisedValues;
|
||||
use Koha::Biblios;
|
||||
use Koha::DateUtils;
|
||||
use Koha::Items;
|
||||
use Koha::Patrons;
|
||||
|
|
@ -258,9 +258,9 @@ $template->param (countorders => $count_orders_using_biblio);
|
|||
my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
|
||||
$template->param (countdeletedorders => $count_deletedorders_using_biblio);
|
||||
|
||||
my $holds = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
|
||||
my $holdcount = scalar( @$holds );
|
||||
$template->param( holdcount => scalar ( @$holds ) );
|
||||
my $biblio = Koha::Biblios->find( $biblionumber );
|
||||
my $holds = $biblio->holds;
|
||||
$template->param( holdcount => $holds->count );
|
||||
|
||||
output_html_with_http_headers $query, $cookie, $template->output;
|
||||
|
||||
|
|
|
|||
|
|
@ -181,11 +181,11 @@ $(document).ready(function() {
|
|||
<tbody>
|
||||
[% FOR biblio IN records %]
|
||||
<tr>
|
||||
<td><input type="checkbox" name="record_id" id="record_id_[% biblio.biblionumber %]" value="[% biblio.biblionumber %]" data-items="[% biblio.itemnumbers.size %]" data-issues="[% biblio.issues_count %]" data-reserves="[% biblio.reserves.size %]" /></td>
|
||||
<td><input type="checkbox" name="record_id" id="record_id_[% biblio.biblionumber %]" value="[% biblio.biblionumber %]" data-items="[% biblio.itemnumbers.size %]" data-issues="[% biblio.issues_count %]" data-reserves="[% biblio.holds_count %]" /></td>
|
||||
<td><label for="record_id_[% biblio.biblionumber %]">[% biblio.biblionumber %]</label></td>
|
||||
<td>[% INCLUDE 'biblio-default-view.inc' biblionumber=biblio.biblionumber %][% biblio.title %][% IF ( biblio.subtitle ) %][% FOREACH subtitle IN biblio.subtitle %] [% subtitle.subfield |html %][% END %][% END %]</a></td>
|
||||
<td><a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% biblio.biblionumber %]">[% biblio.itemnumbers.size %]</a></td>
|
||||
<td><a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% biblio.biblionumber %]">[% biblio.reserves.size %]</a></td>
|
||||
<td><a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% biblio.biblionumber %]">[% biblio.holds_count %]</a></td>
|
||||
<td><a href="/cgi-bin/koha/catalogue/issuehistory.pl?biblionumber=[% biblio.biblionumber %]">[% biblio.issues_count %]</a></td>
|
||||
</tr>
|
||||
[% END %]
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ use C4::HTML5Media;
|
|||
use C4::CourseReserves qw(GetItemCourseReservesInfo);
|
||||
use Koha::RecordProcessor;
|
||||
use Koha::AuthorisedValues;
|
||||
use Koha::Biblios;
|
||||
use Koha::Virtualshelves;
|
||||
use Koha::Ratings;
|
||||
use Koha::Reviews;
|
||||
|
|
@ -591,15 +592,16 @@ for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
|
|||
}
|
||||
my $has_hold;
|
||||
if ( $show_holds_count || $show_priority) {
|
||||
my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
|
||||
$template->param( holds_count => scalar( @$reserves ) ) if $show_holds_count;
|
||||
foreach (@$reserves) {
|
||||
$item_reserves{ $_->{itemnumber} }++ if $_->{itemnumber};
|
||||
if ($show_priority && $_->{borrowernumber} == $borrowernumber) {
|
||||
my $biblio = Koha::Biblios->find( $biblionumber );
|
||||
my $holds = $biblio->holds;
|
||||
$template->param( holds_count => $holds->count );
|
||||
while ( my $hold = $holds->new ) {
|
||||
$item_reserves{ $hold->itemnumber }++ if $hold->itemnumber;
|
||||
if ($show_priority && $hold->borrowernumber == $borrowernumber) {
|
||||
$has_hold = 1;
|
||||
$_->{itemnumber}
|
||||
? ($priority{ $_->{itemnumber} } = $_->{priority})
|
||||
: ($template->param( priority => $_->{priority} ));
|
||||
$hold->itemnumber
|
||||
? ($priority{ $hold->itemnumber } = $hold->priority)
|
||||
: ($template->param( priority => $hold->priority ));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -172,12 +172,12 @@ foreach my $biblioNumber (@biblionumbers) {
|
|||
}
|
||||
|
||||
# Compute the priority rank.
|
||||
my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblioNumber, all_dates => 1 });
|
||||
my $rank = scalar( @$reserves );
|
||||
my $biblio = Koha::Biblios->find( $biblioNumber );
|
||||
my $holds = $biblio->holds;
|
||||
my $rank = $holds->count;
|
||||
$biblioData->{reservecount} = 1; # new reserve
|
||||
foreach my $res (@{$reserves}) {
|
||||
my $found = $res->{found};
|
||||
if ( $found && $found eq 'W' ) {
|
||||
while ( my $hold = $holds->next ) {
|
||||
if ( $hold->is_waiting ) {
|
||||
$rank--;
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ use C4::Biblio;
|
|||
use C4::Items;
|
||||
use C4::Serials;
|
||||
use URI::Escape;
|
||||
|
||||
use Koha::Biblios;
|
||||
use Koha::Libraries;
|
||||
|
||||
my $query = new CGI;
|
||||
|
|
@ -62,38 +64,37 @@ my ($template, $loggedinuser, $cookie);
|
|||
|
||||
if($ok){
|
||||
# get biblio information....
|
||||
my $biblio = $subs->{'biblionumber'};
|
||||
my ($count2,@bibitems) = GetBiblioItemByBiblioNumber($biblio);
|
||||
my $biblionumber = $subs->{'biblionumber'};
|
||||
my ($count2,@bibitems) = GetBiblioItemByBiblioNumber($biblionumber);
|
||||
my @itemresults = GetItemsInfo( $subs->{biblionumber} );
|
||||
my $branch = $itemresults[0]->{'holdingbranch'};
|
||||
my $branchname = Koha::Libraries->find($branch)->branchname;
|
||||
|
||||
if (C4::Context->preference('RoutingListAddReserves')){
|
||||
# get existing reserves .....
|
||||
my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblio });
|
||||
my $count = scalar( @$reserves );
|
||||
my $totalcount = $count;
|
||||
foreach my $res (@$reserves) {
|
||||
if ($res->{'found'} eq 'W') {
|
||||
$count--;
|
||||
}
|
||||
}
|
||||
|
||||
my $biblio = Koha::Biblios->find( $biblionumber );
|
||||
my $holds = $biblio->holds_placed_before_today;
|
||||
my $count = $holds->count;
|
||||
while ( my $hold = $holds->next ) {
|
||||
$count-- if $hold->is_waiting;
|
||||
}
|
||||
my $notes;
|
||||
my $title = $subs->{'bibliotitle'};
|
||||
for my $routing ( @routinglist ) {
|
||||
my $sth = $dbh->prepare('SELECT * FROM reserves WHERE biblionumber = ? AND borrowernumber = ? LIMIT 1');
|
||||
$sth->execute($biblio,$routing->{borrowernumber});
|
||||
$sth->execute($biblionumber,$routing->{borrowernumber});
|
||||
my $reserve = $sth->fetchrow_hashref;
|
||||
|
||||
if($routing->{borrowernumber} == $reserve->{borrowernumber}){
|
||||
ModReserve({
|
||||
rank => $routing->{ranking},
|
||||
biblionumber => $biblio,
|
||||
biblionumber => $biblionumber,
|
||||
borrowernumber => $routing->{borrowernumber},
|
||||
branchcode => $branch
|
||||
});
|
||||
} else {
|
||||
AddReserve($branch,$routing->{borrowernumber},$biblio,\@bibitems,$routing->{ranking}, undef, undef, $notes,$title);
|
||||
AddReserve($branch,$routing->{borrowernumber},$biblionumber,\@bibitems,$routing->{ranking}, undef, undef, $notes,$title);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use C4::Members;
|
|||
use C4::Calendar;
|
||||
use Koha::Database;
|
||||
use Koha::DateUtils qw( dt_from_string output_pref );
|
||||
use Koha::Biblios;
|
||||
use Koha::Holds;
|
||||
|
||||
BEGIN {
|
||||
|
|
@ -84,14 +85,14 @@ foreach my $borrowernumber ( @borrowernumbers ) {
|
|||
);
|
||||
}
|
||||
|
||||
my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblionumber });
|
||||
is( scalar(@$reserves), $borrowers_count, "Test GetReserves()" );
|
||||
|
||||
is( $reserves->[0]->{priority}, 1, "Reserve 1 has a priority of 1" );
|
||||
is( $reserves->[1]->{priority}, 2, "Reserve 2 has a priority of 2" );
|
||||
is( $reserves->[2]->{priority}, 3, "Reserve 3 has a priority of 3" );
|
||||
is( $reserves->[3]->{priority}, 4, "Reserve 4 has a priority of 4" );
|
||||
is( $reserves->[4]->{priority}, 5, "Reserve 5 has a priority of 5" );
|
||||
my $biblio = Koha::Biblios->find( $biblionumber );
|
||||
my $holds = $biblio->holds;
|
||||
is( $holds->count, $borrowers_count, 'Test GetReserves()' );
|
||||
is( $holds->next->priority, 1, "Reserve 1 has a priority of 1" );
|
||||
is( $holds->next->priority, 2, "Reserve 2 has a priority of 2" );
|
||||
is( $holds->next->priority, 3, "Reserve 3 has a priority of 3" );
|
||||
is( $holds->next->priority, 4, "Reserve 4 has a priority of 4" );
|
||||
is( $holds->next->priority, 5, "Reserve 5 has a priority of 5" );
|
||||
|
||||
my ( $reservedate, $borrowernumber, $branch_1code, $reserve_id ) = GetReservesFromItemnumber($itemnumber);
|
||||
is( $reservedate, output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }), "GetReservesFromItemnumber should return a valid reserve date");
|
||||
|
|
@ -122,8 +123,8 @@ ok( GetReserveCount( $borrowernumbers[0] ), "Test GetReserveCount()" );
|
|||
|
||||
|
||||
CancelReserve({ 'reserve_id' => $reserve_id });
|
||||
$reserves = GetReservesFromBiblionumber({ biblionumber => $biblionumber });
|
||||
is( scalar(@$reserves), $borrowers_count - 1, "Test CancelReserve()" );
|
||||
$holds = $biblio->holds;
|
||||
is( $holds->count, $borrowers_count - 1, "Test CancelReserve()" );
|
||||
|
||||
|
||||
( $reservedate, $borrowernumber, $branch_1code, $reserve_id ) = GetReservesFromItemnumber($itemnumber);
|
||||
|
|
@ -202,9 +203,9 @@ my $reserve2 = GetReserveInfo( $reserve->{'reserve_id'} );
|
|||
ok( $reserve->{'reserve_id'} eq $reserve2->{'reserve_id'}, "Test GetReserveInfo()" );
|
||||
|
||||
|
||||
$reserves = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
|
||||
$reserve = $reserves->[1];
|
||||
AlterPriority( 'top', $reserve->{'reserve_id'} );
|
||||
$holds = $biblio->holds;
|
||||
my $hold = $holds->next;
|
||||
AlterPriority( 'top', $hold->reserve_id );
|
||||
$reserve = GetReserve( $reserve->{'reserve_id'} );
|
||||
is( $reserve->{'priority'}, '1', "Test AlterPriority(), move to top" );
|
||||
|
||||
|
|
@ -429,7 +430,7 @@ t::lib::Mocks::mock_preference('ReservesMaxPickUpDelay', 1);
|
|||
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime(time);
|
||||
$year += 1900;
|
||||
$mon += 1;
|
||||
$reserves = $dbh->selectall_arrayref('SELECT * FROM reserves', { Slice => {} });
|
||||
my $reserves = $dbh->selectall_arrayref('SELECT * FROM reserves', { Slice => {} });
|
||||
$reserve = $reserves->[0];
|
||||
my $calendar = C4::Calendar->new(branchcode => $reserve->{branchcode});
|
||||
$calendar->insert_single_holiday(
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
use Modern::Perl;
|
||||
|
||||
use Test::More tests => 72;
|
||||
use Test::More tests => 71;
|
||||
use Test::MockModule;
|
||||
use Test::Warn;
|
||||
|
||||
|
|
@ -268,14 +268,13 @@ AddReserve($branch_1, $requesters{$branch_1}, $bibnum2,
|
|||
ModReserveAffect($itemnum_cpl, $requesters{$branch_3}, 0);
|
||||
|
||||
# Now it should have different priorities.
|
||||
my $title_reserves = GetReservesFromBiblionumber({biblionumber => $bibnum2});
|
||||
# Sort by reserve number in case the database gives us oddly ordered results
|
||||
my @reserves = sort { $a->{reserve_id} <=> $b->{reserve_id} } @$title_reserves;
|
||||
is($reserves[0]{priority}, 0, 'Item is correctly waiting');
|
||||
is($reserves[1]{priority}, 1, 'Item is correctly priority 1');
|
||||
is($reserves[2]{priority}, 2, 'Item is correctly priority 2');
|
||||
my $biblio = Koha::Biblios->find( $bibnum2 );
|
||||
my $holds = $biblio->holds({}, { order_by => 'reserve_id' });;
|
||||
is($holds->next->priority, 0, 'Item is correctly waiting');
|
||||
is($holds->next->priority, 1, 'Item is correctly priority 1');
|
||||
is($holds->next->priority, 2, 'Item is correctly priority 2');
|
||||
|
||||
@reserves = Koha::Holds->search({ borrowernumber => $requesters{$branch_3} })->waiting();
|
||||
my @reserves = Koha::Holds->search({ borrowernumber => $requesters{$branch_3} })->waiting();
|
||||
is( @reserves, 1, 'GetWaiting got only the waiting reserve' );
|
||||
is( $reserves[0]->borrowernumber(), $requesters{$branch_3}, 'GetWaiting got the reserve for the correct borrower' );
|
||||
|
||||
|
|
@ -315,10 +314,10 @@ is( $messages->{ResFound}->{borrowernumber},
|
|||
$requesters{$branch_3},
|
||||
'for generous library, its items fill first hold request in line (bug 10272)');
|
||||
|
||||
my $reserves = GetReservesFromBiblionumber({biblionumber => $biblionumber});
|
||||
isa_ok($reserves, 'ARRAY');
|
||||
is(scalar @$reserves, 1, "Only one reserves for this biblio");
|
||||
my $reserve_id = $reserves->[0]->{reserve_id};
|
||||
$biblio = Koha::Biblios->find( $biblionumber );
|
||||
$holds = $biblio->holds;
|
||||
is($holds->count, 1, "Only one reserves for this biblio");
|
||||
my $reserve_id = $holds->next->reserve_id;
|
||||
|
||||
$reserve = GetReserve($reserve_id);
|
||||
isa_ok($reserve, 'HASH', "GetReserve return");
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ use Test::More tests => 57;
|
|||
use t::lib::Mocks qw(mock_preference);
|
||||
use POSIX qw(strftime);
|
||||
use Data::Dumper;
|
||||
use Koha::Biblios;
|
||||
|
||||
use Koha::Libraries;
|
||||
|
||||
|
|
@ -299,9 +300,9 @@ sub construct_objects_needed {
|
|||
|
||||
# ---------- Add 1 old_reserves
|
||||
AddReserve( $branchcode, $borrowernumber1, $biblionumber1, '', 1, undef, undef, '', 'Title', undef, undef );
|
||||
my $reserves1 = GetReservesFromBiblionumber( { biblionumber => $biblionumber1 } );
|
||||
my $reserve_id1 = $reserves1->[0]->{reserve_id};
|
||||
my $reserve1 = CancelReserve( { reserve_id => $reserve_id1 } );
|
||||
my $biblio = Koha::Biblios->find( $biblionumber1 );
|
||||
my $holds = $biblio->holds;
|
||||
CancelReserve( { reserve_id => $holds->next->reserve_id } );
|
||||
|
||||
# ---------- Add 1 aqbudgets
|
||||
$query = '
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ use C4::Output;
|
|||
use C4::AuthoritiesMarc;
|
||||
use C4::Biblio;
|
||||
|
||||
use Koha::Biblios;
|
||||
|
||||
my $input = new CGI;
|
||||
my $dbh = C4::Context->dbh;
|
||||
my $op = $input->param('op') // q|form|;
|
||||
|
|
@ -68,7 +70,7 @@ if ( $op eq 'form' ) {
|
|||
for my $record_id ( uniq @record_ids ) {
|
||||
if ( $recordtype eq 'biblio' ) {
|
||||
# Retrieve biblio information
|
||||
my $biblio = C4::Biblio::GetBiblio( $record_id );
|
||||
my $biblio = Koha::Biblios->find( $record_id );
|
||||
unless ( $biblio ) {
|
||||
push @messages, {
|
||||
type => 'warning',
|
||||
|
|
@ -77,10 +79,12 @@ if ( $op eq 'form' ) {
|
|||
};
|
||||
next;
|
||||
}
|
||||
my $holds_count = $biblio->holds->count;
|
||||
$biblio = $biblio->unblessed;
|
||||
my $record = &GetMarcBiblio( $record_id );
|
||||
$biblio->{subtitle} = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $record_id ) );
|
||||
$biblio->{itemnumbers} = C4::Items::GetItemnumbersForBiblio( $record_id );
|
||||
$biblio->{reserves} = C4::Reserves::GetReservesFromBiblionumber({ biblionumber => $record_id });
|
||||
$biblio->{holds_count} = $holds_count;
|
||||
$biblio->{issues_count} = C4::Biblio::CountItemsIssued( $record_id );
|
||||
push @records, $biblio;
|
||||
} else {
|
||||
|
|
@ -127,6 +131,9 @@ if ( $op eq 'form' ) {
|
|||
my $biblionumber = $record_id;
|
||||
# First, checking if issues exist.
|
||||
# If yes, nothing to do
|
||||
my $biblio = Koha::Biblios->find( $biblionumber );
|
||||
|
||||
# TODO Replace with $biblio->get_issues->count
|
||||
if ( C4::Biblio::CountItemsIssued( $biblionumber ) ) {
|
||||
push @messages, {
|
||||
type => 'warning',
|
||||
|
|
@ -138,17 +145,17 @@ if ( $op eq 'form' ) {
|
|||
}
|
||||
|
||||
# Cancel reserves
|
||||
my $reserves = C4::Reserves::GetReservesFromBiblionumber({ biblionumber => $biblionumber });
|
||||
for my $reserve ( @$reserves ) {
|
||||
my $holds = $biblio->holds;
|
||||
while ( my $hold = $holds->next ) {
|
||||
eval{
|
||||
C4::Reserves::CancelReserve( { reserve_id => $reserve->{reserve_id} } );
|
||||
C4::Reserves::CancelReserve( { reserve_id => $hold->reserve_id } );
|
||||
};
|
||||
if ( $@ ) {
|
||||
push @messages, {
|
||||
type => 'error',
|
||||
code => 'reserve_not_cancelled',
|
||||
biblionumber => $biblionumber,
|
||||
reserve_id => $reserve->{reserve_id},
|
||||
reserve_id => $hold->reserve_id,
|
||||
error => $@,
|
||||
};
|
||||
$dbh->rollback;
|
||||
|
|
|
|||
Loading…
Reference in New Issue