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

(-)a/C4/Circulation.pm (-10 / +10 lines)
Lines 2662-2677 sub CanBookBeRenewed { Link Here
2662
            # can be filled with available items. We can get the union of the sets simply
2662
            # can be filled with available items. We can get the union of the sets simply
2663
            # by pushing all the elements onto an array and removing the duplicates.
2663
            # by pushing all the elements onto an array and removing the duplicates.
2664
            my @reservable;
2664
            my @reservable;
2665
            my %borrowers;
2665
            my %patrons;
2666
            ITEM: foreach my $i (@itemnumbers) {
2666
            ITEM: foreach my $itemnumber (@itemnumbers) {
2667
                my $item = Koha::Items->find($i)->unblessed;
2667
                my $item = Koha::Items->find( $itemnumber );
2668
                next if IsItemOnHoldAndFound($i);
2668
                next if IsItemOnHoldAndFound( $itemnumber );
2669
                for my $b (@borrowernumbers) {
2669
                for my $borrowernumber (@borrowernumbers) {
2670
                    my $borr = $borrowers{$b} //= Koha::Patrons->find( $b )->unblessed;
2670
                    my $patron = $patrons{$borrowernumber} //= Koha::Patrons->find( $borrowernumber );
2671
                    next unless IsAvailableForItemLevelRequest($item, $borr);
2671
                    next unless IsAvailableForItemLevelRequest($item, $patron);
2672
                    next unless CanItemBeReserved($b,$i);
2672
                    next unless CanItemBeReserved($borrowernumber,$itemnumber);
2673
2673
2674
                    push @reservable, $i;
2674
                    push @reservable, $itemnumber;
2675
                    if (@reservable >= @borrowernumbers) {
2675
                    if (@reservable >= @borrowernumbers) {
2676
                        $resfound = 0;
2676
                        $resfound = 0;
2677
                        last ITEM;
2677
                        last ITEM;
(-)a/C4/ILSDI/Services.pm (-1 / +1 lines)
Lines 562-568 sub GetServices { Link Here
562
    my $canbookbereserved = CanBookBeReserved( $borrower, $biblionumber );
562
    my $canbookbereserved = CanBookBeReserved( $borrower, $biblionumber );
563
    if ($canbookbereserved->{status} eq 'OK') {
563
    if ($canbookbereserved->{status} eq 'OK') {
564
        push @availablefor, 'title level hold';
564
        push @availablefor, 'title level hold';
565
        my $canitembereserved = IsAvailableForItemLevelRequest($item->unblessed, $borrower);
565
        my $canitembereserved = IsAvailableForItemLevelRequest($item, $patron);
566
        if ($canitembereserved) {
566
        if ($canitembereserved) {
567
            push @availablefor, 'item level hold';
567
            push @availablefor, 'item level hold';
568
        }
568
        }
(-)a/C4/Reserves.pm (-16 / +12 lines)
Lines 1162-1210 and canreservefromotherbranches. Link Here
1162
=cut
1162
=cut
1163
1163
1164
sub IsAvailableForItemLevelRequest {
1164
sub IsAvailableForItemLevelRequest {
1165
    my $item = shift;
1165
    my ( $item, $patron, $pickup_branchcode ) = @_;
1166
    my $borrower = shift;
1167
    my $pickup_branchcode = shift;
1168
1166
1169
    my $dbh = C4::Context->dbh;
1167
    my $dbh = C4::Context->dbh;
1170
    # must check the notforloan setting of the itemtype
1168
    # must check the notforloan setting of the itemtype
1171
    # FIXME - a lot of places in the code do this
1169
    # FIXME - a lot of places in the code do this
1172
    #         or something similar - need to be
1170
    #         or something similar - need to be
1173
    #         consolidated
1171
    #         consolidated
1174
    my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
1172
    my $itemtype = $item->effective_itemtype;
1175
    my $item_object = Koha::Items->find( $item->{itemnumber } );
1176
    my $itemtype = $item_object->effective_itemtype;
1177
    my $notforloan_per_itemtype
1173
    my $notforloan_per_itemtype
1178
      = $dbh->selectrow_array("SELECT notforloan FROM itemtypes WHERE itemtype = ?",
1174
      = $dbh->selectrow_array("SELECT notforloan FROM itemtypes WHERE itemtype = ?",
1179
                              undef, $itemtype);
1175
                              undef, $itemtype);
1180
1176
1181
    return 0 if
1177
    return 0 if
1182
        $notforloan_per_itemtype ||
1178
        $notforloan_per_itemtype ||
1183
        $item->{itemlost}        ||
1179
        $item->itemlost        ||
1184
        $item->{notforloan} > 0  ||
1180
        $item->notforloan > 0  ||
1185
        $item->{withdrawn}        ||
1181
        $item->withdrawn        ||
1186
        ($item->{damaged} && !C4::Context->preference('AllowHoldsOnDamagedItems'));
1182
        ($item->damaged && !C4::Context->preference('AllowHoldsOnDamagedItems'));
1187
1183
1188
    my $on_shelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item_object, patron => $patron } );
1184
    my $on_shelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } );
1189
1185
1190
    if ($pickup_branchcode) {
1186
    if ($pickup_branchcode) {
1191
        my $destination = Koha::Libraries->find($pickup_branchcode);
1187
        my $destination = Koha::Libraries->find($pickup_branchcode);
1192
        return 0 unless $destination;
1188
        return 0 unless $destination;
1193
        return 0 unless $destination->pickup_location;
1189
        return 0 unless $destination->pickup_location;
1194
        return 0 unless $item_object->can_be_transferred( { to => $destination } );
1190
        return 0 unless $item->can_be_transferred( { to => $destination } );
1195
    }
1191
    }
1196
1192
1197
    if ( $on_shelf_holds == 1 ) {
1193
    if ( $on_shelf_holds == 1 ) {
1198
        return 1;
1194
        return 1;
1199
    } elsif ( $on_shelf_holds == 2 ) {
1195
    } elsif ( $on_shelf_holds == 2 ) {
1200
        my @items =
1196
        my @items =
1201
          Koha::Items->search( { biblionumber => $item->{biblionumber} } );
1197
          Koha::Items->search( { biblionumber => $item->biblionumber } );
1202
1198
1203
        my $any_available = 0;
1199
        my $any_available = 0;
1204
1200
1205
        foreach my $i (@items) {
1201
        foreach my $i (@items) {
1206
1202
1207
            my $circ_control_branch = C4::Circulation::_GetCircControlBranch( $i->unblessed(), $borrower );
1203
            my $circ_control_branch = C4::Circulation::_GetCircControlBranch( $i->unblessed(), $patron->unblessed );
1208
            my $branchitemrule = C4::Circulation::GetBranchItemRule( $circ_control_branch, $i->itype );
1204
            my $branchitemrule = C4::Circulation::GetBranchItemRule( $circ_control_branch, $i->itype );
1209
1205
1210
            $any_available = 1
1206
            $any_available = 1
Lines 1216-1227 sub IsAvailableForItemLevelRequest { Link Here
1216
              || ( $i->damaged
1212
              || ( $i->damaged
1217
                && !C4::Context->preference('AllowHoldsOnDamagedItems') )
1213
                && !C4::Context->preference('AllowHoldsOnDamagedItems') )
1218
              || Koha::ItemTypes->find( $i->effective_itemtype() )->notforloan
1214
              || Koha::ItemTypes->find( $i->effective_itemtype() )->notforloan
1219
              || $branchitemrule->{holdallowed} == 1 && $borrower->{branchcode} ne $i->homebranch;
1215
              || $branchitemrule->{holdallowed} == 1 && $patron->branchcode ne $i->homebranch;
1220
        }
1216
        }
1221
1217
1222
        return $any_available ? 0 : 1;
1218
        return $any_available ? 0 : 1;
1223
    } else { # on_shelf_holds == 0 "If any unavailable" (the description is rather cryptic and could still be improved)
1219
    } else { # on_shelf_holds == 0 "If any unavailable" (the description is rather cryptic and could still be improved)
1224
        return $item->{onloan} || IsItemOnHoldAndFound( $item->{itemnumber} );
1220
        return $item->onloan || IsItemOnHoldAndFound( $item->itemnumber );
1225
    }
1221
    }
1226
}
1222
}
1227
1223
(-)a/opac/opac-reserve.pl (-1 / +1 lines)
Lines 542-548 foreach my $biblioNum (@biblionumbers) { Link Here
542
542
543
        my $policy_holdallowed = !$itemLoopIter->{already_reserved};
543
        my $policy_holdallowed = !$itemLoopIter->{already_reserved};
544
        $policy_holdallowed &&=
544
        $policy_holdallowed &&=
545
            IsAvailableForItemLevelRequest($itemInfo,$patron_unblessed) &&
545
            IsAvailableForItemLevelRequest($item, $patron) &&
546
            CanItemBeReserved( $borrowernumber, $itemNum )->{status} eq 'OK';
546
            CanItemBeReserved( $borrowernumber, $itemNum )->{status} eq 'OK';
547
547
548
        if ($policy_holdallowed) {
548
        if ($policy_holdallowed) {
(-)a/reserve/request.pl (-1 / +1 lines)
Lines 481-487 foreach my $biblionumber (@biblionumbers) { Link Here
481
                if (
481
                if (
482
                       !$item->{cantreserve}
482
                       !$item->{cantreserve}
483
                    && !$exceeded_maxreserves
483
                    && !$exceeded_maxreserves
484
                    && IsAvailableForItemLevelRequest($item, $patron_unblessed)
484
                    && IsAvailableForItemLevelRequest($item_object, $patron)
485
                    && $can_item_be_reserved->{status} eq 'OK'
485
                    && $can_item_be_reserved->{status} eq 'OK'
486
                  )
486
                  )
487
                {
487
                {
(-)a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t (-48 / +25 lines)
Lines 35-50 t::lib::Mocks::mock_userenv({ branchcode => $library1->{branchcode} }); Link Here
35
35
36
my $bib_title = "Test Title";
36
my $bib_title = "Test Title";
37
37
38
my $borrower1 = $builder->build({
38
my $patron1 = $builder->build_object({
39
    source => 'Borrower',
39
    class => 'Koha::Patrons',
40
    value => {
40
    value => {
41
        branchcode => $library1->{branchcode},
41
        branchcode => $library1->{branchcode},
42
        dateexpiry => '3000-01-01',
42
        dateexpiry => '3000-01-01',
43
    }
43
    }
44
});
44
});
45
my $borrower1 = $patron1->unblessed;
45
46
46
my $borrower2 = $builder->build({
47
my $patron2 = $builder->build_object({
47
    source => 'Borrower',
48
    class => 'Koha::Patrons',
48
    value => {
49
    value => {
49
        branchcode => $library1->{branchcode},
50
        branchcode => $library1->{branchcode},
50
        dateexpiry => '3000-01-01',
51
        dateexpiry => '3000-01-01',
Lines 53-60 my $borrower2 = $builder->build({ Link Here
53
54
54
# Test hold_fulfillment_policy
55
# Test hold_fulfillment_policy
55
my ( $itemtype ) = @{ $dbh->selectrow_arrayref("SELECT itemtype FROM itemtypes LIMIT 1") };
56
my ( $itemtype ) = @{ $dbh->selectrow_arrayref("SELECT itemtype FROM itemtypes LIMIT 1") };
56
my $borrowernumber1 = $borrower1->{borrowernumber};
57
my $borrowernumber2 = $borrower2->{borrowernumber};
58
my $library_A = $library1->{branchcode};
57
my $library_A = $library1->{branchcode};
59
my $library_B = $library2->{branchcode};
58
my $library_B = $library2->{branchcode};
60
59
Lines 69-95 my $biblioitemnumber = Link Here
69
  $dbh->selectrow_array("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber = $biblionumber")
68
  $dbh->selectrow_array("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber = $biblionumber")
70
  or BAIL_OUT("Cannot find newly created biblioitems record");
69
  or BAIL_OUT("Cannot find newly created biblioitems record");
71
70
72
$dbh->do("
71
my $item1 = $builder->build_object({ class => 'Koha::Items', value => { barcode => 'AllowHoldIf1', biblionumber => $biblionumber, biblioitemnumber => $biblioitemnumber, homebranch => $library_A, holdingbranch => $library_A, notforloan => 0, damaged => 0, itemlost => 0, withdrawn => 0, onloan => undef, itype => $itemtype } });
73
    INSERT INTO items (barcode, biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype)
74
    VALUES ('AllowHoldIf1', $biblionumber, $biblioitemnumber, '$library_A', '$library_A', 0, 0, 0, 0, NULL, '$itemtype')
75
");
76
72
77
my $itemnumber1 =
73
my $item2 = $builder->build_object({ class => 'Koha::Items', value => { barcode => 'AllowHoldIf2', biblionumber => $biblionumber, biblioitemnumber => $biblioitemnumber, homebranch => $library_A, holdingbranch => $library_A, notforloan => 0, damaged => 0, itemlost => 0, withdrawn => 0, onloan => undef, itype => $itemtype } });
78
  $dbh->selectrow_array("SELECT itemnumber FROM items WHERE biblionumber = $biblionumber")
79
  or BAIL_OUT("Cannot find newly created item");
80
81
my $item1 = Koha::Items->find( $itemnumber1 )->unblessed;
82
83
$dbh->do("
84
    INSERT INTO items (barcode, biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype)
85
    VALUES ('AllowHoldIf2', $biblionumber, $biblioitemnumber, '$library_A', '$library_A', 0, 0, 0, 0, NULL, '$itemtype')
86
");
87
88
my $itemnumber2 =
89
  $dbh->selectrow_array("SELECT itemnumber FROM items WHERE biblionumber = $biblionumber ORDER BY itemnumber DESC")
90
  or BAIL_OUT("Cannot find newly created item");
91
92
my $item2 = Koha::Items->find( $itemnumber2 )->unblessed;
93
74
94
$dbh->do("DELETE FROM issuingrules");
75
$dbh->do("DELETE FROM issuingrules");
95
my $rule = Koha::IssuingRule->new(
76
my $rule = Koha::IssuingRule->new(
Lines 105-124 my $rule = Koha::IssuingRule->new( Link Here
105
);
86
);
106
$rule->store();
87
$rule->store();
107
88
108
my $is = IsAvailableForItemLevelRequest( $item1, $borrower1);
89
my $is = IsAvailableForItemLevelRequest( $item1, $patron1);
109
is( $is, 0, "Item cannot be held, 2 items available" );
90
is( $is, 0, "Item cannot be held, 2 items available" );
110
91
111
my $issue1 = AddIssue( $borrower2, $item1->{barcode} );
92
my $issue1 = AddIssue( $patron2->unblessed, $item1->barcode );
112
93
113
$is = IsAvailableForItemLevelRequest( $item1, $borrower1);
94
$is = IsAvailableForItemLevelRequest( $item1, $patron1);
114
is( $is, 0, "Item cannot be held, 1 item available" );
95
is( $is, 0, "Item cannot be held, 1 item available" );
115
96
116
AddIssue( $borrower2, $item2->{barcode} );
97
AddIssue( $patron2->unblessed, $item2->barcode );
117
98
118
$is = IsAvailableForItemLevelRequest( $item1, $borrower1);
99
$is = IsAvailableForItemLevelRequest( $item1, $patron1);
119
is( $is, 1, "Item can be held, no items available" );
100
is( $is, 1, "Item can be held, no items available" );
120
101
121
AddReturn( $item1->{barcode} );
102
AddReturn( $item1->barcode );
122
103
123
{ # Remove the issue for the first patron, and modify the branch for item1
104
{ # Remove the issue for the first patron, and modify the branch for item1
124
    subtest 'IsAvailableForItemLevelRequest behaviours depending on ReservesControlBranch + holdallowed' => sub {
105
    subtest 'IsAvailableForItemLevelRequest behaviours depending on ReservesControlBranch + holdallowed' => sub {
Lines 132-140 AddReturn( $item1->{barcode} ); Link Here
132
        subtest 'Item is available at a different library' => sub {
113
        subtest 'Item is available at a different library' => sub {
133
            plan tests => 4;
114
            plan tests => 4;
134
115
135
            $item1 = Koha::Items->find( $item1->{itemnumber} );
136
            $item1->set({homebranch => $library_B, holdingbranch => $library_B })->store;
116
            $item1->set({homebranch => $library_B, holdingbranch => $library_B })->store;
137
            $item1 = $item1->unblessed;
138
            #Scenario is:
117
            #Scenario is:
139
            #One shelf holds is 'If all unavailable'/2
118
            #One shelf holds is 'If all unavailable'/2
140
            #Item 1 homebranch library B is available
119
            #Item 1 homebranch library B is available
Lines 148-158 AddReturn( $item1->{barcode} ); Link Here
148
                $sth_insert_rule->execute( $hold_allowed_from_home_library );
127
                $sth_insert_rule->execute( $hold_allowed_from_home_library );
149
128
150
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
129
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
151
                $is = IsAvailableForItemLevelRequest( $item1, $borrower1);
130
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
152
                is( $is, 1, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at different library, not holdable = none available => the hold is allowed at item level" );
131
                is( $is, 1, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at different library, not holdable = none available => the hold is allowed at item level" );
153
132
154
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary');
133
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary');
155
                $is = IsAvailableForItemLevelRequest( $item1, $borrower1);
134
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
156
                is( $is, 1, "Hold allowed from home library + ReservesControlBranch=PatronLibrary, One item is available at different library, not holdable = none available => the hold is allowed at item level" );
135
                is( $is, 1, "Hold allowed from home library + ReservesControlBranch=PatronLibrary, One item is available at different library, not holdable = none available => the hold is allowed at item level" );
157
            }
136
            }
158
137
Lines 161-171 AddReturn( $item1->{barcode} ); Link Here
161
                $sth_insert_rule->execute( $hold_allowed_from_any_libraries );
140
                $sth_insert_rule->execute( $hold_allowed_from_any_libraries );
162
141
163
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
142
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
164
                $is = IsAvailableForItemLevelRequest( $item1, $borrower1);
143
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
165
                is( $is, 0, "Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level" );
144
                is( $is, 0, "Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level" );
166
145
167
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary');
146
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary');
168
                $is = IsAvailableForItemLevelRequest( $item1, $borrower1);
147
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
169
                is( $is, 0, "Hold allowed from any library + ReservesControlBranch=PatronLibrary, One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level" );
148
                is( $is, 0, "Hold allowed from any library + ReservesControlBranch=PatronLibrary, One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level" );
170
            }
149
            }
171
        };
150
        };
Lines 173-181 AddReturn( $item1->{barcode} ); Link Here
173
        subtest 'Item is available at the same library' => sub {
152
        subtest 'Item is available at the same library' => sub {
174
            plan tests => 4;
153
            plan tests => 4;
175
154
176
            $item1 = Koha::Items->find( $item1->{itemnumber} );
177
            $item1->set({homebranch => $library_A, holdingbranch => $library_A })->store;
155
            $item1->set({homebranch => $library_A, holdingbranch => $library_A })->store;
178
            $item1 = $item1->unblessed;
179
            #Scenario is:
156
            #Scenario is:
180
            #One shelf holds is 'If all unavailable'/2
157
            #One shelf holds is 'If all unavailable'/2
181
            #Item 1 homebranch library A is available
158
            #Item 1 homebranch library A is available
Lines 189-199 AddReturn( $item1->{barcode} ); Link Here
189
                $sth_insert_rule->execute( $hold_allowed_from_home_library );
166
                $sth_insert_rule->execute( $hold_allowed_from_home_library );
190
167
191
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
168
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
192
                $is = IsAvailableForItemLevelRequest( $item1, $borrower1);
169
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
193
                is( $is, 0, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at the same library, holdable = 1 available  => the hold is not allowed at item level" );
170
                is( $is, 0, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at the same library, holdable = 1 available  => the hold is not allowed at item level" );
194
171
195
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary');
172
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary');
196
                $is = IsAvailableForItemLevelRequest( $item1, $borrower1);
173
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
197
                is( $is, 0, "Hold allowed from home library + ReservesControlBranch=PatronLibrary, One item is available at the same library, holdable = 1 available  => the hold is not allowed at item level" );
174
                is( $is, 0, "Hold allowed from home library + ReservesControlBranch=PatronLibrary, One item is available at the same library, holdable = 1 available  => the hold is not allowed at item level" );
198
            }
175
            }
199
176
Lines 202-212 AddReturn( $item1->{barcode} ); Link Here
202
                $sth_insert_rule->execute( $hold_allowed_from_any_libraries );
179
                $sth_insert_rule->execute( $hold_allowed_from_any_libraries );
203
180
204
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
181
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
205
                $is = IsAvailableForItemLevelRequest( $item1, $borrower1);
182
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
206
                is( $is, 0, "Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, One item is available at the same library, holdable = 1 available => the hold is not allowed at item level" );
183
                is( $is, 0, "Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, One item is available at the same library, holdable = 1 available => the hold is not allowed at item level" );
207
184
208
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary');
185
                t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary');
209
                $is = IsAvailableForItemLevelRequest( $item1, $borrower1);
186
                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
210
                is( $is, 0, "Hold allowed from any library + ReservesControlBranch=PatronLibrary, One item is available at the same library, holdable = 1 available  => the hold is not allowed at item level" );
187
                is( $is, 0, "Hold allowed from any library + ReservesControlBranch=PatronLibrary, One item is available at the same library, holdable = 1 available  => the hold is not allowed at item level" );
211
            }
188
            }
212
        };
189
        };
Lines 217-224 my $biblio = $builder->build({ Link Here
217
    source => 'Biblio',
194
    source => 'Biblio',
218
});
195
});
219
196
220
my $item3 = $builder->build({
197
my $item3 = $builder->build_object({
221
    source => 'Item',
198
    class => 'Koha::Items',
222
    value => {
199
    value => {
223
        biblionumber => $biblio->{biblionumber},
200
        biblionumber => $biblio->{biblionumber},
224
        itemlost     => 0,
201
        itemlost     => 0,
Lines 232-238 my $item3 = $builder->build({ Link Here
232
my $hold = $builder->build({
209
my $hold = $builder->build({
233
    source => 'Reserve',
210
    source => 'Reserve',
234
    value =>{
211
    value =>{
235
        itemnumber => $item3->{itemnumber},
212
        itemnumber => $item3->itemnumber,
236
        found => 'T'
213
        found => 'T'
237
    }
214
    }
238
});
215
});
Lines 251-257 $rule = Koha::IssuingRule->new( Link Here
251
);
228
);
252
$rule->store();
229
$rule->store();
253
230
254
$is = IsAvailableForItemLevelRequest( $item3, $borrower1);
231
$is = IsAvailableForItemLevelRequest( $item3, $patron1);
255
is( $is, 1, "Item can be held, items in transit are not available" );
232
is( $is, 1, "Item can be held, items in transit are not available" );
256
233
257
# Cleanup
234
# Cleanup
(-)a/t/db_dependent/Reserves.t (-11 / +10 lines)
Lines 109-115 my %data = ( Link Here
109
);
109
);
110
Koha::Patron::Categories->find($category_1)->set({ enrolmentfee => 0})->store;
110
Koha::Patron::Categories->find($category_1)->set({ enrolmentfee => 0})->store;
111
my $borrowernumber = Koha::Patron->new(\%data)->store->borrowernumber;
111
my $borrowernumber = Koha::Patron->new(\%data)->store->borrowernumber;
112
my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
112
my $patron = Koha::Patrons->find( $borrowernumber );
113
my $borrower = $patron->unblessed;
113
my $biblionumber   = $bibnum;
114
my $biblionumber   = $bibnum;
114
my $barcode        = $testbarcode;
115
my $barcode        = $testbarcode;
115
116
Lines 520-541 is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblio_with_no_item->{bibl Link Here
520
####### EO Bug 13113 <<<
521
####### EO Bug 13113 <<<
521
       ####
522
       ####
522
523
523
$item = Koha::Items->find($itemnumber)->unblessed;
524
$item = Koha::Items->find($itemnumber);
524
525
525
ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $borrower), "Reserving a book on item level" );
526
ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $patron), "Reserving a book on item level" );
526
527
527
my $pickup_branch = $builder->build({ source => 'Branch' })->{ branchcode };
528
my $pickup_branch = $builder->build({ source => 'Branch' })->{ branchcode };
528
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits',  '1' );
529
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits',  '1' );
529
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
530
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
530
my ($item_object) = Koha::Biblios->find($biblionumber)->items;
531
my $limit = Koha::Item::Transfer::Limit->new(
531
my $limit = Koha::Item::Transfer::Limit->new(
532
    {
532
    {
533
        toBranch   => $pickup_branch,
533
        toBranch   => $pickup_branch,
534
        fromBranch => $item_object->holdingbranch,
534
        fromBranch => $item->holdingbranch,
535
        itemtype   => $item_object->effective_itemtype,
535
        itemtype   => $item->effective_itemtype,
536
    }
536
    }
537
)->store();
537
)->store();
538
is( C4::Reserves::IsAvailableForItemLevelRequest($item, $borrower, $pickup_branch), 0, "Item level request not available due to transfer limit" );
538
is( C4::Reserves::IsAvailableForItemLevelRequest($item, $patron, $pickup_branch), 0, "Item level request not available due to transfer limit" );
539
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits',  '0' );
539
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits',  '0' );
540
540
541
# tests for MoveReserve in relation to ConfirmFutureHolds (BZ 14526)
541
# tests for MoveReserve in relation to ConfirmFutureHolds (BZ 14526)
Lines 643-652 subtest '_koha_notify_reserve() tests' => sub { Link Here
643
        })->{borrowernumber};
643
        })->{borrowernumber};
644
644
645
    C4::Reserves::AddReserve(
645
    C4::Reserves::AddReserve(
646
        $item->{homebranch}, $hold_borrower,
646
        $item->homebranch, $hold_borrower,
647
        $item->{biblionumber} );
647
        $item->biblionumber );
648
648
649
    ModReserveAffect($item->{itemnumber}, $hold_borrower, 0);
649
    ModReserveAffect($item->itemnumber, $hold_borrower, 0);
650
    my $sms_message_address = $schema->resultset('MessageQueue')->search({
650
    my $sms_message_address = $schema->resultset('MessageQueue')->search({
651
            letter_code     => 'HOLD',
651
            letter_code     => 'HOLD',
652
            message_transport_type => 'sms',
652
            message_transport_type => 'sms',
653
- 

Return to bug 19302