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

(-)a/C4/Reserves.pm (-1 / +29 lines)
Lines 90-95 use Koha::Library; Link Here
90
use Koha::Patrons;
90
use Koha::Patrons;
91
use Koha::Plugins;
91
use Koha::Plugins;
92
use Koha::Policy::Holds;
92
use Koha::Policy::Holds;
93
use Data::Dumper;
93
94
94
use List::MoreUtils qw( any );
95
use List::MoreUtils qw( any );
95
96
Lines 811-817 sub CheckReserves { Link Here
811
    }
812
    }
812
813
813
    # Find this item in the reserves
814
    # Find this item in the reserves
814
    my @reserves = _Findgroupreserve( $item->biblionumber, $item->itemnumber, $lookahead_days, $ignore_borrowers );
815
    my @reserves = _Findgroupreserve( $item->biblionumber, $item->itemnumber, $lookahead_days, $ignore_borrowers);
816
    # When IndependentBranchesTransfers is activate remove the reserve made from other branches
817
    @reserves = _FilterHoldsForIndependentBranches( @reserves );
815
818
816
    # $priority and $highest are used to find the most important item
819
    # $priority and $highest are used to find the most important item
817
    # in the list returned by &_Findgroupreserve. (The lower $priority,
820
    # in the list returned by &_Findgroupreserve. (The lower $priority,
Lines 1871-1876 sub _Findgroupreserve { Link Here
1871
    return @results;
1874
    return @results;
1872
}
1875
}
1873
1876
1877
=head2 _FilterHoldsForIndependentBranches
1878
1879
  @reserves = &_FilterHoldsForIndependentBranches( @reserves );
1880
1881
Check transfers is allowed from system preference and remove the reserves made from other branches
1882
1883
C<&_FilterHoldsForIndependentBranches> returns :
1884
C<@results> is an array of references-to-hash whose keys are mostly
1885
fields from the reserves table of the Koha database, plus
1886
1887
=cut
1888
1889
sub _FilterHoldsForIndependentBranches {
1890
    my ( @reserves) = @_;
1891
    if ( C4::Context->preference("IndependentBranchesTransfers") && scalar @reserves)
1892
    {
1893
        my @results;
1894
        foreach my $res (@reserves) {
1895
            push( @results, $res ) if ($res->{branchcode} eq C4::Context->userenv->{'branch'});
1896
        }
1897
        return @results;
1898
    }
1899
    return @reserves;
1900
}
1901
1874
=head2 _koha_notify_reserve
1902
=head2 _koha_notify_reserve
1875
1903
1876
  _koha_notify_reserve( $hold->reserve_id );
1904
  _koha_notify_reserve( $hold->reserve_id );
(-)a/t/db_dependent/Reserves.t (-5 / +31 lines)
Lines 17-24 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::NoWarnings;
22
use Test::MockModule;
21
use Test::MockModule;
23
use Test::Warn;
22
use Test::Warn;
24
23
Lines 63-69 my $builder = t::lib::TestBuilder->new; Link Here
63
62
64
my $frameworkcode = q//;
63
my $frameworkcode = q//;
65
64
66
t::lib::Mocks::mock_preference( 'ReservesNeedReturns', 1 );
65
66
t::lib::Mocks::mock_preference('ReservesNeedReturns', 1);
67
t::lib::Mocks::mock_preference( 'IndependentBranchesTransfers', 0 );
67
68
68
# Somewhat arbitrary field chosen for age restriction unit tests. Must be added to db before the framework is cached
69
# Somewhat arbitrary field chosen for age restriction unit tests. Must be added to db before the framework is cached
69
$dbh->do(
70
$dbh->do(
Lines 134-139 ok( exists( $reserve->{reserve_id} ), 'CheckReserves() include reserve_id in its Link Here
134
( $status, $reserve, $all_reserves ) = CheckReserves($item);
135
( $status, $reserve, $all_reserves ) = CheckReserves($item);
135
is( $status, "Reserved", "CheckReserves Test 2" );
136
is( $status, "Reserved", "CheckReserves Test 2" );
136
137
138
# Set the preference 'IndependentBranchesTransfers' is set to 'yes'
139
# the userenv branch and the branche code are not the same holds should be filtered
140
t::lib::Mocks::mock_preference( 'IndependentBranchesTransfers', 1 );
141
($status, $reserve, $all_reserves) = CheckReserves( $item );
142
is( $status, "", 'Reserves is filtered');
143
144
# Set the userenv branchcode to be the same to the item branchcode.
145
t::lib::Mocks::mock_userenv({ branchcode => $branchcode });
146
($status, $reserve, $all_reserves) = CheckReserves( $item );
147
is( $status, "Reserved", 'Reserves should not be filtered');
148
149
t::lib::Mocks::mock_userenv({ branchcode => $branch_1 });
150
t::lib::Mocks::mock_preference( 'IndependentBranchesTransfers', 0 );
151
my $ReservesControlBranch = C4::Context->preference('ReservesControlBranch');
152
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
153
ok(
154
	$item->homebranch eq Koha::Policy::Holds->holds_control_library( $item, $patron	),
155
    "Koha::Policy::Holds->holds_control_library returns item home branch when set to ItemHomeLibrary"
156
);
157
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
158
ok(
159
	$patron->branchcode eq Koha::Policy::Holds->holds_control_library( $item, $patron ),
160
    "Koha::Policy::Holds->holds_control_library returns patron home branch when set to PatronLibrary"
161
);
162
t::lib::Mocks::mock_preference( 'ReservesControlBranch', $ReservesControlBranch );
163
137
###
164
###
138
### Regression test for bug 10272
165
### Regression test for bug 10272
139
###
166
###
Lines 1471-1477 sub count_hold_print_messages { Link Here
1471
        q{
1498
        q{
1472
        SELECT COUNT(*)
1499
        SELECT COUNT(*)
1473
        FROM message_queue
1500
        FROM message_queue
1474
        WHERE letter_code = 'HOLD' 
1501
        WHERE letter_code = 'HOLD'
1475
        AND   message_transport_type = 'print'
1502
        AND   message_transport_type = 'print'
1476
    }
1503
    }
1477
    );
1504
    );
1478
- 

Return to bug 33200