Bug 29087: Prevent filter_by_for_hold to crash if default holdallowed is not_allowed

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Jonathan Druart 2021-11-19 13:27:44 +01:00 committed by Martin Renvoize
parent 6a321c6ee4
commit 8c804c1749
Signed by: martin.renvoize
GPG key ID: 422B469130441A0F
2 changed files with 33 additions and 4 deletions

View file

@ -61,15 +61,37 @@ placing a hold on one of those items.
sub filter_by_for_hold {
my ($self) = @_;
my @hold_not_allowed_itypes = Koha::CirculationRules->search(
my $default_rule = Koha::CirculationRules->get_effective_rule(
{
rule_name => 'holdallowed',
branchcode => undef,
categorycode => undef,
rule_value => 'not_allowed',
}
)->get_column('itemtype');
);
my @hold_not_allowed_itypes;
if ( $default_rule ) {
@hold_not_allowed_itypes = Koha::ItemTypes->search->get_column('itemtype');
my @hold_allowed_itypes = Koha::CirculationRules->search(
{
rule_name => 'holdallowed',
rule_value => { '!=' => 'not_allowed' },
branchcode => undef,
categorycode => undef,
}
)->get_column('itemtype');
@hold_not_allowed_itypes = array_minus( @hold_not_allowed_itypes, @hold_allowed_itypes )
} else {
@hold_not_allowed_itypes = Koha::CirculationRules->search(
{
rule_name => 'holdallowed',
branchcode => undef,
categorycode => undef,
rule_value => 'not_allowed',
}
)->get_column('itemtype');
}
push @hold_not_allowed_itypes, Koha::ItemTypes->search({ notforloan => 1 })->get_column('itemtype');
@hold_not_allowed_itypes = uniq @hold_not_allowed_itypes;
my $params = {
itemlost => 0,

View file

@ -533,6 +533,13 @@ subtest 'Desks' => sub {
subtest 'get_items_that_can_fill' => sub {
plan tests => 6;
Koha::CirculationRules->search(
{
rule_name => 'holdallowed',
rule_value => 'not_allowed',
}
)->delete;
my $biblio = $builder->build_sample_biblio;
my $itype_1 = $builder->build_object({ class => 'Koha::ItemTypes' }); # For 1, 2, 3, 4
my $itype_2 = $builder->build_object({ class => 'Koha::ItemTypes' });