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 144-150 sub get_items_that_can_fill { Link Here
144
    )->filter_by_for_hold();
144
    )->filter_by_for_hold();
145
}
145
}
146
146
147
=head3 type
147
=head3 filter_by_has_pending_cancellation_requests
148
149
    my $with_cancellation_reqs = $holds->filter_by_has_cancellation_requests;
150
151
Returns a filtered resultset only containing holds that pending cancellation requests.
152
153
=cut
154
155
sub filter_by_has_pending_cancellation_requests {
156
    my ($self) = @_;
157
158
    return $self->search( { 'cancellation_requests.status' => 'requested' },
159
        { join => 'cancellation_requests' } );
160
}
161
162
=head2 Internal methods
163
164
=head3 _type
148
165
149
=cut
166
=cut
150
167
(-)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 629-632 subtest 'set_waiting+patron_expiration_date' => sub { Link Here
629
629
630
$schema->storage->txn_rollback;
630
$schema->storage->txn_rollback;
631
631
632
1;
632
subtest 'filter_by_has_pending_cancellation_requests() tests' => sub {
633
634
    plan tests => 4;
635
636
    $schema->storage->txn_begin;
637
638
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
639
640
    my $item_1 = $builder->build_sample_item;
641
    my $item_2 = $builder->build_sample_item;
642
    my $item_3 = $builder->build_sample_item;
643
644
    my $hold_1 = $builder->build_object(
645
        {
646
            class => 'Koha::Holds',
647
            value => {
648
                found          => 'W',
649
                itemnumber     => $item_1->id,
650
                biblionumber   => $item_1->biblionumber,
651
                borrowernumber => $patron->id
652
            }
653
        }
654
    );
655
    my $hold_2 = $builder->build_object(
656
        {
657
            class => 'Koha::Holds',
658
            value => {
659
                found          => 'W',
660
                itemnumber     => $item_2->id,
661
                biblionumber   => $item_2->biblionumber,
662
                borrowernumber => $patron->id
663
            }
664
        }
665
    );
666
    my $hold_3 = $builder->build_object(
667
        {
668
            class => 'Koha::Holds',
669
            value => {
670
                found          => 'W',
671
                itemnumber     => $item_3->id,
672
                biblionumber   => $item_3->biblionumber,
673
                borrowernumber => $patron->id
674
            }
675
        }
676
    );
677
678
    my $rs = Koha::Holds->search(
679
        { reserve_id => [ $hold_1->id, $hold_2->id, $hold_3->id ] } );
680
681
    is( $rs->count, 3 );
682
683
    my $filtered_rs = $rs->filter_by_has_pending_cancellation_requests;
684
685
    is( $filtered_rs->count, 0 );
686
687
    $hold_2->add_cancellation_request( { requester_id => $patron->id } );
688
689
    $filtered_rs = $rs->filter_by_has_pending_cancellation_requests;
690
691
    is( $filtered_rs->count,    1 );
692
    is( $filtered_rs->next->id, $hold_2->id );
693
694
    $schema->storage->txn_rollback;
695
};
633
- 

Return to bug 22456