View | Details | Raw Unified | Return to bug 23172
Collapse All | Expand All

(-)a/C4/Reserves.pm (-3 lines)
Lines 853-859 sub CheckReserves { Link Here
853
853
854
        my $priority = 10000000;
854
        my $priority = 10000000;
855
        foreach my $res (@reserves) {
855
        foreach my $res (@reserves) {
856
857
            #Before allocating to bib-level hold check if reserve respects hold rule, i.e. can patron category/item type combination allow reserves
856
            #Before allocating to bib-level hold check if reserve respects hold rule, i.e. can patron category/item type combination allow reserves
858
            my $checkreserve = Koha::Hold->check_if_existing_hold_matches_issuingrules( $res->{'borrowernumber'}, $itemnumber );
857
            my $checkreserve = Koha::Hold->check_if_existing_hold_matches_issuingrules( $res->{'borrowernumber'}, $itemnumber );
859
            next unless ($checkreserve eq 'OK');
858
            next unless ($checkreserve eq 'OK');
Lines 910-923 sub CheckReserves { Link Here
910
            }
909
            }
911
        }
910
        }
912
    }
911
    }
913
914
    # If we get this far, then no exact match was found.
912
    # If we get this far, then no exact match was found.
915
    # We return the most important (i.e. next) reservation.
913
    # We return the most important (i.e. next) reservation.
916
    if ($highest) {
914
    if ($highest) {
917
        $highest->{'itemnumber'} = $item;
915
        $highest->{'itemnumber'} = $item;
918
        return ( "Reserved", $highest, \@reserves );
916
        return ( "Reserved", $highest, \@reserves );
919
    }
917
    }
920
921
    return ( '' );
918
    return ( '' );
922
}
919
}
923
920
(-)a/t/db_dependent/Circulation.t (+22 lines)
Lines 278-283 Koha::CirculationRules->set_rules( Link Here
278
            auto_renew      => 0,
278
            auto_renew      => 0,
279
            fine            => .10,
279
            fine            => .10,
280
            chargeperiod    => 1,
280
            chargeperiod    => 1,
281
            holds_per_day   => 12,
282
            holds_per_record => 1,
281
        }
283
        }
282
    }
284
    }
283
);
285
);
Lines 1559-1564 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
1559
            branchcode   => undef,
1561
            branchcode   => undef,
1560
            rules        => {
1562
            rules        => {
1561
                onshelfholds => 0,
1563
                onshelfholds => 0,
1564
                holds_per_day => 1
1562
            }
1565
            }
1563
        }
1566
        }
1564
    );
1567
    );
Lines 3339-3344 subtest 'Set waiting flag' => sub { Link Here
3339
    my $library_2 = $builder->build( { source => 'Branch' } );
3342
    my $library_2 = $builder->build( { source => 'Branch' } );
3340
    my $patron_2  = $builder->build( { source => 'Borrower', value => { branchcode => $library_2->{branchcode}, categorycode => $patron_category->{categorycode} } } );
3343
    my $patron_2  = $builder->build( { source => 'Borrower', value => { branchcode => $library_2->{branchcode}, categorycode => $patron_category->{categorycode} } } );
3341
3344
3345
    my $biblio = $builder->build( { source => 'Biblio' } );
3346
    my $biblioitem = $builder->build( { source => 'Biblioitem', value => { biblionumber => $biblio->{biblionumber} } } );
3347
3348
    Koha::CirculationRules->set_rules(
3349
        {
3350
            categorycode => undef,
3351
            itemtype     => undef,
3352
            branchcode   => undef,
3353
            rules        => {
3354
                reservesallowed => 1,
3355
                holds_per_day => 1,
3356
                holds_per_record => 1,
3357
            }
3358
        }
3359
    );
3360
3342
    my $item = $builder->build_sample_item(
3361
    my $item = $builder->build_sample_item(
3343
        {
3362
        {
3344
            library      => $library_1->{branchcode},
3363
            library      => $library_1->{branchcode},
Lines 3366-3371 subtest 'Set waiting flag' => sub { Link Here
3366
    my ( $status ) = CheckReserves($item->itemnumber);
3385
    my ( $status ) = CheckReserves($item->itemnumber);
3367
    is( $status, 'Transferred', 'Hold is not waiting yet');
3386
    is( $status, 'Transferred', 'Hold is not waiting yet');
3368
3387
3388
    my ( $status ) = CheckReserves($item->{itemnumber});
3389
    is( $status, 'Reserved', 'Hold is not waiting yet');
3390
3369
    set_userenv( $library_2 );
3391
    set_userenv( $library_2 );
3370
    $do_transfer = 0;
3392
    $do_transfer = 0;
3371
    AddReturn( $item->barcode, $library_2->{branchcode} );
3393
    AddReturn( $item->barcode, $library_2->{branchcode} );
(-)a/t/db_dependent/Holds.t (-1 / +4 lines)
Lines 242-247 Koha::CirculationRules->set_rules( Link Here
242
        rules        => {
242
        rules        => {
243
            reservesallowed  => 25,
243
            reservesallowed  => 25,
244
            holds_per_record => 99,
244
            holds_per_record => 99,
245
            holds_per_day => 99,
245
        }
246
        }
246
    }
247
    }
247
);
248
);
Lines 251-258 Koha::CirculationRules->set_rules( Link Here
251
        branchcode   => undef,
252
        branchcode   => undef,
252
        itemtype     => 'CANNOT',
253
        itemtype     => 'CANNOT',
253
        rules        => {
254
        rules        => {
254
            reservesallowed  => 0,
255
            reservesallowed  => 1,
255
            holds_per_record => 99,
256
            holds_per_record => 99,
257
            holds_per_day => 99,
256
        }
258
        }
257
    }
259
    }
258
);
260
);
Lines 382-387 AddReserve( Link Here
382
        priority       => 1,
384
        priority       => 1,
383
    }
385
    }
384
);
386
);
387
385
is(
388
is(
386
    CanItemBeReserved( $borrowernumbers[0], $item->itemnumber)->{status}, 'tooManyReserves',
389
    CanItemBeReserved( $borrowernumbers[0], $item->itemnumber)->{status}, 'tooManyReserves',
387
    "cannot request item if policy that matches on item-level item type forbids it"
390
    "cannot request item if policy that matches on item-level item type forbids it"
(-)a/t/db_dependent/Reserves.t (-1 / +93 lines)
Lines 187-192 Koha::CirculationRules->set_rules( Link Here
187
        rules        => {
187
        rules        => {
188
            reservesallowed => 25,
188
            reservesallowed => 25,
189
            holds_per_record => 1,
189
            holds_per_record => 1,
190
            holds_per_day => 1,
190
        }
191
        }
191
    }
192
    }
192
);
193
);
Lines 311-316 my $messages; Link Here
311
# the one placed by the CPL patron, as the other two patron's hold
312
# the one placed by the CPL patron, as the other two patron's hold
312
# requests cannot be filled by that item per policy.
313
# requests cannot be filled by that item per policy.
313
(undef, $messages, undef, undef) = AddReturn('bug10272_CPL', $branch_2);
314
(undef, $messages, undef, undef) = AddReturn('bug10272_CPL', $branch_2);
315
314
is( $messages->{ResFound}->{borrowernumber},
316
is( $messages->{ResFound}->{borrowernumber},
315
    $requesters{$branch_1},
317
    $requesters{$branch_1},
316
    'restrictive library\'s items only fill requests by own patrons (bug 10272)');
318
    'restrictive library\'s items only fill requests by own patrons (bug 10272)');
Lines 722-727 MoveReserve( $item->itemnumber, $borrowernumber ); Link Here
722
is( $status, 'Reserved', 'MoveReserve did not fill future hold of 3 days');
724
is( $status, 'Reserved', 'MoveReserve did not fill future hold of 3 days');
723
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
725
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
724
726
727
728
729
730
731
732
#Test bug 23172. Check when returning an item that any patron category/item type combinations that forbid reservation are skipped over
733
#when allocating the item to a bib-level hold
734
$dbh->do('DELETE FROM issuingrules');
735
736
#Create two new patrons
737
my $patronnumcat1 = Koha::Patron->new({branchcode => $branch_1, categorycode => $category_1})->store->borrowernumber;
738
my $patronnumcat2 = Koha::Patron->new({branchcode => $branch_1, categorycode => $category_2})->store->borrowernumber;
739
740
#Create a new biblio record
741
my $bibnum3 = $builder->build_sample_biblio({frameworkcode => $frameworkcode})->biblionumber;
742
743
#Create a second item type
744
my $itemtype2 = $builder->build({ source => 'Itemtype', value => { notforloan => undef } } )->{itemtype};
745
746
# Create an item from new itemtype
747
my ( $item_bibnum2, $item_bibitemnum2, $itemnumber2 ) = AddItem(
748
    {   homebranch    => $branch_1,
749
        holdingbranch => $branch_1,
750
        itype         => $itemtype2,
751
        barcode       => 'bug23172_CPL'
752
    },
753
    $bibnum3
754
);
755
756
#Make a general All patron category/all item type rule
757
$dbh->do(
758
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_day, holds_per_record)
759
      VALUES (?, ?, ?, ?, ?, ?)},
760
    {},
761
    '*', '*', '*', 25, 1, 1
762
);
763
764
#When patron category = $category_1 and itemtype = $itemtype1 then reservesallowed, holds_per_day and holds_per_record are 0
765
$dbh->do(
766
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_day, holds_per_record)
767
     VALUES (?, ?, ?, ?, ?, ?)},
768
    {},
769
    $category_1, $branch_1, $itemtype2, 0, 1, 1
770
);
771
772
#When patron category = $category_2 and itemtype = $itemtype2 then reservesallowed, holds_per_day and holds_per_record are 1
773
$dbh->do(
774
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_day, holds_per_record)
775
     VALUES (?, ?, ?, ?, ?, ?)},
776
    {},
777
    $category_2, $branch_1, $itemtype2, 1, 1, 1
778
);
779
780
#Remove existing reserves
781
$dbh->do("DELETE FROM reserves");
782
783
#Create Bib-level hold for borrower who has a patron category of $category_2
784
my $reserveid2 = AddReserve($branch_1,  $patronnumcat2, $bibnum3);
785
786
#Bib-level hold for borrower who has a patron category of $category_1
787
my $reserveid1 = AddReserve($branch_1,  $patronnumcat1, $bibnum3 );
788
789
#Check bib-level hold priority and confirm hold made by patronnumcat1 (who fits into issuingrule with reserveallowed = 0) has first priority
790
my $reserve1 = Koha::Holds->find($reserveid1);
791
is( $reserve1->priority, 1, 'patronnumcat1 reserve is first priority');
792
793
my $reserve2 = Koha::Holds->find($reserveid2);
794
is( $reserve2->priority, 2, 'patronnumcat2 reserve is second priority');
795
796
#Return the item
797
(undef, $messages, undef, undef) = AddReturn('bug23172_CPL', $branch_1);
798
799
#First priority hold is skipped as issuingrule is checked and the first hold does not respect issuingrules (as one of the three fields: reservesallowed, holds_per_day is 0) therefore not allocating item to this bib-level hold
800
is( $messages->{ResFound}->{borrowernumber}, $patronnumcat2,'Skip allocating item to first priority hold as it does not respect issuingrules instead allocate to next valid hold (bug 23172)');
801
802
#Remove and re-add the issuing rule that prevented patronnumcat1 bib-level hold from being allocated upon item return making reservesallowed, holds_per_day and holds_per_record > 0
803
$dbh->do(q{DELETE FROM issuingrules WHERE categorycode = ? AND branchcode = ? AND itemtype = ?},
804
        {},
805
        $category_1, $branch_1, $itemtype2
806
);
807
$dbh->do(
808
   q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_day, holds_per_record)
809
    VALUES (?, ?, ?, ?, ?, ?)},
810
   {},
811
   $category_1, $branch_1, $itemtype2, 1, 1, 1
812
);
813
814
#Return the item again and notice this time it is allocated to the bib-level hold made by patronnumcat1
815
(undef, $messages, undef, undef) = AddReturn('bug23172_CPL', $branch_1);
816
is( $messages->{ResFound}->{borrowernumber}, $patronnumcat1,'Skip allocating item to first priority hold as it does not respect issuingrules instead allocate to next valid hold (bug 23172)');
817
725
$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
818
$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
726
$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
819
$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
727
$cache->clear_from_cache("default_value_for_mod_marc-");
820
$cache->clear_from_cache("default_value_for_mod_marc-");
728
- 

Return to bug 23172