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

(-)a/C4/Reserves.pm (-1 / +29 lines)
Lines 47-52 use Koha::Library; Link Here
47
use Koha::Patrons;
47
use Koha::Patrons;
48
use Koha::Plugins;
48
use Koha::Plugins;
49
use Koha::Policy::Holds;
49
use Koha::Policy::Holds;
50
use Data::Dumper;
50
51
51
use List::MoreUtils qw( any );
52
use List::MoreUtils qw( any );
52
53
Lines 875-881 sub CheckReserves { Link Here
875
    }
876
    }
876
877
877
    # Find this item in the reserves
878
    # Find this item in the reserves
878
    my @reserves = _Findgroupreserve( $item->biblionumber, $item->itemnumber, $lookahead_days, $ignore_borrowers );
879
    my @reserves = _Findgroupreserve( $item->biblionumber, $item->itemnumber, $lookahead_days, $ignore_borrowers);
880
    # When IndependentBranchesTransfers is activate remove the reserve made from other branches
881
    @reserves = _FilterHoldsForIndependentBranches( @reserves );
879
882
880
    # $priority and $highest are used to find the most important item
883
    # $priority and $highest are used to find the most important item
881
    # in the list returned by &_Findgroupreserve. (The lower $priority,
884
    # in the list returned by &_Findgroupreserve. (The lower $priority,
Lines 1808-1813 sub _Findgroupreserve { Link Here
1808
    return @results;
1811
    return @results;
1809
}
1812
}
1810
1813
1814
=head2 _FilterHoldsForIndependentBranches
1815
1816
  @reserves = &_FilterHoldsForIndependentBranches( @reserves );
1817
1818
Check transfers is allowed from system preference and remove the reserves made from other branches
1819
1820
C<&_FilterHoldsForIndependentBranches> returns :
1821
C<@results> is an array of references-to-hash whose keys are mostly
1822
fields from the reserves table of the Koha database, plus
1823
1824
=cut
1825
1826
sub _FilterHoldsForIndependentBranches {
1827
    my ( @reserves) = @_;
1828
    if ( C4::Context->preference("IndependentBranchesTransfers") && scalar @reserves)
1829
    {
1830
        my @results;
1831
        foreach my $res (@reserves) {
1832
            push( @results, $res ) if ($res->{branchcode} eq C4::Context->userenv->{'branch'});
1833
        }
1834
        return @results;
1835
    }
1836
    return @reserves;
1837
}
1838
1811
=head2 _koha_notify_reserve
1839
=head2 _koha_notify_reserve
1812
1840
1813
  _koha_notify_reserve( $hold->reserve_id );
1841
  _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 => 70;
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 1533-1539 sub count_hold_print_messages { Link Here
1533
        q{
1561
        q{
1534
        SELECT COUNT(*)
1562
        SELECT COUNT(*)
1535
        FROM message_queue
1563
        FROM message_queue
1536
        WHERE letter_code = 'HOLD' 
1564
        WHERE letter_code = 'HOLD'
1537
        AND   message_transport_type = 'print'
1565
        AND   message_transport_type = 'print'
1538
    }
1566
    }
1539
    );
1567
    );
1540
- 

Return to bug 33200