Bug 18357: Handle unlimited on-site checkouts
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 2 Nov 2017 16:22:31 +0000 (13:22 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Sun, 26 Nov 2017 16:00:17 +0000 (13:00 -0300)
If on-site checkouts are set to unlimited (i.e. NULL/undef), they are
currently blocked.

Test plan:
1/ Set All/All rule with Unlimited/unlimited for normal/onsite checkouts
2/ Will be able to perform onsite checkout
3/ Edit rule to be 15/Unlimited normal/onsite
4/ Will be able to perform onsite checkout
=> Without this patch it was blocked
5/ Set rule to 15/15
6/ Onsite checkouts work again

Signed-off-by: David Bourgault <david.bourgault@inlibro.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
C4/Circulation.pm
t/db_dependent/Circulation/TooMany.t

index 5c55e8c..9397cbc 100644 (file)
@@ -474,7 +474,7 @@ sub TooMany {
         my $max_checkouts_allowed = $issuing_rule->maxissueqty;
         my $max_onsite_checkouts_allowed = $issuing_rule->maxonsiteissueqty;
 
-        if ( $onsite_checkout ) {
+        if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) {
             if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed )  {
                 return {
                     reason => 'TOO_MANY_ONSITE_CHECKOUTS',
@@ -528,7 +528,7 @@ sub TooMany {
         my $max_checkouts_allowed = $branch_borrower_circ_rule->{maxissueqty};
         my $max_onsite_checkouts_allowed = $branch_borrower_circ_rule->{maxonsiteissueqty};
 
-        if ( $onsite_checkout ) {
+        if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) {
             if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed )  {
                 return {
                     reason => 'TOO_MANY_ONSITE_CHECKOUTS',
index 7ce7e8e..193752f 100644 (file)
@@ -15,7 +15,7 @@
 # with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
-use Test::More tests => 6;
+use Test::More tests => 7;
 use C4::Context;
 
 use C4::Biblio;
@@ -159,6 +159,59 @@ subtest '1 Issuingrule exist 0 0: no issue allowed' => sub {
     teardown();
 };
 
+subtest '1 Issuingrule exist with onsiteissueqty=unlimited' => sub {
+    plan tests => 4;
+    my $issuingrule = $builder->build({
+        source => 'Issuingrule',
+        value => {
+            branchcode         => $branch->{branchcode},
+            categorycode       => $category->{categorycode},
+            itemtype           => '*',
+            maxissueqty        => 1,
+            maxonsiteissueqty  => undef,
+        },
+    });
+    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string() );
+    t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0);
+    is_deeply(
+        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
+        {
+            reason => 'TOO_MANY_CHECKOUTS',
+            count => 1,
+            max_allowed => 1,
+        },
+        'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0'
+    );
+    is(
+        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item, { onsite_checkout => 1 } ),
+        undef,
+        'OSCO should be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0'
+    );
+
+    t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 1);
+    is_deeply(
+        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
+        {
+            reason => 'TOO_MANY_CHECKOUTS',
+            count => 1,
+            max_allowed => 1,
+        },
+        'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1'
+    );
+    is_deeply(
+        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item, { onsite_checkout => 1 } ),
+        {
+            reason => 'TOO_MANY_CHECKOUTS',
+            count => 1,
+            max_allowed => 1,
+        },
+        'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1'
+    );
+
+    teardown();
+};
+
+
 subtest '1 Issuingrule exist 1 1: issue is allowed' => sub {
     plan tests => 4;
     my $issuingrule = $builder->build({