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

(-)a/C4/Reserves.pm (-2 / +31 lines)
Lines 298-308 sub CanBookBeReserved{ Link Here
298
         { status => ageRestricted },   if the Item is age restricted for this borrower.
298
         { status => ageRestricted },   if the Item is age restricted for this borrower.
299
         { status => damaged },         if the Item is damaged.
299
         { status => damaged },         if the Item is damaged.
300
         { status => cannotReserveFromOtherBranches }, if syspref 'canreservefromotherbranches' is OK.
300
         { status => cannotReserveFromOtherBranches }, if syspref 'canreservefromotherbranches' is OK.
301
         { status => branchNotInHoldGroup }, if borrower home library is not in hold group, and holds are only allowed from hold groups.
301
         { status => tooManyReserves, limit => $limit }, if the borrower has exceeded their maximum reserve amount.
302
         { status => tooManyReserves, limit => $limit }, if the borrower has exceeded their maximum reserve amount.
302
         { status => notReservable },   if holds on this item are not allowed
303
         { status => notReservable },   if holds on this item are not allowed
303
         { status => libraryNotFound },   if given branchcode is not an existing library
304
         { status => libraryNotFound },   if given branchcode is not an existing library
304
         { status => libraryNotPickupLocation },   if given branchcode is not configured to be a pickup location
305
         { status => libraryNotPickupLocation },   if given branchcode is not configured to be a pickup location
305
         { status => cannotBeTransferred }, if branch transfer limit applies on given item and branchcode
306
         { status => cannotBeTransferred }, if branch transfer limit applies on given item and branchcode
307
         { status => pickupNotInHoldGroup }, pickup location is not in hold group, and pickup locations are only allowed from hold groups.
306
308
307
=cut
309
=cut
308
310
Lines 457-462 sub CanItemBeReserved { Link Here
457
        return { status => 'cannotReserveFromOtherBranches' };
459
        return { status => 'cannotReserveFromOtherBranches' };
458
    }
460
    }
459
461
462
    my $branch_control = C4::Context->preference('HomeOrHoldingBranch');
463
    my $itembranchcode = $branch_control eq 'holdingbranch' ? $item->holdingbranch : $item->homebranch;
464
    my $item_library = Koha::Libraries->find( {branchcode => $itembranchcode} );
465
    if ( $branchitemrule->{holdallowed} == 3) {
466
        if($borrower->{branchcode} ne $itembranchcode && !$item_library->validate_hold_sibling( {branchcode => $borrower->{branchcode}} )) {
467
            return { status => 'branchNotInHoldGroup' };
468
        }
469
    }
470
460
    # If reservecount is ok, we check item branch if IndependentBranches is ON
471
    # If reservecount is ok, we check item branch if IndependentBranches is ON
461
    # and canreservefromotherbranches is OFF
472
    # and canreservefromotherbranches is OFF
462
    if ( C4::Context->preference('IndependentBranches')
473
    if ( C4::Context->preference('IndependentBranches')
Lines 481-486 sub CanItemBeReserved { Link Here
481
        unless ($item->can_be_transferred({ to => $destination })) {
492
        unless ($item->can_be_transferred({ to => $destination })) {
482
            return { status => 'cannotBeTransferred' };
493
            return { status => 'cannotBeTransferred' };
483
        }
494
        }
495
        unless ($branchitemrule->{hold_fulfillment_policy} ne 'holdgroup' || $item_library->validate_hold_sibling( {branchcode => $pickup_branchcode} )) {
496
            return { status => 'pickupNotInHoldGroup' };
497
        }
484
    }
498
    }
485
499
486
    return { status => 'OK' };
500
    return { status => 'OK' };
Lines 797-804 sub CheckReserves { Link Here
797
                    my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype);
811
                    my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype);
798
                    next if ($branchitemrule->{'holdallowed'} == 0);
812
                    next if ($branchitemrule->{'holdallowed'} == 0);
799
                    next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $patron->branchcode));
813
                    next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $patron->branchcode));
814
                    my $library = Koha::Libraries->find({branchcode=>$branch});
815
                    next if (($branchitemrule->{'holdallowed'} == 3) && (!$library->validate_hold_sibling({branchcode => $patron->branchcode}) ));
800
                    my $hold_fulfillment_policy = $branchitemrule->{hold_fulfillment_policy};
816
                    my $hold_fulfillment_policy = $branchitemrule->{hold_fulfillment_policy};
801
                    next if ( ($branchitemrule->{hold_fulfillment_policy} ne 'any') && ($res->{branchcode} ne $item->$hold_fulfillment_policy) );
817
                    next if ( ($hold_fulfillment_policy eq 'holdgroup') && (!$library->validate_hold_sibling({branchcode => $res->{branchcode}})) );
818
                    next if ( ($hold_fulfillment_policy eq 'homebranch') && ($res->{branchcode} ne $item->$hold_fulfillment_policy) );
819
                    next if ( ($hold_fulfillment_policy eq 'holdingbranch') && ($res->{branchcode} ne $item->$hold_fulfillment_policy) );
802
                    next unless $item->can_be_transferred( { to => scalar Koha::Libraries->find( $res->{branchcode} ) } );
820
                    next unless $item->can_be_transferred( { to => scalar Koha::Libraries->find( $res->{branchcode} ) } );
803
                    $priority = $res->{'priority'};
821
                    $priority = $res->{'priority'};
804
                    $highest  = $res;
822
                    $highest  = $res;
Lines 1192-1197 sub IsAvailableForItemLevelRequest { Link Here
1192
        return 0 unless $destination;
1210
        return 0 unless $destination;
1193
        return 0 unless $destination->pickup_location;
1211
        return 0 unless $destination->pickup_location;
1194
        return 0 unless $item_object->can_be_transferred( { to => $destination } );
1212
        return 0 unless $item_object->can_be_transferred( { to => $destination } );
1213
        my $circ_control_branch =
1214
            C4::Circulation::_GetCircControlBranch( $item_object->unblessed(), $borrower );
1215
        my $branchitemrule =
1216
            C4::Circulation::GetBranchItemRule( $circ_control_branch, $item_object->itype );
1217
        my $home_library = Koka::Libraries->find( {branchcode => $item_object->homebranch} );
1218
        return 0 unless $branchitemrule->{hold_fulfillment_policy} ne 'holdgroup' || $home_library->validate_hold_sibling( {branchcode => $pickup_branchcode} );
1195
    }
1219
    }
1196
1220
1197
    if ( $on_shelf_holds == 1 ) {
1221
    if ( $on_shelf_holds == 1 ) {
Lines 1206-1211 sub IsAvailableForItemLevelRequest { Link Here
1206
1230
1207
            my $circ_control_branch = C4::Circulation::_GetCircControlBranch( $i->unblessed(), $borrower );
1231
            my $circ_control_branch = C4::Circulation::_GetCircControlBranch( $i->unblessed(), $borrower );
1208
            my $branchitemrule = C4::Circulation::GetBranchItemRule( $circ_control_branch, $i->itype );
1232
            my $branchitemrule = C4::Circulation::GetBranchItemRule( $circ_control_branch, $i->itype );
1233
            my $branch_control = C4::Context->preference('HomeOrHoldingBranch');
1234
            my $itembranchcode = $branch_control eq 'holdingbranch' ? $item->holdingbranch : $item->homebranch;
1235
            my $item_library = Koha::Libraries->find( {branchcode => $itembranchcode} );
1236
1209
1237
1210
            $any_available = 1
1238
            $any_available = 1
1211
              unless $i->itemlost
1239
              unless $i->itemlost
Lines 1216-1222 sub IsAvailableForItemLevelRequest { Link Here
1216
              || ( $i->damaged
1244
              || ( $i->damaged
1217
                && !C4::Context->preference('AllowHoldsOnDamagedItems') )
1245
                && !C4::Context->preference('AllowHoldsOnDamagedItems') )
1218
              || Koha::ItemTypes->find( $i->effective_itemtype() )->notforloan
1246
              || Koha::ItemTypes->find( $i->effective_itemtype() )->notforloan
1219
              || $branchitemrule->{holdallowed} == 1 && $borrower->{branchcode} ne $i->homebranch;
1247
              || $branchitemrule->{holdallowed} == 1 && $borrower->{branchcode} ne $i->homebranch
1248
              || $branchitemrule->{holdallowed} == 3 && !$item_library->validate_hold_sibling( {branchcode => $pickup_branchcode} );
1220
        }
1249
        }
1221
1250
1222
        return $any_available ? 0 : 1;
1251
        return $any_available ? 0 : 1;
(-)a/t/db_dependent/Holds.t (-2 / +396 lines)
Lines 7-13 use t::lib::TestBuilder; Link Here
7
7
8
use C4::Context;
8
use C4::Context;
9
9
10
use Test::More tests => 58;
10
use Test::More tests => 60;
11
use MARC::Record;
11
use MARC::Record;
12
12
13
use C4::Biblio;
13
use C4::Biblio;
Lines 24-31 use Koha::IssuingRules; Link Here
24
use Koha::Item::Transfer::Limits;
24
use Koha::Item::Transfer::Limits;
25
use Koha::Items;
25
use Koha::Items;
26
use Koha::Libraries;
26
use Koha::Libraries;
27
use Koha::Library::Groups;
27
use Koha::Patrons;
28
use Koha::Patrons;
28
29
30
use Data::Dumper;
31
29
BEGIN {
32
BEGIN {
30
    use FindBin;
33
    use FindBin;
31
    use lib $FindBin::Bin;
34
    use lib $FindBin::Bin;
Lines 262-267 t::lib::Mocks::mock_preference('item-level_itypes', 1); Link Here
262
265
263
# if IndependentBranches is OFF, a $branch_1 patron can reserve an $branch_2 item
266
# if IndependentBranches is OFF, a $branch_1 patron can reserve an $branch_2 item
264
t::lib::Mocks::mock_preference('IndependentBranches', 0);
267
t::lib::Mocks::mock_preference('IndependentBranches', 0);
268
265
ok(
269
ok(
266
    CanItemBeReserved($borrowernumbers[0], $foreign_itemnumber)->{status} eq 'OK',
270
    CanItemBeReserved($borrowernumbers[0], $foreign_itemnumber)->{status} eq 'OK',
267
    '$branch_1 patron allowed to reserve $branch_2 item with IndependentBranches OFF (bug 2394)'
271
    '$branch_1 patron allowed to reserve $branch_2 item with IndependentBranches OFF (bug 2394)'
Lines 670-672 subtest 'CanItemBeReserved / holds_per_day tests' => sub { Link Here
670
674
671
    $schema->storage->txn_rollback;
675
    $schema->storage->txn_rollback;
672
};
676
};
673
- 
677
678
subtest 'CanItemBeReserved / branch_not_in_hold_group' => sub {
679
    plan tests => 9;
680
681
    $schema->storage->txn_begin;
682
683
    # Cleanup database
684
    Koha::Holds->search->delete;
685
    $dbh->do('DELETE FROM issues');
686
    $dbh->do('DELETE FROM issuingrules');
687
    $dbh->do(
688
        q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed)
689
        VALUES (?, ?, ?, ?)},
690
        {},
691
        '*', '*', '*', 25
692
    );
693
    $dbh->do('DELETE FROM branch_item_rules');
694
    $dbh->do('DELETE FROM default_branch_circ_rules');
695
    $dbh->do('DELETE FROM default_branch_item_rules');
696
    $dbh->do('DELETE FROM default_circ_rules');
697
698
    Koha::Items->search->delete;
699
    Koha::Biblios->search->delete;
700
701
    # Create item types
702
    my $itemtype1 = $builder->build_object( { class => 'Koha::ItemTypes' } );
703
    my $itemtype2 = $builder->build_object( { class => 'Koha::ItemTypes' } );
704
705
    # Create libraries
706
    my $library1  = $builder->build_object( { class => 'Koha::Libraries' } );
707
    my $library2  = $builder->build_object( { class => 'Koha::Libraries' } );
708
    my $library3  = $builder->build_object( { class => 'Koha::Libraries' } );
709
710
    # Create library groups hierarchy
711
    my $rootgroup  = $builder->build_object( { class => 'Koha::Library::Groups', value => {ft_local_hold_group => 1} } );
712
    my $group1  = $builder->build_object( { class => 'Koha::Library::Groups', value => {parent_id => $rootgroup->id, branchcode => $library1->branchcode}} );
713
    my $group2  = $builder->build_object( { class => 'Koha::Library::Groups', value => {parent_id => $rootgroup->id, branchcode => $library2->branchcode} } );
714
715
    # Create 2 patrons
716
    my $patron1   = $builder->build_object( { class => 'Koha::Patrons', value => {branchcode => $library1->branchcode} } );
717
    my $patron3   = $builder->build_object( { class => 'Koha::Patrons', value => {branchcode => $library3->branchcode} } );
718
719
    # Create 3 biblios with items
720
    my $biblio_1 = $builder->build_sample_biblio({ itemtype => $itemtype1->itemtype });
721
    my ( undef, undef, $itemnumber_1 ) = AddItem(
722
        {   homebranch    => $library1->branchcode,
723
            holdingbranch => $library1->branchcode
724
        },
725
        $biblio_1->biblionumber
726
    );
727
    my $biblio_2 = $builder->build_sample_biblio({ itemtype => $itemtype2->itemtype });
728
    my ( undef, undef, $itemnumber_2 ) = AddItem(
729
        {   homebranch    => $library2->branchcode,
730
            holdingbranch => $library2->branchcode
731
        },
732
        $biblio_2->biblionumber
733
    );
734
    my $biblio_3 = $builder->build_sample_biblio({ itemtype => $itemtype1->itemtype });
735
    my ( undef, undef, $itemnumber_3 ) = AddItem(
736
        {   homebranch    => $library1->branchcode,
737
            holdingbranch => $library1->branchcode
738
        },
739
        $biblio_3->biblionumber
740
    );
741
742
    # Test 1: Patron 3 can place hold
743
    is_deeply(
744
        CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2 ),
745
        { status => 'OK' },
746
        'Patron can place hold if no circ_rules where defined'
747
    );
748
749
    # Insert default circ rule of holds allowed only from local hold group for all libraries
750
    $dbh->do(
751
        q{INSERT INTO default_circ_rules (holdallowed, hold_fulfillment_policy, returnbranch)
752
        VALUES (?,?,?)},
753
        {},
754
        3, 'any', 'any'
755
    );
756
757
    # Test 2: Patron 1 can place hold
758
    is_deeply(
759
        CanItemBeReserved( $patron1->borrowernumber, $itemnumber_2 ),
760
        { status => 'OK' },
761
        'Patron can place hold because patron\'s home library is part of hold group'
762
    );
763
764
    # Test 3: Patron 3 cannot place hold
765
    is_deeply(
766
        CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2 ),
767
        { status => 'branchNotInHoldGroup' },
768
        'Patron cannot place hold because patron\'s home library is not part of hold group'
769
    );
770
771
    # Cleanup default_cirt_rules
772
    $dbh->do('DELETE FROM default_circ_rules');
773
774
    # Insert default circ rule to "any" for library 2
775
    $dbh->do(
776
        q{INSERT INTO default_branch_circ_rules (branchcode, holdallowed, hold_fulfillment_policy, returnbranch)
777
        VALUES (?,?,?,?)},
778
        {},
779
        $library2->branchcode, 2, 'any', 'any'
780
    );
781
782
    # Test 4: Patron 3 can place hold
783
    is_deeply(
784
        CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2 ),
785
        { status => 'OK' },
786
        'Patron can place hold if holdallowed is set to "any" for library 2'
787
    );
788
789
    # Update default circ rule to "hold group" for library 2
790
    $dbh->do(
791
        q{UPDATE default_branch_circ_rules set holdallowed = ?
792
        WHERE branchcode = ?},
793
        {},
794
        3, $library2->branchcode
795
    );
796
797
    # Test 5: Patron 3 cannot place hold
798
    is_deeply(
799
        CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2 ),
800
        { status => 'branchNotInHoldGroup' },
801
        'Patron cannot place hold if holdallowed is set to "hold group" for library 2'
802
    );
803
804
    # Cleanup default_branch_cirt_rules
805
    $dbh->do('DELETE FROM default_branch_circ_rules');
806
807
    # Insert default item rule to "any" for itemtype 2
808
    $dbh->do(
809
        q{INSERT INTO default_branch_item_rules (itemtype, holdallowed, hold_fulfillment_policy, returnbranch)
810
        VALUES (?,?,?,?)},
811
        {},
812
        $itemtype2->itemtype, 2, 'any', 'any'
813
    );
814
815
    # Test 6: Patron 3 can place hold
816
    is_deeply(
817
        CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2 ),
818
        { status => 'OK' },
819
        'Patron can place hold if holdallowed is set to "any" for itemtype 2'
820
    );
821
822
    # Update default item rule to "hold group" for itemtype 2
823
    $dbh->do(
824
        q{UPDATE default_branch_item_rules set holdallowed = ?
825
        WHERE itemtype = ?},
826
        {},
827
        3, $itemtype2->itemtype
828
    );
829
830
    # Test 7: Patron 3 cannot place hold
831
    is_deeply(
832
        CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2 ),
833
        { status => 'branchNotInHoldGroup' },
834
        'Patron cannot place hold if holdallowed is set to "hold group" for itemtype 2'
835
    );
836
837
    # Cleanup default_branch_item_rules
838
    $dbh->do('DELETE FROM default_branch_item_rules');
839
840
    # Insert branch item rule to "any" for itemtype 2 and library 2
841
    $dbh->do(
842
        q{INSERT INTO branch_item_rules (branchcode, itemtype, holdallowed, hold_fulfillment_policy, returnbranch)
843
        VALUES (?,?,?,?,?)},
844
        {},
845
        $library2->branchcode, $itemtype2->itemtype, 2, 'any', 'any'
846
    );
847
848
    # Test 8: Patron 3 can place hold
849
    is_deeply(
850
        CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2 ),
851
        { status => 'OK' },
852
        'Patron can place hold if holdallowed is set to "any" for itemtype 2 and library 2'
853
    );
854
855
    # Update branch item rule to "hold group" for itemtype 2 and library 2
856
    $dbh->do(
857
        q{UPDATE branch_item_rules set holdallowed = ?
858
        WHERE branchcode = ? and itemtype = ?},
859
        {},
860
        3, $library2->branchcode, $itemtype2->itemtype
861
    );
862
863
    # Test 9: Patron 3 cannot place hold
864
    is_deeply(
865
        CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2 ),
866
        { status => 'branchNotInHoldGroup' },
867
        'Patron cannot place hold if holdallowed is set to "hold group" for itemtype 2 and library 2'
868
    );
869
870
    $schema->storage->txn_rollback;
871
872
};
873
874
subtest 'CanItemBeReserved / pickup_not_in_hold_group' => sub {
875
    plan tests => 9;
876
877
    $schema->storage->txn_begin;
878
879
    # Cleanup database
880
    Koha::Holds->search->delete;
881
    $dbh->do('DELETE FROM issues');
882
    $dbh->do('DELETE FROM issuingrules');
883
    $dbh->do(
884
        q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed)
885
        VALUES (?, ?, ?, ?)},
886
        {},
887
        '*', '*', '*', 25
888
    );
889
    $dbh->do('DELETE FROM branch_item_rules');
890
    $dbh->do('DELETE FROM default_branch_circ_rules');
891
    $dbh->do('DELETE FROM default_branch_item_rules');
892
    $dbh->do('DELETE FROM default_circ_rules');
893
894
    Koha::Items->search->delete;
895
    Koha::Biblios->search->delete;
896
897
    # Create item types
898
    my $itemtype1 = $builder->build_object( { class => 'Koha::ItemTypes' } );
899
    my $itemtype2 = $builder->build_object( { class => 'Koha::ItemTypes' } );
900
901
    # Create libraries
902
    my $library1  = $builder->build_object( { class => 'Koha::Libraries' } );
903
    my $library2  = $builder->build_object( { class => 'Koha::Libraries' } );
904
    my $library3  = $builder->build_object( { class => 'Koha::Libraries' } );
905
906
    # Create library groups hierarchy
907
    my $rootgroup  = $builder->build_object( { class => 'Koha::Library::Groups', value => {ft_local_hold_group => 1} } );
908
    my $group1  = $builder->build_object( { class => 'Koha::Library::Groups', value => {parent_id => $rootgroup->id, branchcode => $library1->branchcode}} );
909
    my $group2  = $builder->build_object( { class => 'Koha::Library::Groups', value => {parent_id => $rootgroup->id, branchcode => $library2->branchcode} } );
910
911
    # Create 2 patrons
912
    my $patron1   = $builder->build_object( { class => 'Koha::Patrons', value => {branchcode => $library1->branchcode} } );
913
    my $patron3   = $builder->build_object( { class => 'Koha::Patrons', value => {branchcode => $library3->branchcode} } );
914
915
    # Create 3 biblios with items
916
    my $biblio_1 = $builder->build_sample_biblio({ itemtype => $itemtype1->itemtype });
917
    my ( undef, undef, $itemnumber_1 ) = AddItem(
918
        {   homebranch    => $library1->branchcode,
919
            holdingbranch => $library1->branchcode
920
        },
921
        $biblio_1->biblionumber
922
    );
923
    my $biblio_2 = $builder->build_sample_biblio({ itemtype => $itemtype2->itemtype });
924
    my ( undef, undef, $itemnumber_2 ) = AddItem(
925
        {   homebranch    => $library2->branchcode,
926
            holdingbranch => $library2->branchcode
927
        },
928
        $biblio_2->biblionumber
929
    );
930
    my $biblio_3 = $builder->build_sample_biblio({ itemtype => $itemtype1->itemtype });
931
    my ( undef, undef, $itemnumber_3 ) = AddItem(
932
        {   homebranch    => $library1->branchcode,
933
            holdingbranch => $library1->branchcode
934
        },
935
        $biblio_3->biblionumber
936
    );
937
938
    # Test 1: Patron 3 can place hold
939
    is_deeply(
940
        CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2, $library3->branchcode ),
941
        { status => 'OK' },
942
        'Patron can place hold if no circ_rules where defined'
943
    );
944
945
    # Insert default circ rule of holds allowed only from local hold group for all libraries
946
    $dbh->do(
947
        q{INSERT INTO default_circ_rules (holdallowed, hold_fulfillment_policy, returnbranch)
948
        VALUES (?,?,?)},
949
        {},
950
        2, 'holdgroup', 'any'
951
    );
952
953
    # Test 2: Patron 1 can place hold
954
    is_deeply(
955
        CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2, $library1->branchcode ),
956
        { status => 'OK' },
957
        'Patron can place hold because pickup location is part of hold group'
958
    );
959
960
    # Test 3: Patron 3 cannot place hold
961
    is_deeply(
962
        CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2, $library3->branchcode ),
963
        { status => 'pickupNotInHoldGroup' },
964
        'Patron cannot place hold because pickup location is not part of hold group'
965
    );
966
967
    # Cleanup default_cirt_rules
968
    $dbh->do('DELETE FROM default_circ_rules');
969
970
    # Insert default circ rule to "any" for library 2
971
    $dbh->do(
972
        q{INSERT INTO default_branch_circ_rules (branchcode, holdallowed, hold_fulfillment_policy, returnbranch)
973
        VALUES (?,?,?,?)},
974
        {},
975
        $library2->branchcode, 2, 'any', 'any'
976
    );
977
978
    # Test 4: Patron 3 can place hold
979
    is_deeply(
980
        CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2, $library3->branchcode ),
981
        { status => 'OK' },
982
        'Patron can place hold if default_branch_circ_rules is set to "any" for library 2'
983
    );
984
985
    # Update default circ rule to "hold group" for library 2
986
    $dbh->do(
987
        q{UPDATE default_branch_circ_rules set hold_fulfillment_policy = ?
988
        WHERE branchcode = ?},
989
        {},
990
        'holdgroup', $library2->branchcode
991
    );
992
993
    # Test 5: Patron 3 cannot place hold
994
    is_deeply(
995
        CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2, $library3->branchcode ),
996
        { status => 'pickupNotInHoldGroup' },
997
        'Patron cannot place hold if hold_fulfillment_policy is set to "hold group" for library 2'
998
    );
999
1000
    # Cleanup default_branch_cirt_rules
1001
    $dbh->do('DELETE FROM default_branch_circ_rules');
1002
1003
    # Insert default item rule to "any" for itemtype 2
1004
    $dbh->do(
1005
        q{INSERT INTO default_branch_item_rules (itemtype, holdallowed, hold_fulfillment_policy, returnbranch)
1006
        VALUES (?,?,?,?)},
1007
        {},
1008
        $itemtype2->itemtype, 2, 'any', 'any'
1009
    );
1010
1011
    # Test 6: Patron 3 can place hold
1012
    is_deeply(
1013
        CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2, $library3->branchcode ),
1014
        { status => 'OK' },
1015
        'Patron can place hold if hold_fulfillment_policy is set to "any" for itemtype 2'
1016
    );
1017
1018
    # Update default item rule to "hold group" for itemtype 2
1019
    $dbh->do(
1020
        q{UPDATE default_branch_item_rules set hold_fulfillment_policy = ?
1021
        WHERE itemtype = ?},
1022
        {},
1023
        'holdgroup', $itemtype2->itemtype
1024
    );
1025
1026
    # Test 7: Patron 3 cannot place hold
1027
    is_deeply(
1028
        CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2, $library3->branchcode ),
1029
        { status => 'pickupNotInHoldGroup' },
1030
        'Patron cannot place hold if hold_fulfillment_policy is set to "hold group" for itemtype 2'
1031
    );
1032
1033
    # Cleanup default_branch_item_rules
1034
    $dbh->do('DELETE FROM default_branch_item_rules');
1035
1036
    # Insert branch item rule to "any" for itemtype 2 and library 2
1037
    $dbh->do(
1038
        q{INSERT INTO branch_item_rules (branchcode, itemtype, holdallowed, hold_fulfillment_policy, returnbranch)
1039
        VALUES (?,?,?,?,?)},
1040
        {},
1041
        $library2->branchcode, $itemtype2->itemtype, 2, 'any', 'any'
1042
    );
1043
1044
    # Test 8: Patron 3 can place hold
1045
    is_deeply(
1046
        CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2, $library3->branchcode ),
1047
        { status => 'OK' },
1048
        'Patron can place hold if hold_fulfillment_policy is set to "any" for itemtype 2 and library 2'
1049
    );
1050
1051
    # Update branch item rule to "hold group" for itemtype 2 and library 2
1052
    $dbh->do(
1053
        q{UPDATE branch_item_rules set hold_fulfillment_policy = ?
1054
        WHERE branchcode = ? and itemtype = ?},
1055
        {},
1056
        'holdgroup', $library2->branchcode, $itemtype2->itemtype
1057
    );
1058
1059
    # Test 9: Patron 3 cannot place hold
1060
    is_deeply(
1061
        CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2, $library3->branchcode ),
1062
        { status => 'pickupNotInHoldGroup' },
1063
        'Patron cannot place hold if hold_fulfillment_policy is set to "hold group" for itemtype 2 and library 2'
1064
    );
1065
1066
    $schema->storage->txn_rollback;
1067
};

Return to bug 22284