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 145-151 sub get_items_that_can_fill { Link Here
145
    )->filter_by_for_hold();
145
    )->filter_by_for_hold();
146
}
146
}
147
147
148
=head3 type
148
=head3 filter_by_has_pending_cancellation_requests
149
150
    my $with_cancellation_reqs = $holds->filter_by_has_cancellation_requests;
151
152
Returns a filtered resultset only containing holds that pending cancellation requests.
153
154
=cut
155
156
sub filter_by_has_pending_cancellation_requests {
157
    my ($self) = @_;
158
159
    return $self->search( { 'cancellation_requests.status' => 'requested' },
160
        { join => 'cancellation_requests' } );
161
}
162
163
=head2 Internal methods
164
165
=head3 _type
149
166
150
=cut
167
=cut
151
168
(-)a/Koha/Schema/Result/Reserve.pm (+7 lines)
Lines 491-494 __PACKAGE__->belongs_to( Link Here
491
  },
491
  },
492
);
492
);
493
493
494
__PACKAGE__->has_many(
495
  "cancellation_requests",
496
  "Koha::Schema::Result::HoldCancellationRequest",
497
  { "foreign.hold_id" => "self.reserve_id" },
498
  { cascade_copy => 0, cascade_delete => 0 },
499
);
500
494
1;
501
1;
(-)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 638-641 subtest 'set_waiting+patron_expiration_date' => sub { Link Here
638
638
639
$schema->storage->txn_rollback;
639
$schema->storage->txn_rollback;
640
640
641
1;
641
subtest 'filter_by_has_pending_cancellation_requests() tests' => sub {
642
643
    plan tests => 4;
644
645
    $schema->storage->txn_begin;
646
647
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
648
649
    my $item_1 = $builder->build_sample_item;
650
    my $item_2 = $builder->build_sample_item;
651
    my $item_3 = $builder->build_sample_item;
652
653
    my $hold_1 = $builder->build_object(
654
        {
655
            class => 'Koha::Holds',
656
            value => {
657
                found          => 'W',
658
                itemnumber     => $item_1->id,
659
                biblionumber   => $item_1->biblionumber,
660
                borrowernumber => $patron->id
661
            }
662
        }
663
    );
664
    my $hold_2 = $builder->build_object(
665
        {
666
            class => 'Koha::Holds',
667
            value => {
668
                found          => 'W',
669
                itemnumber     => $item_2->id,
670
                biblionumber   => $item_2->biblionumber,
671
                borrowernumber => $patron->id
672
            }
673
        }
674
    );
675
    my $hold_3 = $builder->build_object(
676
        {
677
            class => 'Koha::Holds',
678
            value => {
679
                found          => 'W',
680
                itemnumber     => $item_3->id,
681
                biblionumber   => $item_3->biblionumber,
682
                borrowernumber => $patron->id
683
            }
684
        }
685
    );
686
687
    my $rs = Koha::Holds->search(
688
        { reserve_id => [ $hold_1->id, $hold_2->id, $hold_3->id ] } );
689
690
    is( $rs->count, 3 );
691
692
    my $filtered_rs = $rs->filter_by_has_pending_cancellation_requests;
693
694
    is( $filtered_rs->count, 0 );
695
696
    $hold_2->add_cancellation_request( { requester_id => $patron->id } );
697
698
    $filtered_rs = $rs->filter_by_has_pending_cancellation_requests;
699
700
    is( $filtered_rs->count,    1 );
701
    is( $filtered_rs->next->id, $hold_2->id );
702
703
    $schema->storage->txn_rollback;
704
};
642
- 

Return to bug 22456