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

(-)a/C4/Reserves.pm (-33 / +3 lines)
Lines 133-140 BEGIN { Link Here
133
      ToggleSuspend
133
      ToggleSuspend
134
      SuspendAll
134
      SuspendAll
135
135
136
      GetReservesControlBranch
137
138
      CalculatePriority
136
      CalculatePriority
139
137
140
      IsItemOnHoldAndFound
138
      IsItemOnHoldAndFound
Lines 923-929 sub CheckReserves { Link Here
923
                    next if $res->{item_group_id} && ( !$item->item_group || $item->item_group->id != $res->{item_group_id} );
921
                    next if $res->{item_group_id} && ( !$item->item_group || $item->item_group->id != $res->{item_group_id} );
924
                    next if $res->{itemtype} && $res->{itemtype} ne $item->effective_itemtype;
922
                    next if $res->{itemtype} && $res->{itemtype} ne $item->effective_itemtype;
925
                    $patron //= Koha::Patrons->find( $res->{borrowernumber} );
923
                    $patron //= Koha::Patrons->find( $res->{borrowernumber} );
926
                    my $branch = GetReservesControlBranch( $item->unblessed, $patron->unblessed );
924
                    my $branch = $item->holds_control_library( $patron );
927
                    my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype);
925
                    my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype);
928
                    next if ($branchitemrule->{'holdallowed'} eq 'not_allowed');
926
                    next if ($branchitemrule->{'holdallowed'} eq 'not_allowed');
929
                    next if (($branchitemrule->{'holdallowed'} eq 'from_home_library') && ($item->homebranch ne $patron->branchcode));
927
                    next if (($branchitemrule->{'holdallowed'} eq 'from_home_library') && ($item->homebranch ne $patron->branchcode));
Lines 1346-1353 sub IsAvailableForItemLevelRequest { Link Here
1346
        return 0 unless $destination;
1344
        return 0 unless $destination;
1347
        return 0 unless $destination->pickup_location;
1345
        return 0 unless $destination->pickup_location;
1348
        return 0 unless $item->can_be_transferred( { to => $destination } );
1346
        return 0 unless $item->can_be_transferred( { to => $destination } );
1349
        my $reserves_control_branch =
1347
        my $reserves_control_branch = $item->holds_control_library( $patron );
1350
            GetReservesControlBranch( $item->unblessed(), $patron->unblessed() );
1351
        my $branchitemrule =
1348
        my $branchitemrule =
1352
            C4::Circulation::GetBranchItemRule( $reserves_control_branch, $item->itype );
1349
            C4::Circulation::GetBranchItemRule( $reserves_control_branch, $item->itype );
1353
        my $home_library = Koha::Libraries->find( {branchcode => $item->homebranch} );
1350
        my $home_library = Koha::Libraries->find( {branchcode => $item->homebranch} );
Lines 1389-1396 sub ItemsAnyAvailableAndNotRestricted { Link Here
1389
    my @items = Koha::Items->search( { biblionumber => $param->{biblionumber} } )->as_list;
1386
    my @items = Koha::Items->search( { biblionumber => $param->{biblionumber} } )->as_list;
1390
1387
1391
    foreach my $i (@items) {
1388
    foreach my $i (@items) {
1392
        my $reserves_control_branch =
1389
        my $reserves_control_branch = $i->holds_control_library( $param->{patron} );
1393
            GetReservesControlBranch( $i->unblessed(), $param->{patron}->unblessed );
1394
        my $branchitemrule =
1390
        my $branchitemrule =
1395
            C4::Circulation::GetBranchItemRule( $reserves_control_branch, $i->itype );
1391
            C4::Circulation::GetBranchItemRule( $reserves_control_branch, $i->itype );
1396
        my $item_library = Koha::Libraries->find( { branchcode => $i->homebranch } );
1392
        my $item_library = Koha::Libraries->find( { branchcode => $i->homebranch } );
Lines 2206-2237 sub ReserveSlip { Link Here
2206
    );
2202
    );
2207
}
2203
}
2208
2204
2209
=head2 GetReservesControlBranch
2210
2211
  my $reserves_control_branch = GetReservesControlBranch($item, $borrower);
2212
2213
  Return the branchcode to be used to determine which reserves
2214
  policy applies to a transaction.
2215
2216
  C<$item> is a hashref for an item. Only 'homebranch' is used.
2217
2218
  C<$borrower> is a hashref to borrower. Only 'branchcode' is used.
2219
2220
=cut
2221
2222
sub GetReservesControlBranch {
2223
    my ( $item, $borrower ) = @_;
2224
2225
    my $reserves_control = C4::Context->preference('ReservesControlBranch');
2226
2227
    my $branchcode =
2228
        ( $reserves_control eq 'ItemHomeLibrary' ) ? $item->{'homebranch'}
2229
      : ( $reserves_control eq 'PatronLibrary' )   ? $borrower->{'branchcode'}
2230
      :                                              undef;
2231
2232
    return $branchcode;
2233
}
2234
2235
=head2 CalculatePriority
2205
=head2 CalculatePriority
2236
2206
2237
    my $p = CalculatePriority($biblionumber, $resdate);
2207
    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 ItemsAnyAvailableAndNotRestricted IsAvailableForItemLevelRequest GetReserveFee );
28
use C4::Reserves qw( CanItemBeReserved CanBookBeReserved AddReserve ItemsAnyAvailableAndNotRestricted 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 479-485 foreach my $biblioNum (@biblionumbers) { Link Here
479
            $item_info->{hosttitle}        = Koha::Biblios->find( $item_info->{biblionumber} )->title;
479
            $item_info->{hosttitle}        = Koha::Biblios->find( $item_info->{biblionumber} )->title;
480
        }
480
        }
481
481
482
        my $branch = GetReservesControlBranch( $item_info, $patron_unblessed );
482
        my $branch = $item->holds_control_library( $patron );
483
483
484
        # items_any_available defined outside of the current loop,
484
        # items_any_available defined outside of the current loop,
485
        # so we avoiding loop inside IsAvailableForItemLevelRequest:
485
        # so we avoiding loop inside IsAvailableForItemLevelRequest:
(-)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 => 77;
20
use Test::More tests => 75;
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( GetMarcFromKohaField ModBiblio );
32
use C4::Biblio qw( 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::Biblios;
36
use Koha::Biblios;
37
use Koha::Caches;
37
use Koha::Caches;
Lines 128-150 ok(exists($reserve->{reserve_id}), 'CheckReserves() include reserve_id in its re Link Here
128
($status, $reserve, $all_reserves) = CheckReserves( $item );
128
($status, $reserve, $all_reserves) = CheckReserves( $item );
129
is($status, "Reserved", "CheckReserves Test 2");
129
is($status, "Reserved", "CheckReserves Test 2");
130
130
131
my $ReservesControlBranch = C4::Context->preference('ReservesControlBranch');
132
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
133
ok(
134
    'ItemHomeLib' eq GetReservesControlBranch(
135
        { homebranch => 'ItemHomeLib' },
136
        { branchcode => 'PatronHomeLib' }
137
    ), "GetReservesControlBranch returns item home branch when set to ItemHomeLibrary"
138
);
139
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
140
ok(
141
    'PatronHomeLib' eq GetReservesControlBranch(
142
        { homebranch => 'ItemHomeLib' },
143
        { branchcode => 'PatronHomeLib' }
144
    ), "GetReservesControlBranch returns patron home branch when set to PatronLibrary"
145
);
146
t::lib::Mocks::mock_preference( 'ReservesControlBranch', $ReservesControlBranch );
147
148
###
131
###
149
### Regression test for bug 10272
132
### Regression test for bug 10272
150
###
133
###
151
- 

Return to bug 30825