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

(-)a/C4/Reserves.pm (-3 / +4 lines)
Lines 47-52 use Koha::Libraries; Link Here
47
use Koha::Old::Holds;
47
use Koha::Old::Holds;
48
use Koha::Patrons;
48
use Koha::Patrons;
49
use Koha::Plugins;
49
use Koha::Plugins;
50
use Koha::Policy::Holds;
50
51
51
use List::MoreUtils qw( any );
52
use List::MoreUtils qw( any );
52
53
Lines 937-943 sub CheckReserves { Link Here
937
                    next if $res->{item_group_id} && ( !$item->item_group || $item->item_group->id != $res->{item_group_id} );
938
                    next if $res->{item_group_id} && ( !$item->item_group || $item->item_group->id != $res->{item_group_id} );
938
                    next if $res->{itemtype} && $res->{itemtype} ne $item->effective_itemtype;
939
                    next if $res->{itemtype} && $res->{itemtype} ne $item->effective_itemtype;
939
                    $patron //= Koha::Patrons->find( $res->{borrowernumber} );
940
                    $patron //= Koha::Patrons->find( $res->{borrowernumber} );
940
                    my $branch = $item->holds_control_library( $patron );
941
                    my $branch = Koha::Policy::Holds->holds_control_library( $item, $patron );
941
                    my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype);
942
                    my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype);
942
                    next if ($branchitemrule->{'holdallowed'} eq 'not_allowed');
943
                    next if ($branchitemrule->{'holdallowed'} eq 'not_allowed');
943
                    next if (($branchitemrule->{'holdallowed'} eq 'from_home_library') && ($item->homebranch ne $patron->branchcode));
944
                    next if (($branchitemrule->{'holdallowed'} eq 'from_home_library') && ($item->homebranch ne $patron->branchcode));
Lines 1357-1363 sub IsAvailableForItemLevelRequest { Link Here
1357
        return 0 unless $destination;
1358
        return 0 unless $destination;
1358
        return 0 unless $destination->pickup_location;
1359
        return 0 unless $destination->pickup_location;
1359
        return 0 unless $item->can_be_transferred( { to => $destination } );
1360
        return 0 unless $item->can_be_transferred( { to => $destination } );
1360
        my $reserves_control_branch = $item->holds_control_library( $patron );
1361
        my $reserves_control_branch = Koha::Policy::Holds->holds_control_library( $item, $patron );
1361
        my $branchitemrule =
1362
        my $branchitemrule =
1362
            C4::Circulation::GetBranchItemRule( $reserves_control_branch, $item->itype );
1363
            C4::Circulation::GetBranchItemRule( $reserves_control_branch, $item->itype );
1363
        my $home_library = Koha::Libraries->find( {branchcode => $item->homebranch} );
1364
        my $home_library = Koha::Libraries->find( {branchcode => $item->homebranch} );
Lines 1406-1412 sub ItemsAnyAvailableAndNotRestricted { Link Here
1406
    my @items = Koha::Items->search( { biblionumber => $param->{biblionumber} } )->as_list;
1407
    my @items = Koha::Items->search( { biblionumber => $param->{biblionumber} } )->as_list;
1407
1408
1408
    foreach my $i (@items) {
1409
    foreach my $i (@items) {
1409
        my $reserves_control_branch = $i->holds_control_library( $param->{patron} );
1410
        my $reserves_control_branch = Koha::Policy::Holds->holds_control_library( $i, $param->{patron} );
1410
        my $branchitemrule =
1411
        my $branchitemrule =
1411
            C4::Circulation::GetBranchItemRule( $reserves_control_branch, $i->itype );
1412
            C4::Circulation::GetBranchItemRule( $reserves_control_branch, $i->itype );
1412
        my $item_library = Koha::Libraries->find( { branchcode => $i->homebranch } );
1413
        my $item_library = Koha::Libraries->find( { branchcode => $i->homebranch } );
(-)a/Koha/Item.pm (-20 / +2 lines)
Lines 54-59 use Koha::SearchEngine::Indexer; Link Here
54
use Koha::StockRotationItem;
54
use Koha::StockRotationItem;
55
use Koha::StockRotationRotas;
55
use Koha::StockRotationRotas;
56
use Koha::TrackedLinks;
56
use Koha::TrackedLinks;
57
use Koha::Policy::Holds;
57
58
58
use base qw(Koha::Object);
59
use base qw(Koha::Object);
59
60
Lines 483-507 sub holds { Link Here
483
    return Koha::Holds->_new_from_dbic( $holds_rs );
484
    return Koha::Holds->_new_from_dbic( $holds_rs );
484
}
485
}
485
486
486
=head3 holds_control_library
487
488
    my $control_library = $item->holds_control_library( $patron );
489
490
Given a I<Koha::Patron> object, this method returns a library id, for
491
the library that is to be used for calculating circulation rules. It relies
492
on the B<ReservesControlBranch> system preference.
493
494
=cut
495
496
sub holds_control_library {
497
    my ( $self, $patron ) = @_;
498
499
    return (
500
        C4::Context->preference('ReservesControlBranch') eq 'ItemHomeLibrary' )
501
      ? $self->homebranch
502
      : $patron->branchcode;
503
}
504
505
=head3 request_transfer
487
=head3 request_transfer
506
488
507
  my $transfer = $item->request_transfer(
489
  my $transfer = $item->request_transfer(
Lines 759-765 sub pickup_locations { Link Here
759
741
760
    my $patron = $params->{patron};
742
    my $patron = $params->{patron};
761
743
762
    my $circ_control_branch = $self->holds_control_library( $patron );
744
    my $circ_control_branch = Koha::Policy::Holds->holds_control_library( $self, $patron );
763
    my $branchitemrule =
745
    my $branchitemrule =
764
      C4::Circulation::GetBranchItemRule( $circ_control_branch, $self->itype );
746
      C4::Circulation::GetBranchItemRule( $circ_control_branch, $self->itype );
765
747
(-)a/Koha/Policy/Holds.pm (+58 lines)
Line 0 Link Here
1
package Koha::Policy::Holds;
2
3
# Copyright 2023 Koha Development team
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use C4::Context;
23
24
=head1 NAME
25
26
Koha::Policy::Holds - module to deal with holds policy
27
28
=head1 API
29
30
=head2 Class Methods
31
32
=head3 new
33
34
=cut
35
36
sub new {
37
    return bless {}, shift;
38
}
39
40
=head3 holds_control_library
41
42
    my $control_library = Koha::Policy::Holds->holds_control_library( $item, $patron );
43
44
Given I<Koha::Item> and I<Koha::Patron> objects, this method returns a library id, for
45
the library that is to be used for calculating circulation rules. It relies
46
on the B<ReservesControlBranch> system preference.
47
48
=cut
49
50
sub holds_control_library {
51
    my ( $class, $item, $patron ) = @_;
52
53
    return ( C4::Context->preference('ReservesControlBranch') eq 'ItemHomeLibrary' )
54
        ? $item->homebranch
55
        : $patron->branchcode;
56
}
57
58
1;
(-)a/opac/opac-reserve.pl (-1 / +1 lines)
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 = $item->holds_control_library( $patron );
480
        my $branch = Koha::Policy::Holds->holds_control_library( $item, $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/Koha/Item.t (-24 / +1 lines)
Lines 20-26 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
use utf8;
21
use utf8;
22
22
23
use Test::More tests => 31;
23
use Test::More tests => 30;
24
use Test::Exception;
24
use Test::Exception;
25
use Test::MockModule;
25
use Test::MockModule;
26
26
Lines 2295-2320 subtest 'current_branchtransfers relationship' => sub { Link Here
2295
2295
2296
    $schema->storage->txn_rollback;
2296
    $schema->storage->txn_rollback;
2297
};
2297
};
2298
2299
subtest 'holds_control_library() tests' => sub {
2300
2301
    plan tests => 2;
2302
2303
    $schema->storage->txn_begin;
2304
2305
    my $library_1 = $builder->build_object({ class => 'Koha::Libraries' });
2306
    my $library_2 = $builder->build_object({ class => 'Koha::Libraries' });
2307
2308
    my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library_1->id } });
2309
    my $item   = $builder->build_sample_item({ library => $library_2->id });
2310
2311
    t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
2312
2313
    is( $item->holds_control_library( $patron ), $library_2->id );
2314
2315
    t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
2316
2317
    is( $item->holds_control_library( $patron ), $library_1->id );
2318
2319
    $schema->storage->txn_rollback;
2320
};
(-)a/t/db_dependent/Koha/Policy/Holds.t (-1 / +54 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2023 Koha Development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 1;
23
24
use Koha::Database;
25
use t::lib::Mocks;
26
use t::lib::TestBuilder;
27
28
my $schema  = Koha::Database->new->schema;
29
my $builder = t::lib::TestBuilder->new;
30
31
subtest 'holds_control_library() tests' => sub {
32
33
    plan tests => 2;
34
35
    $schema->storage->txn_begin;
36
37
    my $library_1 = $builder->build_object( { class => 'Koha::Libraries' } );
38
    my $library_2 = $builder->build_object( { class => 'Koha::Libraries' } );
39
40
    my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library_1->id } } );
41
    my $item = $builder->build_sample_item( { library => $library_2->id } );
42
43
    t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
44
45
    my $policy = Koha::Policy::Holds->new;
46
47
    is( $policy->holds_control_library( $item, $patron ), $library_2->id );
48
49
    t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
50
51
    is( $policy->holds_control_library( $item, $patron ), $library_1->id );
52
53
    $schema->storage->txn_rollback;
54
};

Return to bug 30825