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

(-)a/C4/Reserves.pm (-4 / +4 lines)
Lines 919-928 sub CheckReserves { Link Here
919
                if ( ( $res->{'priority'} && $res->{'priority'} < $priority ) || $local_hold_match ) {
919
                if ( ( $res->{'priority'} && $res->{'priority'} < $priority ) || $local_hold_match ) {
920
                    $item ||= Koha::Items->find($itemnumber);
920
                    $item ||= Koha::Items->find($itemnumber);
921
                    next if $res->{itemtype} && $res->{itemtype} ne $item->effective_itemtype;
921
                    next if $res->{itemtype} && $res->{itemtype} ne $item->effective_itemtype;
922
                    $patron ||= Koha::Patrons->find( $res->{borrowernumber} );
922
                    my $branch = $item->holds_control_library({ patron => \$patron, patron_id => $res->{borrowernumber} });
923
                    my $branch = $item->holds_control_library( $patron );
924
                    my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype);
923
                    my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype);
925
                    next if ($branchitemrule->{'holdallowed'} eq 'not_allowed');
924
                    next if ($branchitemrule->{'holdallowed'} eq 'not_allowed');
925
                    $patron ||= Koha::Patrons->find( $res->{borrowernumber} );
926
                    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));
927
                    my $library = Koha::Libraries->find({branchcode=>$item->homebranch});
927
                    my $library = Koha::Libraries->find({branchcode=>$item->homebranch});
928
                    next if (($branchitemrule->{'holdallowed'} eq 'from_local_hold_group') && (!$library->validate_hold_sibling({branchcode => $patron->branchcode}) ));
928
                    next if (($branchitemrule->{'holdallowed'} eq 'from_local_hold_group') && (!$library->validate_hold_sibling({branchcode => $patron->branchcode}) ));
Lines 1341-1347 sub IsAvailableForItemLevelRequest { Link Here
1341
        return 0 unless $destination;
1341
        return 0 unless $destination;
1342
        return 0 unless $destination->pickup_location;
1342
        return 0 unless $destination->pickup_location;
1343
        return 0 unless $item->can_be_transferred( { to => $destination } );
1343
        return 0 unless $item->can_be_transferred( { to => $destination } );
1344
        my $reserves_control_branch = $item->holds_control_library( $patron );
1344
        my $reserves_control_branch = $item->holds_control_library({ patron => \$patron });
1345
        my $branchitemrule =
1345
        my $branchitemrule =
1346
            C4::Circulation::GetBranchItemRule( $reserves_control_branch, $item->itype );
1346
            C4::Circulation::GetBranchItemRule( $reserves_control_branch, $item->itype );
1347
        my $home_library = Koha::Libraries->find( {branchcode => $item->homebranch} );
1347
        my $home_library = Koha::Libraries->find( {branchcode => $item->homebranch} );
Lines 1383-1389 sub ItemsAnyAvailableAndNotRestricted { Link Here
1383
    my @items = Koha::Items->search( { biblionumber => $param->{biblionumber} } )->as_list;
1383
    my @items = Koha::Items->search( { biblionumber => $param->{biblionumber} } )->as_list;
1384
1384
1385
    foreach my $i (@items) {
1385
    foreach my $i (@items) {
1386
        my $reserves_control_branch = $i->holds_control_library( $param->{patron} );
1386
        my $reserves_control_branch = $i->holds_control_library({ patron => \$param->{patron} });
1387
        my $branchitemrule =
1387
        my $branchitemrule =
1388
            C4::Circulation::GetBranchItemRule( $reserves_control_branch, $i->itype );
1388
            C4::Circulation::GetBranchItemRule( $reserves_control_branch, $i->itype );
1389
        my $item_library = Koha::Libraries->find( { branchcode => $i->homebranch } );
1389
        my $item_library = Koha::Libraries->find( { branchcode => $i->homebranch } );
(-)a/Koha/Item.pm (-7 / +8 lines)
Lines 434-440 sub holds { Link Here
434
434
435
=head3 holds_control_library
435
=head3 holds_control_library
436
436
437
    my $control_library = $item->holds_control_library( $patron );
437
    my $control_library = $item->holds_control_library({ patron => $patron, patron_id => $patron_id });
438
438
439
Given a I<Koha::Patron> object, this method returns a library id, for
439
Given a I<Koha::Patron> object, this method returns a library id, for
440
the library that is to be used for calculating circulation rules. It relies
440
the library that is to be used for calculating circulation rules. It relies
Lines 443-454 on the B<ReservesControlBranch> system preference. Link Here
443
=cut
443
=cut
444
444
445
sub holds_control_library {
445
sub holds_control_library {
446
    my ( $self, $patron ) = @_;
446
    my ( $self, $params ) = @_;
447
448
    return $self->homebranch
449
      if C4::Context->preference('ReservesControlBranch') eq 'ItemHomeLibrary';
447
450
448
    return (
451
    ${ $params->{patron} } //= Koha::Patrons->find( $params->{patron_id} );
449
        C4::Context->preference('ReservesControlBranch') eq 'ItemHomeLibrary' )
452
    return ${ $params->{patron} }->branchcode;
450
      ? $self->homebranch
451
      : $patron->branchcode;
452
}
453
}
453
454
454
=head3 request_transfer
455
=head3 request_transfer
Lines 729-735 sub pickup_locations { Link Here
729
730
730
    my $patron = $params->{patron};
731
    my $patron = $params->{patron};
731
732
732
    my $circ_control_branch = $self->holds_control_library( $patron );
733
    my $circ_control_branch = $self->holds_control_library({ patron => \$patron });
733
    my $branchitemrule =
734
    my $branchitemrule =
734
      C4::Circulation::GetBranchItemRule( $circ_control_branch, $self->itype );
735
      C4::Circulation::GetBranchItemRule( $circ_control_branch, $self->itype );
735
736
(-)a/opac/opac-reserve.pl (-1 / +1 lines)
Lines 559-565 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 $branch = $item->holds_control_library( $patron );
562
        my $branch = $item->holds_control_library({ patron => \$patron });
563
563
564
        my $policy_holdallowed = !$itemLoopIter->{already_reserved};
564
        my $policy_holdallowed = !$itemLoopIter->{already_reserved};
565
        # items_any_available defined outside of the current loop,
565
        # items_any_available defined outside of the current loop,
(-)a/t/db_dependent/Koha/Item.t (-5 / +8 lines)
Lines 1456-1478 subtest 'Recalls tests' => sub { Link Here
1456
1456
1457
subtest 'holds_control_library() tests' => sub {
1457
subtest 'holds_control_library() tests' => sub {
1458
1458
1459
    plan tests => 2;
1459
    plan tests => 5;
1460
1460
1461
    $schema->storage->txn_begin;
1461
    $schema->storage->txn_begin;
1462
1462
1463
    my $library_1 = $builder->build_object({ class => 'Koha::Libraries' });
1463
    my $library_1 = $builder->build_object({ class => 'Koha::Libraries' });
1464
    my $library_2 = $builder->build_object({ class => 'Koha::Libraries' });
1464
    my $library_2 = $builder->build_object({ class => 'Koha::Libraries' });
1465
1465
1466
    my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library_1->id } });
1466
    my $patron;
1467
    my $new_patron = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library_1->id } });
1467
    my $item   = $builder->build_sample_item({ library => $library_2->id });
1468
    my $item   = $builder->build_sample_item({ library => $library_2->id });
1468
1469
1469
    t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
1470
    t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
1470
1471
1471
    is( $item->holds_control_library( $patron ), $library_2->id );
1472
    is( $patron, undef, '$patron is not yet set');
1473
    is( $item->holds_control_library({ patron => \$patron, patron_id => $new_patron->borrowernumber }), $library_2->id, 'ItemHomeLibrary correctly selected' );
1474
    is( $patron, undef, '$patron is still not set');
1472
1475
1473
    t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
1476
    t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
1474
1477
1475
    is( $item->holds_control_library( $patron ), $library_1->id );
1478
    is( $item->holds_control_library({ patron => \$patron, patron_id => $new_patron->borrowernumber }), $library_1->id, 'PatronLibrary correctly selected' );
1479
    is(ref($patron), 'Koha::Patron', '$patron now set to Koha::Patron object'); 
1476
1480
1477
    $schema->storage->txn_rollback;
1481
    $schema->storage->txn_rollback;
1478
};
1482
};
1479
- 

Return to bug 30825