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

(-)a/C4/Reserves.pm (-33 / +3 lines)
Lines 134-141 BEGIN { Link Here
134
      ToggleSuspend
134
      ToggleSuspend
135
      SuspendAll
135
      SuspendAll
136
136
137
      GetReservesControlBranch
138
139
      CalculatePriority
137
      CalculatePriority
140
138
141
      IsItemOnHoldAndFound
139
      IsItemOnHoldAndFound
Lines 922-928 sub CheckReserves { Link Here
922
                    $item ||= Koha::Items->find($itemnumber);
920
                    $item ||= Koha::Items->find($itemnumber);
923
                    next if $res->{itemtype} && $res->{itemtype} ne $item->effective_itemtype;
921
                    next if $res->{itemtype} && $res->{itemtype} ne $item->effective_itemtype;
924
                    $patron ||= Koha::Patrons->find( $res->{borrowernumber} );
922
                    $patron ||= Koha::Patrons->find( $res->{borrowernumber} );
925
                    my $branch = GetReservesControlBranch( $item->unblessed, $patron->unblessed );
923
                    my $branch = $item->holds_control_library( $patron );
926
                    my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype);
924
                    my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype);
927
                    next if ($branchitemrule->{'holdallowed'} eq 'not_allowed');
925
                    next if ($branchitemrule->{'holdallowed'} eq 'not_allowed');
928
                    next if (($branchitemrule->{'holdallowed'} eq 'from_home_library') && ($item->homebranch ne $patron->branchcode));
926
                    next if (($branchitemrule->{'holdallowed'} eq 'from_home_library') && ($item->homebranch ne $patron->branchcode));
Lines 1343-1350 sub IsAvailableForItemLevelRequest { Link Here
1343
        return 0 unless $destination;
1341
        return 0 unless $destination;
1344
        return 0 unless $destination->pickup_location;
1342
        return 0 unless $destination->pickup_location;
1345
        return 0 unless $item->can_be_transferred( { to => $destination } );
1343
        return 0 unless $item->can_be_transferred( { to => $destination } );
1346
        my $reserves_control_branch =
1344
        my $reserves_control_branch = $item->holds_control_library( $patron );
1347
            GetReservesControlBranch( $item->unblessed(), $patron->unblessed() );
1348
        my $branchitemrule =
1345
        my $branchitemrule =
1349
            C4::Circulation::GetBranchItemRule( $reserves_control_branch, $item->itype );
1346
            C4::Circulation::GetBranchItemRule( $reserves_control_branch, $item->itype );
1350
        my $home_library = Koha::Libraries->find( {branchcode => $item->homebranch} );
1347
        my $home_library = Koha::Libraries->find( {branchcode => $item->homebranch} );
Lines 1386-1393 sub ItemsAnyAvailableAndNotRestricted { Link Here
1386
    my @items = Koha::Items->search( { biblionumber => $param->{biblionumber} } )->as_list;
1383
    my @items = Koha::Items->search( { biblionumber => $param->{biblionumber} } )->as_list;
1387
1384
1388
    foreach my $i (@items) {
1385
    foreach my $i (@items) {
1389
        my $reserves_control_branch =
1386
        my $reserves_control_branch = $i->holds_control_library( $param->{patron} );
1390
            GetReservesControlBranch( $i->unblessed(), $param->{patron}->unblessed );
1391
        my $branchitemrule =
1387
        my $branchitemrule =
1392
            C4::Circulation::GetBranchItemRule( $reserves_control_branch, $i->itype );
1388
            C4::Circulation::GetBranchItemRule( $reserves_control_branch, $i->itype );
1393
        my $item_library = Koha::Libraries->find( { branchcode => $i->homebranch } );
1389
        my $item_library = Koha::Libraries->find( { branchcode => $i->homebranch } );
Lines 2158-2189 sub ReserveSlip { Link Here
2158
    );
2154
    );
2159
}
2155
}
2160
2156
2161
=head2 GetReservesControlBranch
2162
2163
  my $reserves_control_branch = GetReservesControlBranch($item, $borrower);
2164
2165
  Return the branchcode to be used to determine which reserves
2166
  policy applies to a transaction.
2167
2168
  C<$item> is a hashref for an item. Only 'homebranch' is used.
2169
2170
  C<$borrower> is a hashref to borrower. Only 'branchcode' is used.
2171
2172
=cut
2173
2174
sub GetReservesControlBranch {
2175
    my ( $item, $borrower ) = @_;
2176
2177
    my $reserves_control = C4::Context->preference('ReservesControlBranch');
2178
2179
    my $branchcode =
2180
        ( $reserves_control eq 'ItemHomeLibrary' ) ? $item->{'homebranch'}
2181
      : ( $reserves_control eq 'PatronLibrary' )   ? $borrower->{'branchcode'}
2182
      :                                              undef;
2183
2184
    return $branchcode;
2185
}
2186
2187
=head2 CalculatePriority
2157
=head2 CalculatePriority
2188
2158
2189
    my $p = CalculatePriority($biblionumber, $resdate);
2159
    my $p = CalculatePriority($biblionumber, $resdate);
(-)a/opac/opac-reserve.pl (-3 / +2 lines)
Lines 24-30 use CGI qw ( -utf8 ); Link Here
24
use C4::Auth qw( get_template_and_user );
24
use C4::Auth qw( get_template_and_user );
25
use C4::Koha qw( getitemtypeimagelocation getitemtypeimagesrc );
25
use C4::Koha qw( getitemtypeimagelocation getitemtypeimagesrc );
26
use C4::Circulation qw( GetBranchItemRule GetTransfers );
26
use C4::Circulation qw( GetBranchItemRule GetTransfers );
27
use C4::Reserves qw( CanItemBeReserved CanBookBeReserved AddReserve GetReservesControlBranch ItemsAnyAvailableAndNotRestricted IsAvailableForItemLevelRequest );
27
use C4::Reserves qw( CanItemBeReserved CanBookBeReserved AddReserve ItemsAnyAvailableAndNotRestricted IsAvailableForItemLevelRequest );
28
use C4::Biblio qw( GetBiblioData GetFrameworkCode GetMarcBiblio );
28
use C4::Biblio qw( GetBiblioData GetFrameworkCode GetMarcBiblio );
29
use C4::Items qw( GetHostItemsInfo GetItemsInfo );
29
use C4::Items qw( GetHostItemsInfo GetItemsInfo );
30
use C4::Output qw( output_html_with_http_headers );
30
use C4::Output qw( output_html_with_http_headers );
Lines 559-566 foreach my $biblioNum (@biblionumbers) { Link Here
559
        # If there is no loan, return and transfer, we show a checkbox.
559
        # If there is no loan, return and transfer, we show a checkbox.
560
        $itemLoopIter->{notforloan} = $itemLoopIter->{notforloan} || 0;
560
        $itemLoopIter->{notforloan} = $itemLoopIter->{notforloan} || 0;
561
561
562
        my $patron_unblessed = $patron->unblessed;
562
        my $branch = $item->holds_control_library( $patron );
563
        my $branch = GetReservesControlBranch( $itemInfo, $patron_unblessed );
564
563
565
        my $policy_holdallowed = !$itemLoopIter->{already_reserved};
564
        my $policy_holdallowed = !$itemLoopIter->{already_reserved};
566
        # items_any_available defined outside of the current loop,
565
        # items_any_available defined outside of the current loop,
(-)a/t/db_dependent/Reserves.t (-20 / +2 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 71;
20
use Test::More tests => 69;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 31-37 use C4::Circulation qw( AddReturn AddIssue ); Link Here
31
use C4::Items;
31
use C4::Items;
32
use C4::Biblio qw( GetMarcBiblio GetMarcFromKohaField ModBiblio );
32
use C4::Biblio qw( GetMarcBiblio GetMarcFromKohaField ModBiblio );
33
use C4::Members;
33
use C4::Members;
34
use C4::Reserves qw( AddReserve AlterPriority CheckReserves GetReservesControlBranch ModReserve ModReserveAffect ReserveSlip CalculatePriority CanReserveBeCanceledFromOpac CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee RevertWaitingStatus CanItemBeReserved MergeHolds );
34
use C4::Reserves qw( AddReserve AlterPriority CheckReserves ModReserve ModReserveAffect ReserveSlip CalculatePriority CanReserveBeCanceledFromOpac CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee RevertWaitingStatus CanItemBeReserved MergeHolds );
35
use Koha::ActionLogs;
35
use Koha::ActionLogs;
36
use Koha::Caches;
36
use Koha::Caches;
37
use Koha::DateUtils qw( dt_from_string output_pref );
37
use Koha::DateUtils qw( dt_from_string output_pref );
Lines 131-153 is($status, "Reserved", "CheckReserves Test 2"); Link Here
131
($status, $reserve, $all_reserves) = CheckReserves(undef, $barcode);
131
($status, $reserve, $all_reserves) = CheckReserves(undef, $barcode);
132
is($status, "Reserved", "CheckReserves Test 3");
132
is($status, "Reserved", "CheckReserves Test 3");
133
133
134
my $ReservesControlBranch = C4::Context->preference('ReservesControlBranch');
135
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
136
ok(
137
    'ItemHomeLib' eq GetReservesControlBranch(
138
        { homebranch => 'ItemHomeLib' },
139
        { branchcode => 'PatronHomeLib' }
140
    ), "GetReservesControlBranch returns item home branch when set to ItemHomeLibrary"
141
);
142
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
143
ok(
144
    'PatronHomeLib' eq GetReservesControlBranch(
145
        { homebranch => 'ItemHomeLib' },
146
        { branchcode => 'PatronHomeLib' }
147
    ), "GetReservesControlBranch returns patron home branch when set to PatronLibrary"
148
);
149
t::lib::Mocks::mock_preference( 'ReservesControlBranch', $ReservesControlBranch );
150
151
###
134
###
152
### Regression test for bug 10272
135
### Regression test for bug 10272
153
###
136
###
154
- 

Return to bug 30825