From 99d15b18c533b346e6929bf61ac35d67578be4db Mon Sep 17 00:00:00 2001 From: Rafal Kopaczka Date: Fri, 30 May 2014 15:15:37 +0200 Subject: [PATCH] Bug 11651: (QA Follow-up) Add possibility to print holds from holds queue. Added unit tests, for new and modified subroutines. Fixed minor qa suggestions. Koha-qa.pl - pass. --- C4/HoldsQueue.pm | 33 +++++++------- circ/hold-pull-print.pl | 23 +++++----- .../prog/en/modules/circ/view_holdsqueue.tt | 46 ++++++++++---------- t/db_dependent/HoldsQueue.t | 26 ++++++++++- t/db_dependent/Reserves.t | 6 ++- 5 files changed, 79 insertions(+), 55 deletions(-) diff --git a/C4/HoldsQueue.pm b/C4/HoldsQueue.pm index 200cf53..b3467f0 100755 --- a/C4/HoldsQueue.pm +++ b/C4/HoldsQueue.pm @@ -657,14 +657,12 @@ sub least_cost_branch { sub MarkHoldPrinted { my ( $reserve_id ) = @_; my $dbh = C4::Context->dbh; - my $strsth="UPDATE reserves INNER JOIN tmp_holdsqueue USING (reserve_id) - SET reserves.print_status = 1 , tmp_holdsqueue.print_status = 1 + my $strsth="UPDATE reserves LEFT JOIN tmp_holdsqueue USING (reserve_id) + SET reserves.print_status = '1' , tmp_holdsqueue.print_status = '1' WHERE reserve_id = ? - "; + "; my $sth = $dbh->prepare($strsth); - $sth->execute($reserve_id); - - return 1; + return $sth->execute($reserve_id); } =head2 GetItemNumberFromTmpHold @@ -672,20 +670,19 @@ sub MarkHoldPrinted { Returns itemnumber associated with hold. Item number is taken from tmp_holdsqueue table, which is populated by bulid_holds_queue.pl script. - =cut -sub GetItemNumberFromTmpHold{ - my ( $reserve_id ) = @_; - my $dbh = C4::Context->dbh; - my $strsth="SELECT itemnumber - FROM tmp_holdsqueue - WHERE reserve_id = ? - "; - my $sth = $dbh->prepare($strsth); - $sth->execute($reserve_id); +sub GetItemNumberFromTmpHold { + my ( $reserve_id ) = @_; + my $dbh = C4::Context->dbh; + my $strsth="SELECT itemnumber + FROM tmp_holdsqueue + WHERE reserve_id = ? + "; + my $sth = $dbh->prepare($strsth); + $sth->execute($reserve_id); - my $data = $sth->fetchrow; - return $data; + my $data = $sth->fetchrow; + return $data; } 1; diff --git a/circ/hold-pull-print.pl b/circ/hold-pull-print.pl index 106b479..46ff91e 100755 --- a/circ/hold-pull-print.pl +++ b/circ/hold-pull-print.pl @@ -2,21 +2,20 @@ # This file is part of Koha. # -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later -# version. +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. # -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along -# with Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . -use strict; -#use warnings; #FIXME - Bug 2505 +use Modern::Perl; use C4::Context; use C4::Output; use CGI; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/view_holdsqueue.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/view_holdsqueue.tt index 1a66e81..ae0747f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/view_holdsqueue.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/view_holdsqueue.tt @@ -11,39 +11,37 @@ [% INCLUDE 'cat-search.inc' %] [% INCLUDE 'datatables.inc' %] + @@ -72,8 +70,8 @@ function clearAll () { [% IF ( printenable ) %]

- Select all | - Clear all + Select all | + Clear all

@@ -89,7 +87,9 @@ function clearAll () {
[% END %] [% IF ( itemsloop ) %] -
+ [% IF ( printenable ) %] + + [% END %] @@ -110,7 +110,7 @@ function clearAll () { [% FOREACH itemsloo IN itemsloop %] [% IF ( printenable ) %] - + [% END %]

[% itemsloo.title |html %] [% IF ( itemsloo.subtitle ) %][% itemsloo.subtitle %][% END %]

[% itemsloo.author %] diff --git a/t/db_dependent/HoldsQueue.t b/t/db_dependent/HoldsQueue.t index 0a96143..bec0ec4 100755 --- a/t/db_dependent/HoldsQueue.t +++ b/t/db_dependent/HoldsQueue.t @@ -12,7 +12,7 @@ use C4::Context; use Data::Dumper; -use Test::More tests => 21; +use Test::More tests => 28; use C4::Branch; @@ -281,6 +281,14 @@ $sth->execute( $borrower3->{borrowernumber}, $biblionumber, $branchcodes[0], 3 ) #warn "RESERVES" . Data::Dumper::Dumper( $dbh->selectall_arrayref("SELECT * FROM reserves", { Slice => {} }) ); #warn "ITEMS: " . Data::Dumper::Dumper( $dbh->selectall_arrayref("SELECT * FROM items WHERE biblionumber = $biblionumber", { Slice => {} }) ); +my $reserve_id = $dbh->selectcol_arrayref("SELECT reserve_id FROM reserves"); +my $print_status = $dbh->selectcol_arrayref("SELECT print_status FROM reserves WHERE reserve_id = ?", undef, $reserve_id->[0]); +is( $print_status->[0], "0", "Default print status in reserves for new reserve set as 0"); +C4::HoldsQueue::MarkHoldPrinted($reserve_id->[0]); +$print_status = $dbh->selectcol_arrayref("SELECT print_status FROM reserves WHERE reserve_id = ?", undef, $reserve_id->[0]); +is( $print_status->[0], "1", "Hold status in reserves correctly marked as printed"); +C4::HoldsQueue::MarkHoldPrinted($reserve_id->[1]); + my $holds_queue; $dbh->do("DELETE FROM default_circ_rules"); @@ -298,6 +306,22 @@ $holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice ok( @$holds_queue == 3, "Holds queue filling correct number for holds for default holds policy 'from any library'" ); #warn "HOLDS QUEUE: " . Data::Dumper::Dumper( $holds_queue ); +my $print_status_tmp = $dbh->selectcol_arrayref("SELECT print_status FROM reserves WHERE reserve_id = ?", undef, $reserve_id->[1]); +is( $print_status_tmp->[0], "1", "Hold status printed moved to tmp_holdsqueue from reserves"); +$print_status_tmp = $dbh->selectcol_arrayref("SELECT print_status FROM reserves WHERE reserve_id = ?", undef, $reserve_id->[2]); +is( $print_status_tmp->[0], "0", "Default print status in tmp_holdsqueue moved from reserves"); +C4::HoldsQueue::MarkHoldPrinted($reserve_id->[2]); +$print_status_tmp = $dbh->selectcol_arrayref("SELECT print_status FROM reserves WHERE reserve_id = ?", undef, $reserve_id->[2]); +is( $print_status_tmp->[0], "1", "Hold status in tmp_holdsqueue correctly marked as printed"); + +my $select_itnum = $dbh->selectcol_arrayref("SELECT itemnumber FROM tmp_holdsqueue WHERE reserve_id = ?", undef, $reserve_id->[0]); +my $get_itnum = C4::HoldsQueue::GetItemNumberFromTmpHold($reserve_id->[0]); +is( $select_itnum->[0], $get_itnum, "Correct itemnumber selected from tmp_holdsqueue"); + +C4::Context->set_preference('printSlipFromHoldsQueue', 1); +my $getholds_queue = C4::HoldsQueue::GetHoldsQueueItems(undef, 1); +is( @$getholds_queue, "3", "Get printed holds from tmp_holdsqueue"); + # Cleanup $dbh->rollback; diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 0698534..4ec07d5 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -2,7 +2,7 @@ use Modern::Perl; -use Test::More tests => 35; +use Test::More tests => 36; use MARC::Record; use DateTime::Duration; @@ -395,6 +395,10 @@ $p = C4::Reserves::CalculatePriority($bibnum, $resdate); is($p, 3, 'CalculatePriority should now return priority 3'); # End of tests for bug 8918 +@results = GetReservesFromItemnumber($itemnumber); +my $hold_slip = C4::Reserves::HoldSlip('CPL', $results[3], $itemnumber); +ok(defined($hold_slip), 'can successfully generate hold slip'); + $dbh->rollback; sub count_hold_print_messages { -- 1.7.10.4