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

(-)a/C4/Reserves.pm (+10 lines)
Lines 928-933 sub CheckReserves { Link Here
928
                    next if ( ($hold_fulfillment_policy eq 'homebranch') && ($res->{branchcode} ne $item->$hold_fulfillment_policy) );
928
                    next if ( ($hold_fulfillment_policy eq 'homebranch') && ($res->{branchcode} ne $item->$hold_fulfillment_policy) );
929
                    next if ( ($hold_fulfillment_policy eq 'holdingbranch') && ($res->{branchcode} ne $item->$hold_fulfillment_policy) );
929
                    next if ( ($hold_fulfillment_policy eq 'holdingbranch') && ($res->{branchcode} ne $item->$hold_fulfillment_policy) );
930
                    next unless $item->can_be_transferred( { to => Koha::Libraries->find( $res->{branchcode} ) } );
930
                    next unless $item->can_be_transferred( { to => Koha::Libraries->find( $res->{branchcode} ) } );
931
                    my $reservesallowed = Koha::CirculationRules->get_effective_rule_value(
932
                        {
933
                            itemtype     => $item->effective_itemtype,
934
                            categorycode => $patron->categorycode,
935
                            branchcode   => $branch,
936
                            rule_name    => 'reservesallowed',
937
                        }
938
                    );
939
                    next unless $reservesallowed;
940
931
                    $priority = $res->{'priority'};
941
                    $priority = $res->{'priority'};
932
                    $highest  = $res;
942
                    $highest  = $res;
933
                    last if $local_hold_match;
943
                    last if $local_hold_match;
(-)a/t/db_dependent/Reserves/CheckReserves.t (-1 / +109 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More;
21
22
use C4::Reserves;
23
use Koha::CirculationRules;
24
use Koha::Database;
25
use Koha::ItemType;
26
use t::lib::TestBuilder;
27
28
plan tests => 1;
29
30
my $schema  = Koha::Database->schema;
31
my $builder = t::lib::TestBuilder->new;
32
33
subtest 'CheckReserves checks circulation rule reservesallowed' => sub {
34
    plan tests => 2;
35
36
    $schema->txn_begin;
37
38
    # One biblio has 2 items of different itemtype. One is reservable
39
    # (reservesallowed = 1), the other is not (reservesallowed = 0).
40
    # A patron made a reserve at the biblio-level
41
    # CheckReserves, when given the non-reservable item, should NOT return this
42
    # reserve
43
44
    my $itemtype_ok = Koha::ItemType->new( { itemtype => 'CHKRES:OK' } );
45
    $itemtype_ok->store();
46
    my $itemtype_ko = Koha::ItemType->new( { itemtype => 'CHKRES:KO' } );
47
    $itemtype_ko->store();
48
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
49
    my $biblio  = $builder->build_sample_biblio();
50
    my $item_ok = $builder->build_sample_item(
51
        {
52
            biblionumber => $biblio->biblionumber,
53
            library      => $library->unblessed,
54
            itype        => $itemtype_ok->itemtype,
55
        }
56
    );
57
    my $item_ko = $builder->build_sample_item(
58
        {
59
            biblionumber => $biblio->biblionumber,
60
            library      => $library->branchcode,
61
            itype        => $itemtype_ko->itemtype,
62
        }
63
    );
64
    my $patron = $builder->build_object(
65
        {
66
            class => 'Koha::Patrons',
67
            value => {
68
                branchcode => $library->branchcode,
69
            },
70
        }
71
    );
72
    Koha::CirculationRules->set_rule(
73
        {
74
            branchcode   => $library->branchcode,
75
            categorycode => $patron->categorycode,
76
            itemtype     => $itemtype_ok->itemtype,
77
            rule_name    => 'reservesallowed',
78
            rule_value   => '1',
79
        }
80
    );
81
    Koha::CirculationRules->set_rule(
82
        {
83
            branchcode   => $library->branchcode,
84
            categorycode => $patron->categorycode,
85
            itemtype     => $itemtype_ko->itemtype,
86
            rule_name    => 'reservesallowed',
87
            rule_value   => '0',
88
        }
89
    );
90
    C4::Reserves::AddReserve(
91
        {
92
            branchcode     => $library->branchcode,
93
            borrowernumber => $patron->borrowernumber,
94
            biblionumber   => $biblio->biblionumber,
95
        }
96
    );
97
98
    {
99
        my ($status) = C4::Reserves::CheckReserves($item_ko);
100
        is( $status, '', 'No reserves found for the item that cannot be reserved' );
101
    }
102
103
    {
104
        my ($status) = C4::Reserves::CheckReserves($item_ok);
105
        is( $status, 'Reserved', 'A reserve is found for the item that can be reserved' );
106
    }
107
108
    $schema->txn_rollback;
109
};

Return to bug 30274