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

(-)a/Koha/Holds.pm (-2 / +19 lines)
Lines 32-38 Koha::Holds - Koha Hold object set class Link Here
32
32
33
=head1 API
33
=head1 API
34
34
35
=head2 Class Methods
35
=head2 Class methods
36
36
37
=cut
37
=cut
38
38
Lines 148-154 sub get_items_that_can_fill { Link Here
148
    )->filter_by_for_hold();
148
    )->filter_by_for_hold();
149
}
149
}
150
150
151
=head3 type
151
=head3 filter_by_has_cancellation_requests
152
153
    my $with_cancellation_reqs = $holds->filter_by_has_cancellation_requests;
154
155
Returns a filtered resultset only containing holds that have cancellation requests.
156
157
=cut
158
159
sub filter_by_has_cancellation_requests {
160
    my ($self) = @_;
161
162
    return $self->search( { 'hold_cancellation_request_id' => { '!=' => undef } },
163
        { join => 'cancellation_requests' } );
164
}
165
166
=head2 Internal methods
167
168
=head3 _type
152
169
153
=cut
170
=cut
154
171
(-)a/t/db_dependent/Koha/Holds.t (-3 / +65 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 7;
22
use Test::More tests => 8;
23
use Test::Warn;
23
use Test::Warn;
24
24
25
use C4::Circulation qw( AddIssue );
25
use C4::Circulation qw( AddIssue );
Lines 644-647 subtest 'set_waiting+patron_expiration_date' => sub { Link Here
644
644
645
$schema->storage->txn_rollback;
645
$schema->storage->txn_rollback;
646
646
647
1;
647
subtest 'filter_by_has_cancellation_requests() tests' => sub {
648
649
    plan tests => 4;
650
651
    $schema->storage->txn_begin;
652
653
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
654
655
    my $item_1 = $builder->build_sample_item;
656
    my $item_2 = $builder->build_sample_item;
657
    my $item_3 = $builder->build_sample_item;
658
659
    my $hold_1 = $builder->build_object(
660
        {
661
            class => 'Koha::Holds',
662
            value => {
663
                found          => 'W',
664
                itemnumber     => $item_1->id,
665
                biblionumber   => $item_1->biblionumber,
666
                borrowernumber => $patron->id
667
            }
668
        }
669
    );
670
    my $hold_2 = $builder->build_object(
671
        {
672
            class => 'Koha::Holds',
673
            value => {
674
                found          => 'W',
675
                itemnumber     => $item_2->id,
676
                biblionumber   => $item_2->biblionumber,
677
                borrowernumber => $patron->id
678
            }
679
        }
680
    );
681
    my $hold_3 = $builder->build_object(
682
        {
683
            class => 'Koha::Holds',
684
            value => {
685
                found          => 'W',
686
                itemnumber     => $item_3->id,
687
                biblionumber   => $item_3->biblionumber,
688
                borrowernumber => $patron->id
689
            }
690
        }
691
    );
692
693
    my $rs = Koha::Holds->search(
694
        { reserve_id => [ $hold_1->id, $hold_2->id, $hold_3->id ] } );
695
696
    is( $rs->count, 3 );
697
698
    my $filtered_rs = $rs->filter_by_has_cancellation_requests;
699
700
    is( $filtered_rs->count, 0 );
701
702
    $hold_2->add_cancellation_request;
703
704
    $filtered_rs = $rs->filter_by_has_cancellation_requests;
705
706
    is( $filtered_rs->count,    1 );
707
    is( $filtered_rs->next->id, $hold_2->id );
708
709
    $schema->storage->txn_rollback;
710
};
648
- 

Return to bug 22456