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

(-)a/Koha/Biblio.pm (+29 lines)
Lines 850-855 sub get_marc_notes { Link Here
850
    return \@marcnotes;
850
    return \@marcnotes;
851
}
851
}
852
852
853
=head3 allowed_holds
854
855
    my $holds_allowed_on_record_today = $biblio->allowed_holds( $patron_obj );
856
857
Calculates and returns the number of item-level holds a borrower is allowed to place on the record on a single day.
858
859
=cut
860
861
sub allowed_holds {
862
863
    my ( $self, $patron ) = @_;
864
865
    my $controlbranch = C4::Context->preference('ReservesControlBranch');
866
    my $holds_allowed = 0;
867
    foreach my $item ( $self->items()->as_list() ) {
868
        my $holds_per_day = Koha::CirculationRules->get_effective_rule({
869
            rule_name => 'holds_per_day',
870
            categorycode => $patron->categorycode,
871
            itemtype => $item->effective_itemtype(),
872
            branchcode => ( $controlbranch and $controlbranch eq 'PatronLibrary' ) ? $patron->branchcode : $item->homebranch,
873
        });
874
        $holds_per_day = $holds_per_day ? $holds_per_day->rule_value : 0;
875
        if ( $holds_per_day ) {
876
            $holds_allowed = $holds_per_day if $holds_per_day > $holds_allowed;
877
        }
878
    }
879
    return $holds_allowed;
880
}
881
853
=head3 to_api
882
=head3 to_api
854
883
855
    my $json = $biblio->to_api;
884
    my $json = $biblio->to_api;
(-)a/t/db_dependent/Reserves/MultiplePerRecord.t (-2 / +15 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 16;
22
use Test::More tests => 18;
23
use t::lib::TestBuilder;
23
use t::lib::TestBuilder;
24
use t::lib::Mocks;
24
use t::lib::Mocks;
25
25
Lines 98-103 Koha::CirculationRules->set_rules( Link Here
98
        rules        => {
98
        rules        => {
99
            reservesallowed  => 1,
99
            reservesallowed  => 1,
100
            holds_per_record => 1,
100
            holds_per_record => 1,
101
            holds_per_day    => 1,
101
        }
102
        }
102
    }
103
    }
103
);
104
);
Lines 115-120 Koha::CirculationRules->set_rules( Link Here
115
        rules        => {
116
        rules        => {
116
            reservesallowed  => 2,
117
            reservesallowed  => 2,
117
            holds_per_record => 2,
118
            holds_per_record => 2,
119
            holds_per_day    => 2,
118
        }
120
        }
119
    }
121
    }
120
);
122
);
Lines 130-135 Koha::CirculationRules->set_rules( Link Here
130
        rules        => {
132
        rules        => {
131
            reservesallowed  => 3,
133
            reservesallowed  => 3,
132
            holds_per_record => 3,
134
            holds_per_record => 3,
135
            holds_per_day    => 3,
133
        }
136
        }
134
    }
137
    }
135
);
138
);
Lines 145-150 Koha::CirculationRules->set_rules( Link Here
145
        rules        => {
148
        rules        => {
146
            reservesallowed  => 4,
149
            reservesallowed  => 4,
147
            holds_per_record => 4,
150
            holds_per_record => 4,
151
            holds_per_day    => 4,
148
        }
152
        }
149
    }
153
    }
150
);
154
);
Lines 152-157 Koha::CirculationRules->set_rules( Link Here
152
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->biblionumber );
156
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->biblionumber );
153
is( $max, 4, 'GetMaxPatronHoldsForRecord returns max of 4' );
157
is( $max, 4, 'GetMaxPatronHoldsForRecord returns max of 4' );
154
158
159
my $patron_obj = Koha::Patrons->find( $patron->{borrowernumber} );
160
my $holds_per_day = $biblio->allowed_holds( $patron_obj );
161
is( $holds_per_day, 4, "GetAllowedHoldsForPatronToday returns max of 4" );
162
155
Koha::CirculationRules->set_rules(
163
Koha::CirculationRules->set_rules(
156
    {
164
    {
157
        categorycode => $category->{categorycode},
165
        categorycode => $category->{categorycode},
Lines 160-165 Koha::CirculationRules->set_rules( Link Here
160
        rules        => {
168
        rules        => {
161
            reservesallowed  => 5,
169
            reservesallowed  => 5,
162
            holds_per_record => 5,
170
            holds_per_record => 5,
171
            holds_per_day    => 5,
163
        }
172
        }
164
    }
173
    }
165
);
174
);
Lines 167-172 Koha::CirculationRules->set_rules( Link Here
167
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->biblionumber );
176
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->biblionumber );
168
is( $max, 5, 'GetMaxPatronHoldsForRecord returns max of 5' );
177
is( $max, 5, 'GetMaxPatronHoldsForRecord returns max of 5' );
169
178
179
$holds_per_day = $biblio->allowed_holds( $patron_obj );
180
is( $holds_per_day, 5, "GetAllowedHoldsForPatronToday returns max of 4" );
181
170
Koha::CirculationRules->set_rules(
182
Koha::CirculationRules->set_rules(
171
    {
183
    {
172
        categorycode => undef,
184
        categorycode => undef,
Lines 175-180 Koha::CirculationRules->set_rules( Link Here
175
        rules        => {
187
        rules        => {
176
            reservesallowed  => 9,
188
            reservesallowed  => 9,
177
            holds_per_record => 9,
189
            holds_per_record => 9,
190
            holds_per_day    => 9,
178
        }
191
        }
179
    }
192
    }
180
);
193
);
Lines 216-221 Koha::CirculationRules->set_rules( Link Here
216
        rules        => {
229
        rules        => {
217
            reservesallowed  => 3,
230
            reservesallowed  => 3,
218
            holds_per_record => 2,
231
            holds_per_record => 2,
232
            holds_per_day    => 3,
219
        }
233
        }
220
    }
234
    }
221
);
235
);
222
- 

Return to bug 15565