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 939-945 sub CheckReserves { Link Here
939
                    next if $res->{item_group_id} && ( !$item->item_group || $item->item_group->id != $res->{item_group_id} );
937
                    next if $res->{item_group_id} && ( !$item->item_group || $item->item_group->id != $res->{item_group_id} );
940
                    next if $res->{itemtype} && $res->{itemtype} ne $item->effective_itemtype;
938
                    next if $res->{itemtype} && $res->{itemtype} ne $item->effective_itemtype;
941
                    $patron //= Koha::Patrons->find( $res->{borrowernumber} );
939
                    $patron //= Koha::Patrons->find( $res->{borrowernumber} );
942
                    my $branch = GetReservesControlBranch( $item->unblessed, $patron->unblessed );
940
                    my $branch = $item->holds_control_library( $patron );
943
                    my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype);
941
                    my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype);
944
                    next if ($branchitemrule->{'holdallowed'} eq 'not_allowed');
942
                    next if ($branchitemrule->{'holdallowed'} eq 'not_allowed');
945
                    next if (($branchitemrule->{'holdallowed'} eq 'from_home_library') && ($item->homebranch ne $patron->branchcode));
943
                    next if (($branchitemrule->{'holdallowed'} eq 'from_home_library') && ($item->homebranch ne $patron->branchcode));
Lines 1359-1366 sub IsAvailableForItemLevelRequest { Link Here
1359
        return 0 unless $destination;
1357
        return 0 unless $destination;
1360
        return 0 unless $destination->pickup_location;
1358
        return 0 unless $destination->pickup_location;
1361
        return 0 unless $item->can_be_transferred( { to => $destination } );
1359
        return 0 unless $item->can_be_transferred( { to => $destination } );
1362
        my $reserves_control_branch =
1360
        my $reserves_control_branch = $item->holds_control_library( $patron );
1363
            GetReservesControlBranch( $item->unblessed(), $patron->unblessed() );
1364
        my $branchitemrule =
1361
        my $branchitemrule =
1365
            C4::Circulation::GetBranchItemRule( $reserves_control_branch, $item->itype );
1362
            C4::Circulation::GetBranchItemRule( $reserves_control_branch, $item->itype );
1366
        my $home_library = Koha::Libraries->find( {branchcode => $item->homebranch} );
1363
        my $home_library = Koha::Libraries->find( {branchcode => $item->homebranch} );
Lines 1409-1416 sub ItemsAnyAvailableAndNotRestricted { Link Here
1409
    my @items = Koha::Items->search( { biblionumber => $param->{biblionumber} } )->as_list;
1406
    my @items = Koha::Items->search( { biblionumber => $param->{biblionumber} } )->as_list;
1410
1407
1411
    foreach my $i (@items) {
1408
    foreach my $i (@items) {
1412
        my $reserves_control_branch =
1409
        my $reserves_control_branch = $i->holds_control_library( $param->{patron} );
1413
            GetReservesControlBranch( $i->unblessed(), $param->{patron}->unblessed );
1414
        my $branchitemrule =
1410
        my $branchitemrule =
1415
            C4::Circulation::GetBranchItemRule( $reserves_control_branch, $i->itype );
1411
            C4::Circulation::GetBranchItemRule( $reserves_control_branch, $i->itype );
1416
        my $item_library = Koha::Libraries->find( { branchcode => $i->homebranch } );
1412
        my $item_library = Koha::Libraries->find( { branchcode => $i->homebranch } );
Lines 2185-2216 sub ReserveSlip { Link Here
2185
    );
2181
    );
2186
}
2182
}
2187
2183
2188
=head2 GetReservesControlBranch
2189
2190
  my $reserves_control_branch = GetReservesControlBranch($item, $borrower);
2191
2192
  Return the branchcode to be used to determine which reserves
2193
  policy applies to a transaction.
2194
2195
  C<$item> is a hashref for an item. Only 'homebranch' is used.
2196
2197
  C<$borrower> is a hashref to borrower. Only 'branchcode' is used.
2198
2199
=cut
2200
2201
sub GetReservesControlBranch {
2202
    my ( $item, $borrower ) = @_;
2203
2204
    my $reserves_control = C4::Context->preference('ReservesControlBranch');
2205
2206
    my $branchcode =
2207
        ( $reserves_control eq 'ItemHomeLibrary' ) ? $item->{'homebranch'}
2208
      : ( $reserves_control eq 'PatronLibrary' )   ? $borrower->{'branchcode'}
2209
      :                                              undef;
2210
2211
    return $branchcode;
2212
}
2213
2214
=head2 CalculatePriority
2184
=head2 CalculatePriority
2215
2185
2216
    my $p = CalculatePriority($biblionumber, $resdate);
2186
    my $p = CalculatePriority($biblionumber, $resdate);
(-)a/opac/opac-reserve.pl (-2 / +2 lines)
Lines 25-31 use CGI qw ( -utf8 ); Link Here
25
use C4::Auth qw( get_template_and_user );
25
use C4::Auth qw( get_template_and_user );
26
use C4::Koha qw( getitemtypeimagelocation getitemtypeimagesrc );
26
use C4::Koha qw( getitemtypeimagelocation getitemtypeimagesrc );
27
use C4::Circulation qw( GetBranchItemRule );
27
use C4::Circulation qw( GetBranchItemRule );
28
use C4::Reserves qw( CanItemBeReserved CanBookBeReserved AddReserve GetReservesControlBranch IsAvailableForItemLevelRequest GetReserveFee );
28
use C4::Reserves qw( CanItemBeReserved CanBookBeReserved AddReserve IsAvailableForItemLevelRequest GetReserveFee );
29
use C4::Biblio qw( GetBiblioData GetFrameworkCode );
29
use C4::Biblio qw( GetBiblioData GetFrameworkCode );
30
use C4::Output qw( output_html_with_http_headers );
30
use C4::Output qw( output_html_with_http_headers );
31
use C4::Context;
31
use C4::Context;
Lines 477-483 foreach my $biblioNum (@biblionumbers) { Link Here
477
            $item_info->{hosttitle}        = Koha::Biblios->find( $item_info->{biblionumber} )->title;
477
            $item_info->{hosttitle}        = Koha::Biblios->find( $item_info->{biblionumber} )->title;
478
        }
478
        }
479
479
480
        my $branch = GetReservesControlBranch( $item_info, $patron_unblessed );
480
        my $branch = $item->holds_control_library( $patron );
481
481
482
        my $policy_holdallowed =
482
        my $policy_holdallowed =
483
            CanItemBeReserved( $patron, $item, undef, { get_from_cache => 1 } )->{status} eq 'OK' &&
483
            CanItemBeReserved( $patron, $item, undef, { get_from_cache => 1 } )->{status} eq 'OK' &&
(-)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 => 78;
20
use Test::More tests => 76;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 32-38 use C4::Items; Link Here
32
use C4::Biblio qw( GetMarcFromKohaField ModBiblio );
32
use C4::Biblio qw( GetMarcFromKohaField ModBiblio );
33
use C4::HoldsQueue;
33
use C4::HoldsQueue;
34
use C4::Members;
34
use C4::Members;
35
use C4::Reserves qw( AddReserve AlterPriority CheckReserves GetReservesControlBranch ModReserve ModReserveAffect ReserveSlip CalculatePriority CanReserveBeCanceledFromOpac CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee RevertWaitingStatus CanItemBeReserved MergeHolds );
35
use C4::Reserves qw( AddReserve AlterPriority CheckReserves ModReserve ModReserveAffect ReserveSlip CalculatePriority CanReserveBeCanceledFromOpac CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee RevertWaitingStatus CanItemBeReserved MergeHolds );
36
use Koha::ActionLogs;
36
use Koha::ActionLogs;
37
use Koha::Biblios;
37
use Koha::Biblios;
38
use Koha::Caches;
38
use Koha::Caches;
Lines 129-151 ok(exists($reserve->{reserve_id}), 'CheckReserves() include reserve_id in its re Link Here
129
($status, $reserve, $all_reserves) = CheckReserves( $item );
129
($status, $reserve, $all_reserves) = CheckReserves( $item );
130
is($status, "Reserved", "CheckReserves Test 2");
130
is($status, "Reserved", "CheckReserves Test 2");
131
131
132
my $ReservesControlBranch = C4::Context->preference('ReservesControlBranch');
133
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
134
ok(
135
    'ItemHomeLib' eq GetReservesControlBranch(
136
        { homebranch => 'ItemHomeLib' },
137
        { branchcode => 'PatronHomeLib' }
138
    ), "GetReservesControlBranch returns item home branch when set to ItemHomeLibrary"
139
);
140
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
141
ok(
142
    'PatronHomeLib' eq GetReservesControlBranch(
143
        { homebranch => 'ItemHomeLib' },
144
        { branchcode => 'PatronHomeLib' }
145
    ), "GetReservesControlBranch returns patron home branch when set to PatronLibrary"
146
);
147
t::lib::Mocks::mock_preference( 'ReservesControlBranch', $ReservesControlBranch );
148
149
###
132
###
150
### Regression test for bug 10272
133
### Regression test for bug 10272
151
###
134
###
152
- 

Return to bug 30825