From 4c45db038ce7f205616d4804a22c575a97100dbc Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 21 Apr 2016 21:42:11 +0100 Subject: [PATCH] Bug 16272: Specific case when switching an on-site checkout to a regular checkout In the case on-site checkouts are considered as a regular checkout in issuing rules (i.e. ConsiderOnSiteCheckoutsAsNormalCheckouts is on): When after the on-site checkout the maximum limit of checkouts is reached and the patron wants to switch an on-site checkout to a regular checkout, the C4::Circulation::TooMany subroutine will return a TOO_MANY_CHECKOUTS error. To avoid that, we need to allow an extra checkout in this subroutine. Test plan: 0/ Switch ConsiderOnSiteCheckoutsAsNormalCheckouts and SwitchOnSiteCheckouts on 1/ In the issuing rules, set the total number of checkouts (maxissueqty) to 2 and the number of on-site checkouts to 2 (maxonsiteissueqty) 2/ Check 2 items out ticking the 'on-site checkout' checkbox 3/ Check one of these items out, to automatically switch it to a regular checkout => The checkout should be allowed. Sponsored-by: BULAC - http://www.bulac.fr/ Signed-off-by: Nicolas Legrand --- C4/Circulation.pm | 11 +++++++++-- t/db_dependent/Circulation/SwitchOnSiteCheckouts.t | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 19bc39b..2b436ff 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -384,6 +384,7 @@ sub TooMany { my $item = shift; my $params = shift; my $onsite_checkout = $params->{onsite_checkout} || 0; + my $switch_onsite_checkout = $params->{switch_onsite_checkout} || 0; my $cat_borrower = $borrower->{'categorycode'}; my $dbh = C4::Context->dbh; my $branch; @@ -474,7 +475,8 @@ sub TooMany { } } if ( C4::Context->preference('ConsiderOnSiteCheckoutsAsNormalCheckouts') ) { - if ( $checkout_count >= $max_checkouts_allowed ) { + my $delta = $switch_onsite_checkout ? 1 : 0; + if ( $checkout_count >= $max_checkouts_allowed + $delta ) { return { reason => 'TOO_MANY_CHECKOUTS', count => $checkout_count, @@ -924,7 +926,12 @@ sub CanBookBeIssued { # # JB34 CHECKS IF BORROWERS DON'T HAVE ISSUE TOO MANY BOOKS # - my $toomany = TooMany( $borrower, $item->{biblionumber}, $item, { onsite_checkout => $onsite_checkout } ); + my $switch_onsite_checkout = + C4::Context->preference('SwitchOnSiteCheckouts') + and $issue->{onsite_checkout} + and $issue + and $issue->{borrowernumber} == $borrower->{'borrowernumber'} ? 1 : 0; + my $toomany = TooMany( $borrower, $item->{biblionumber}, $item, { onsite_checkout => $onsite_checkout, switch_onsite_checkout => $switch_onsite_checkout, } ); # if TooMany max_allowed returns 0 the user doesn't have permission to check out this book if ( $toomany ) { if ( $toomany->{max_allowed} == 0 ) { diff --git a/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t b/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t index dd98993..4f8f175 100644 --- a/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t +++ b/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t @@ -15,7 +15,7 @@ # with Koha; if not, see . use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 5; use C4::Context; use C4::Biblio; @@ -105,6 +105,21 @@ is( $issue->{onsite_checkout}, 0, '' ); my $five_days_after = dt_from_string->add( days => 5 )->set( hour => 23, minute => 59, second => 0 ); is( $issue->{date_due}, $five_days_after ); +# Specific case +t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 1); +my $another_item = $builder->build({ + source => 'Item', + value => { + biblionumber => $biblio->{biblionumber}, + homebranch => $branch->{branchcode}, + holdingbranch => $branch->{branchcode}, + }, +}); + +C4::Circulation::AddIssue( $patron, $another_item->{barcode}, dt_from_string, undef, dt_from_string, undef, { onsite_checkout => 1 } ); +( undef, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->{barcode} ); +is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, '' ); + $schema->storage->txn_rollback; 1; -- 2.1.4