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

(-)a/Koha/Biblio.pm (+28 lines)
Lines 797-802 sub cover_images { Link Here
797
    return Koha::CoverImages->_new_from_dbic($cover_images_rs);
797
    return Koha::CoverImages->_new_from_dbic($cover_images_rs);
798
}
798
}
799
799
800
=head3 allowed_holds
801
802
    my $holds_allowed_on_record_today = $biblio->allowed_holds( $patron_obj );
803
804
Calculates and returns the number of item-level holds a borrower is allowed to place on the record on a single day.
805
806
=cut
807
808
sub allowed_holds {
809
810
    my ( $self, $patron ) = @_;
811
812
    my $controlbranch = C4::Context->preference('ReservesControlBranch');
813
    my $holds_allowed = 0;
814
    foreach my $item ( $self->items()->as_list() ) {
815
        my $holds_per_day = Koha::CirculationRules->get_effective_rule({
816
            rule_name => 'holds_per_day',
817
            categorycode => $patron->categorycode,
818
            itemtype => $item->effective_itemtype(),
819
            branchcode => ( $controlbranch and $controlbranch eq 'PatronLibrary' ) ? $patron->branchcode : $item->homebranch,
820
        });
821
        $holds_per_day = $holds_per_day ? $holds_per_day->rule_value : 0;
822
        if ( $holds_per_day ) {
823
            $holds_allowed = $holds_per_day if $holds_per_day > $holds_allowed;
824
        }
825
    }
826
    return $holds_allowed;
827
}
800
828
801
=head3 to_api
829
=head3 to_api
802
830
(-)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