From 548ff77019875796e270c346b7557a3d3240f471 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Sun, 11 Jun 2017 09:10:17 +0000 Subject: [PATCH] Bug 17171 - Add a syspref to allow currently issued items to be issued to a new patron without staff confirmation Some libraries don't want to force the librarians to manually confirm each checkout when the item is checked out to another. Instead, they would prefer to be alerted after the fact. Test Plan: 1) Apply this patch 2) Run updatedatabase.pl 3) Enable the new syspref AutoReturnCheckedOutItems 4) Check an item out to a patron 5) Check the same item out to another patron 6) Note you are not prompted to confirm the checkout, but are instead alerted that is had been checked out to another patron! --- C4/Circulation.pm | 15 ++++-- installer/data/mysql/atomicupdate/bug_17171.perl | 10 ++++ installer/data/mysql/sysprefs.sql | 1 + .../csv_headers/reports/cash_register_stats.tt | 2 +- .../en/modules/admin/preferences/circulation.pref | 6 +++ .../prog/en/modules/circ/circulation.tt | 4 ++ t/db_dependent/Circulation.t | 57 +++++++++++++++++++++- 7 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_17171.perl diff --git a/C4/Circulation.pm b/C4/Circulation.pm index a439021..c2f6e41 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -980,11 +980,16 @@ sub CanBookBeIssued { $issuingimpossible{RETURN_IMPOSSIBLE} = 1; $issuingimpossible{branch_to_return} = $message; } else { - $needsconfirmation{ISSUED_TO_ANOTHER} = 1; - $needsconfirmation{issued_firstname} = $currborinfo->{'firstname'}; - $needsconfirmation{issued_surname} = $currborinfo->{'surname'}; - $needsconfirmation{issued_cardnumber} = $currborinfo->{'cardnumber'}; - $needsconfirmation{issued_borrowernumber} = $currborinfo->{'borrowernumber'}; + if ( C4::Context->preference('AutoReturnCheckedOutItems') ) { + $alerts{RETURNED_FROM_ANOTHER} = { patron => $currborinfo }; + } + else { + $needsconfirmation{ISSUED_TO_ANOTHER} = 1; + $needsconfirmation{issued_firstname} = $currborinfo->{'firstname'}; + $needsconfirmation{issued_surname} = $currborinfo->{'surname'}; + $needsconfirmation{issued_cardnumber} = $currborinfo->{'cardnumber'}; + $needsconfirmation{issued_borrowernumber} = $currborinfo->{'borrowernumber'}; + } } } diff --git a/installer/data/mysql/atomicupdate/bug_17171.perl b/installer/data/mysql/atomicupdate/bug_17171.perl new file mode 100644 index 0000000..c1a6fe3 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_17171.perl @@ -0,0 +1,10 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + $dbh->do(q{ + INSERT IGNORE INTO `systempreferences` (`variable`, `value`, `options`, `explanation`, `type`) VALUES + ('AutoReturnCheckedOutItems', '0', '', 'If disabled, librarian must confirm return of checked out item when checking out to another.', 'YesNo'); + }); + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 17171 - Add a syspref to allow currently issued items to be issued to a new patron without staff confirmation)\n"; +} diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 0bd8cac..232b9d1 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -68,6 +68,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('AutoSelfCheckAllowed','0','','For corporate and special libraries which want web-based self-check available from any PC without the need for a manual staff login. Most libraries will want to leave this turned off. If on, requires self-check ID and password to be entered in AutoSelfCheckID and AutoSelfCheckPass sysprefs.','YesNo'), ('AutoSelfCheckID','','','Staff ID with circulation rights to be used for automatic web-based self-check. Only applies if AutoSelfCheckAllowed syspref is turned on.','free'), ('AutoSelfCheckPass','','','Password to be used for automatic web-based self-check. Only applies if AutoSelfCheckAllowed syspref is turned on.','free'), +('AutoReturnCheckedOutItems', '0', '', 'If disabled, librarian must confirm return of checked out item when checking out to another.', 'YesNo'), ('Babeltheque','0','','Turn ON Babeltheque content - See babeltheque.com to subscribe to this service','YesNo'), ('Babeltheque_url_js','','','Url for Babeltheque javascript (e.g. http://www.babeltheque.com/bw_XX.js)','Free'), ('Babeltheque_url_update','','','Url for Babeltheque update (E.G. http://www.babeltheque.com/.../file.csv.bz2)','Free'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/csv_headers/reports/cash_register_stats.tt b/koha-tmpl/intranet-tmpl/prog/en/includes/csv_headers/reports/cash_register_stats.tt index 0746a69..e70f1b5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/csv_headers/reports/cash_register_stats.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/csv_headers/reports/cash_register_stats.tt @@ -1 +1 @@ -mfirstname[% sep %]card number[% sep %]firstname[% sep %]branchname[% sep %]date[% sep %]accounttype[% sep %]amount[% sep %]title[% sep %]barcode[% sep %]itype +mfirstname[% sep %]card number[% sep %]firstname[% sep %]branchname[% sep %]date[% sep %]accounttype[% sep %]amount[% sep %]title[% sep %]barcode[% sep %]"itype" diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index 90b2844..2561bef 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -153,6 +153,12 @@ Circulation: Checkout Policy: - + - pref: AutoReturnCheckedOutItems + choices: + yes: Don't + no: Do + - require librarians to manually confirm a checkout where the item is already checked out to another patron. + - - pref: AllowTooManyOverride choices: yes: Allow diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index 21fbbf2..ce3d58f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -177,6 +177,10 @@ $(document).ready(function() {
High demand item. Loan period was not shortened due to override. Shortened due date would have been [% alert.HIGHHOLDS.returndate %] ([% alert.HIGHHOLDS.duration %] days).
[% END %] +[% IF alert.RETURNED_FROM_ANOTHER %] +
Item was checked out to [% alert.RETURNED_FROM_ANOTHER.patron.firstname %] [% alert.RETURNED_FROM_ANOTHER.patron.surname %] ([% alert.RETURNED_FROM_ANOTHER.patron.cardnumber %]) and was returned automatically.
+[% END %] + [% IF ( nopermission ) %]
Staff members are not allowed to discharge borrowers, nor borrowers to request a discharge.
[% END %] diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 9d0f77c..249675b 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 95; +use Test::More tests => 96; use DateTime; @@ -72,6 +72,8 @@ my $borrower = { branchcode => $library2->{branchcode} }; +t::lib::Mocks::mock_preference('AutoReturnCheckedOutItems', 0); + # No userenv, PickupLibrary t::lib::Mocks::mock_preference('IndependentBranches', '0'); t::lib::Mocks::mock_preference('CircControl', 'PickupLibrary'); @@ -1631,6 +1633,59 @@ subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { is( $debarments->[0]->{expiration}, $expected_expiration ); }; +subtest 'CanBookBeIssued + AutoReturnCheckedOutItems' => sub { + plan tests => 2; + + my $library = $builder->build( { source => 'Branch' } ); + my $patron1 = $builder->build( + { + source => 'Borrower', + value => { + branchcode => $library->{branchcode}, + } + } + ); + my $patron2 = $builder->build( + { + source => 'Borrower', + value => { + branchcode => $library->{branchcode}, + } + } + ); + + C4::Context->_new_userenv('xxx'); + C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, 'Random Library', '', '', ''); + + my $biblioitem = $builder->build( { source => 'Biblioitem' } ); + my $biblionumber = $biblioitem->{biblionumber}; + my $item = $builder->build( + { source => 'Item', + value => { + homebranch => $library->{branchcode}, + holdingbranch => $library->{branchcode}, + notforloan => 0, + itemlost => 0, + withdrawn => 0, + biblionumber => $biblionumber, + } + } + ); + + my ( $error, $question, $alerts ); + my $issue = AddIssue( $patron1, $item->{barcode} ); + + t::lib::Mocks::mock_preference('AutoReturnCheckedOutItems', 0); + ( $error, $question, $alerts ) = CanBookBeIssued( $patron2, $item->{barcode} ); + is( $question->{ISSUED_TO_ANOTHER}, 1, 'ISSUED_TO_ANOTHER question flag should be set if AutoReturnCheckedOutItems is disabled and item is checked out to another' ); + + t::lib::Mocks::mock_preference('AutoReturnCheckedOutItems', 1); + ( $error, $question, $alerts ) = CanBookBeIssued( $patron2, $item->{barcode} ); + is( $alerts->{RETURNED_FROM_ANOTHER}->{patron}->{borrowernumber}, $patron1->{borrowernumber}, 'RETURNED_FROM_ANOTHER alert flag should be set if AutoReturnCheckedOutItems is enabled and item is checked out to another' ); + + t::lib::Mocks::mock_preference('AutoReturnCheckedOutItems', 0); +}; + sub set_userenv { my ( $library ) = @_; C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', ''); -- 2.1.4