From 0e17926b61d462adb09f711a06e07c384ebe946c Mon Sep 17 00:00:00 2001 From: Nahuel ANGELINETTI Date: Thu, 1 Oct 2009 10:26:43 +0200 Subject: [PATCH] [replaceprevious](bug #3678) Fix circulation This patch fix major circulation problems with reserves: A reserved document on "next available", is no more detected when an item of this record is checked-in. And add a db dependant test to validate this everywhen. Signed-off-by: Henri-Damien LAURENT --- C4/Circulation.pm | 13 ++++---- C4/Reserves.pm | 34 ++++++++++++++++++--- t/db_dependent/Reserves.t | 62 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 10 deletions(-) create mode 100755 t/db_dependent/Reserves.t diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 81cc08ba0a..9f86058082 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1312,10 +1312,11 @@ sub AddReturn { $branch ||=C4::Context->userenv->{'branch'}; # get information on item - my $iteminformation = GetItemIssue( GetItemnumberFromBarcode($barcode)); + my $itemnumber = GetItemnumberFromBarcode($barcode); + my $iteminformation = GetItemIssue( $itemnumber ); my $biblio = GetBiblioItemData($iteminformation->{'biblioitemnumber'}); # use Data::Dumper;warn Data::Dumper::Dumper($iteminformation); - unless ($iteminformation->{'itemnumber'} ) { + unless ( $iteminformation->{'itemnumber'} or $itemnumber) { $messages->{'BadBarcode'} = $barcode; $doreturn = 0; } else { @@ -1327,7 +1328,7 @@ sub AddReturn { # even though item is not on loan, it may still # be transferred; therefore, get current branch information - my $curr_iteminfo = GetItem($iteminformation->{'itemnumber'}); + my $curr_iteminfo = GetItem($itemnumber); $iteminformation->{'homebranch'} = $curr_iteminfo->{'homebranch'}; $iteminformation->{'holdingbranch'} = $curr_iteminfo->{'holdingbranch'}; $iteminformation->{'itemlost'} = $curr_iteminfo->{'itemlost'}; @@ -1341,7 +1342,7 @@ sub AddReturn { } # if independent branches are on and returning to different branch, refuse the return - if ($hbr ne $branch && C4::Context->preference("IndependantBranches")){ + if ($hbr ne $branch && C4::Context->preference("IndependantBranches") && $iteminformation->{borrowernumber}){ $messages->{'Wrongbranch'} = 1; $doreturn=0; } @@ -1420,8 +1421,8 @@ sub AddReturn { # find reserves..... # if we don't have a reserve with the status W, we launch the Checkreserves routine - my ( $resfound, $resrec ) = - C4::Reserves::CheckReserves( $iteminformation->{'itemnumber'} ); + my ( $resfound, $resrec ) = + C4::Reserves::CheckReserves( $itemnumber, $barcode ); if ($resfound) { $resrec->{'ResFound'} = $resfound; $messages->{'ResFound'} = $resrec; diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 394246f164..1596ed015f 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1314,17 +1314,43 @@ sub _Findgroupreserve { reserves.itemnumber AS itemnumber FROM reserves JOIN biblioitems USING (biblionumber) - JOIN hold_fill_targets USING (biblionumber, borrowernumber) + JOIN hold_fill_targets USING (biblionumber, borrowernumber, itemnumber) WHERE found IS NULL AND priority > 0 - AND holds_fill_targets.itemnumber = ? + AND hold_fill_targets.itemnumber = ? /; my $sth = $dbh->prepare($item_level_target_query); $sth->execute($itemnumber); my $data = $sth->fetchall_arrayref({}); - return @$data if ($data); + return @$data if (@$data); + # check for title-level targetted match + my $title_level_target_query = qq/ + SELECT reserves.biblionumber AS biblionumber, + reserves.borrowernumber AS borrowernumber, + reserves.reservedate AS reservedate, + reserves.branchcode AS branchcode, + reserves.cancellationdate AS cancellationdate, + reserves.found AS found, + reserves.reservenotes AS reservenotes, + reserves.priority AS priority, + reserves.timestamp AS timestamp, + biblioitems.biblioitemnumber AS biblioitemnumber, + reserves.itemnumber AS itemnumber + FROM reserves + JOIN biblioitems USING (biblionumber) + JOIN hold_fill_targets USING (biblionumber, borrowernumber) + WHERE found IS NULL + AND priority > 0 + AND item_level_request = 0 + AND hold_fill_targets.itemnumber = ? + /; + $sth = $dbh->prepare($title_level_target_query); + $sth->execute($itemnumber); + $data = $sth->fetchall_arrayref({}); + return @$data if (@$data); + my $query = qq/ SELECT reserves.biblionumber AS biblionumber, reserves.borrowernumber AS borrowernumber, @@ -1349,7 +1375,7 @@ sub _Findgroupreserve { $sth = $dbh->prepare($query); $sth->execute( $biblio, $bibitem, $itemnumber ); $data = $sth->fetchall_arrayref({}); - return @$data if ($data); + return @$data if (@$data); return undef; } diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t new file mode 100755 index 0000000000..177febb58a --- /dev/null +++ b/t/db_dependent/Reserves.t @@ -0,0 +1,62 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use C4::Branch; + +use Test::More tests => 4; + +BEGIN { + use FindBin; + use lib $FindBin::Bin; + use_ok('C4::Reserves'); +} + +my $dbh = C4::Context->dbh; +my $query = qq/SELECT borrowernumber + FROM borrowers + LIMIT 1/; +my $sth = $dbh->prepare($query); +$sth->execute; +my $borrower = $sth->fetchrow_hashref; + +$query = qq/SELECT biblionumber, title, itemnumber, barcode + FROM biblio + LEFT JOIN items USING (biblionumber) + WHERE barcode <> "" + AND barcode IS NOT NULL + LIMIT 1/; +$sth = $dbh->prepare($query); +$sth->execute; +my $biblio = $sth->fetchrow_hashref; + + +my $borrowernumber = $borrower->{'borrowernumber'}; +my $biblionumber = $biblio->{'biblionumber'}; +my $itemnumber = $biblio->{'itemnumber'}; +my $barcode = $biblio->{'barcode'}; + +my $constraint = 'a'; +my $bibitems = ''; +my $priority = '1'; +my $notes = ''; +my $title = $biblio->{'title'}; +my $checkitem = undef; +my $found = undef; + +my @branches = GetBranchesLoop(); +my $branch = $branches[0][0]{value}; + +AddReserve($branch, $borrowernumber, $biblionumber, + $constraint, $bibitems, $priority, $notes, + $title, $checkitem, $found); + +my ($status, $reserve) = CheckReserves($itemnumber, $barcode); +ok($status eq "Reserved", "CheckReserves Test 1"); + +($status, $reserve) = CheckReserves($itemnumber); +ok($status eq "Reserved", "CheckReserves Test 2"); + +($status, $reserve) = CheckReserves(undef, $barcode); +ok($status eq "Reserved", "CheckReserves Test 3"); + -- 2.39.5