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

(-)a/C4/Reserves.pm (-1 / +29 lines)
Lines 46-51 use Koha::Libraries; Link Here
46
use Koha::Patrons;
46
use Koha::Patrons;
47
use Koha::Plugins;
47
use Koha::Plugins;
48
use Koha::Policy::Holds;
48
use Koha::Policy::Holds;
49
use Data::Dumper;
49
50
50
use List::MoreUtils qw( any );
51
use List::MoreUtils qw( any );
51
52
Lines 873-879 sub CheckReserves { Link Here
873
    }
874
    }
874
875
875
    # Find this item in the reserves
876
    # Find this item in the reserves
876
    my @reserves = _Findgroupreserve( $item->biblionumber, $item->itemnumber, $lookahead_days, $ignore_borrowers );
877
    my @reserves = _Findgroupreserve( $item->biblionumber, $item->itemnumber, $lookahead_days, $ignore_borrowers);
878
    # When IndependentBranchesTransfers is activate remove the reserve made from other branches
879
    @reserves = _FilterHoldsForIndependentBranches( @reserves );
877
880
878
    # $priority and $highest are used to find the most important item
881
    # $priority and $highest are used to find the most important item
879
    # in the list returned by &_Findgroupreserve. (The lower $priority,
882
    # in the list returned by &_Findgroupreserve. (The lower $priority,
Lines 1785-1790 sub _Findgroupreserve { Link Here
1785
    return @results;
1788
    return @results;
1786
}
1789
}
1787
1790
1791
=head2 _FilterHoldsForIndependentBranches
1792
1793
  @reserves = &_FilterHoldsForIndependentBranches( @reserves );
1794
1795
Check transfers is allowed from system preference and remove the reserves made from other branches
1796
1797
C<&_FilterHoldsForIndependentBranches> returns :
1798
C<@results> is an array of references-to-hash whose keys are mostly
1799
fields from the reserves table of the Koha database, plus
1800
1801
=cut
1802
1803
sub _FilterHoldsForIndependentBranches {
1804
    my ( @reserves) = @_;
1805
    if ( C4::Context->preference("IndependentBranchesTransfers") && scalar @reserves)
1806
    {
1807
        my @results;
1808
        foreach my $res (@reserves) {
1809
            push( @results, $res ) if ($res->{branchcode} eq C4::Context->userenv->{'branch'});
1810
        }
1811
        return @results;
1812
    }
1813
    return @reserves;
1814
}
1815
1788
=head2 _koha_notify_reserve
1816
=head2 _koha_notify_reserve
1789
1817
1790
  _koha_notify_reserve( $hold->reserve_id );
1818
  _koha_notify_reserve( $hold->reserve_id );
(-)a/t/db_dependent/Reserves.t (-4 / +31 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 69;
20
use Test::More tests => 73;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 61-67 my $builder = t::lib::TestBuilder->new; Link Here
61
61
62
my $frameworkcode = q//;
62
my $frameworkcode = q//;
63
63
64
t::lib::Mocks::mock_preference( 'ReservesNeedReturns', 1 );
64
65
t::lib::Mocks::mock_preference('ReservesNeedReturns', 1);
66
t::lib::Mocks::mock_preference( 'IndependentBranchesTransfers', 0 );
65
67
66
# Somewhat arbitrary field chosen for age restriction unit tests. Must be added to db before the framework is cached
68
# Somewhat arbitrary field chosen for age restriction unit tests. Must be added to db before the framework is cached
67
$dbh->do(
69
$dbh->do(
Lines 132-137 ok( exists( $reserve->{reserve_id} ), 'CheckReserves() include reserve_id in its Link Here
132
( $status, $reserve, $all_reserves ) = CheckReserves($item);
134
( $status, $reserve, $all_reserves ) = CheckReserves($item);
133
is( $status, "Reserved", "CheckReserves Test 2" );
135
is( $status, "Reserved", "CheckReserves Test 2" );
134
136
137
# Set the preference 'IndependentBranchesTransfers' is set to 'yes'
138
# the userenv branch and the branche code are not the same holds should be filtered
139
t::lib::Mocks::mock_preference( 'IndependentBranchesTransfers', 1 );
140
($status, $reserve, $all_reserves) = CheckReserves( $item );
141
is( $status, "", 'Reserves is filtered');
142
143
# Set the userenv branchcode to be the same to the item branchcode.
144
t::lib::Mocks::mock_userenv({ branchcode => $branchcode });
145
($status, $reserve, $all_reserves) = CheckReserves( $item );
146
is( $status, "Reserved", 'Reserves should not be filtered');
147
148
t::lib::Mocks::mock_userenv({ branchcode => $branch_1 });
149
t::lib::Mocks::mock_preference( 'IndependentBranchesTransfers', 0 );
150
my $ReservesControlBranch = C4::Context->preference('ReservesControlBranch');
151
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
152
ok(
153
	$item->homebranch eq Koha::Policy::Holds->holds_control_library( $item, $patron	),
154
    "Koha::Policy::Holds->holds_control_library returns item home branch when set to ItemHomeLibrary"
155
);
156
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
157
ok(
158
	$patron->branchcode eq Koha::Policy::Holds->holds_control_library( $item, $patron ),
159
    "Koha::Policy::Holds->holds_control_library returns patron home branch when set to PatronLibrary"
160
);
161
t::lib::Mocks::mock_preference( 'ReservesControlBranch', $ReservesControlBranch );
162
135
###
163
###
136
### Regression test for bug 10272
164
### Regression test for bug 10272
137
###
165
###
Lines 1510-1516 sub count_hold_print_messages { Link Here
1510
        q{
1538
        q{
1511
        SELECT COUNT(*)
1539
        SELECT COUNT(*)
1512
        FROM message_queue
1540
        FROM message_queue
1513
        WHERE letter_code = 'HOLD' 
1541
        WHERE letter_code = 'HOLD'
1514
        AND   message_transport_type = 'print'
1542
        AND   message_transport_type = 'print'
1515
    }
1543
    }
1516
    );
1544
    );
1517
- 

Return to bug 33200