Bug 15516: (follow-up) fix count_holds() for CanBookBeReserved()

This patch adds search_attrs to count_holds() since these get
used with CanBookBeReserved.

Test plan:
0. Apply the patch
1. prove t/db_dependent/Koha/Holds.t t/db_dependent/Reserves/HoldGroup.t t/db_dependent/Reserves.t

Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
David Cook 2025-07-23 04:51:06 +00:00 committed by Lucas Gass
parent 8e11019993
commit c0ea7bd469
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
2 changed files with 7 additions and 5 deletions

View File

@ -397,7 +397,7 @@ sub CanBookBeReserved {
]
},
{ join => ['item'] }
)->count;
);
return { status => '' }
if defined $reservesallowed and $reservesallowed < $count + 1;

View File

@ -217,13 +217,15 @@ Return the number of holds, where a hold group is counted as one hold.
=cut
sub count_holds {
my ( $self, $search_params ) = @_;
$search_params = {} if !$search_params;
my ( $self, $search_params, $search_attrs ) = @_;
$search_params = {} if !$search_params;
$search_attrs = {} if !$search_attrs;
$search_params->{hold_group_id} = undef;
my $holds_without_group_count = $self->search($search_params)->count();
my $holds_without_group_count = $self->search( $search_params, $search_attrs )->count();
$search_params->{hold_group_id} = { '!=', undef };
my $hold_groups_count = $self->search( $search_params, { group_by => 'me.hold_group_id' } )->count();
$search_attrs->{group_by} = 'me.hold_group_id';
my $hold_groups_count = $self->search( $search_params, $search_attrs )->count();
return $holds_without_group_count + $hold_groups_count;
}