Bug 32529: Add Koha::Holds->filter_by_found

This patch adds a method for filtering Koha::Holds resultsets by the
status belonging to Koha's concept of 'found'.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Holds.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Tomas Cohen Arazi 2022-12-26 13:02:25 -03:00
parent b48ea1b452
commit f8b7a5a9cd
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
2 changed files with 44 additions and 1 deletions

View File

@ -34,8 +34,21 @@ Koha::Holds - Koha Hold object set class
=head2 Class methods
=head3 filter_by_found
my $found_holds = $holds->filter_by_found;
Returns a filtered resultset without holds that are considered I<found>.
i.e. 'P', 'T' and 'W'.
=cut
sub filter_by_found {
my ($self) = @_;
return $self->search( { found => [ 'P', 'T', 'W' ] } );
}
=head3 waiting
returns a set of holds that are waiting from an existing set

View File

@ -19,7 +19,7 @@
use Modern::Perl;
use Test::More tests => 10;
use Test::More tests => 11;
use Test::Warn;
use C4::Circulation qw( AddIssue );
@ -670,6 +670,36 @@ subtest 'Test Koha::Hold::item_group' => sub {
$schema->storage->txn_rollback;
subtest 'filter_by_found() tests' => sub {
plan tests => 5;
$schema->storage->txn_begin;
my $unfilled = $builder->build_object( { class => 'Koha::Holds', value => { found => undef } } );
my $processing = $builder->build_object( { class => 'Koha::Holds', value => { found => 'P' } } );
my $in_transit = $builder->build_object( { class => 'Koha::Holds', value => { found => 'T' } } );
my $waiting = $builder->build_object( { class => 'Koha::Holds', value => { found => 'W' } } );
my $holds = Koha::Holds->search(
{ reserve_id => [ $unfilled->id, $processing->id, $in_transit->id, $waiting->id ] },
{ order_by => ['reserve_id'] }
);
is( $holds->count, 4, 'Resultset count is correct' );
my $found_holds = $holds->filter_by_found;
is( $found_holds->count, 3, 'Resultset count is correct' );
ok( $found_holds->next->is_in_processing, 'Status is correct (P)' );
ok( $found_holds->next->is_in_transit, 'Status is correct (T)' );
ok( $found_holds->next->is_waiting, 'Status is correct (W)' );
$schema->storage->txn_rollback;
};
subtest 'filter_by_has_cancellation_requests() and filter_out_has_cancellation_requests() tests' => sub {
plan tests => 7;