diff --git a/Koha/Hold.pm b/Koha/Hold.pm index f275530d97..2775e59184 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -645,6 +645,20 @@ sub cancellation_requests { return Koha::Hold::CancellationRequests->search( { hold_id => $self->id } ); } +=head3 cancellation_requested + + if ( $hold->cancellation_requested ) { ... } + +Returns true if a cancellation request has been placed for the hold. + +=cut + +sub cancellation_requested { + my ($self) = @_; + + return Koha::Hold::CancellationRequests->search( { hold_id => $self->id } )->count > 0; +} + =head3 cancel my $cancel_hold = $hold->cancel( diff --git a/t/db_dependent/Koha/Hold.t b/t/db_dependent/Koha/Hold.t index cc90dafb89..50d6ffdbe9 100755 --- a/t/db_dependent/Koha/Hold.t +++ b/t/db_dependent/Koha/Hold.t @@ -728,9 +728,9 @@ subtest 'suspend_hold() and resume() tests' => sub { $schema->storage->txn_rollback; }; -subtest 'cancellation_requests() and add_cancellation_request() tests' => sub { +subtest 'cancellation_requests(), add_cancellation_request() and cancellation_requested() tests' => sub { - plan tests => 4; + plan tests => 6; $schema->storage->txn_begin; @@ -739,6 +739,7 @@ subtest 'cancellation_requests() and add_cancellation_request() tests' => sub { my $hold = $builder->build_object( { class => 'Koha::Holds', } ); is( $hold->cancellation_requests->count, 0 ); + ok( !$hold->cancellation_requested ); # Add two cancellation requests my $request_1 = $hold->add_cancellation_request; @@ -756,6 +757,7 @@ subtest 'cancellation_requests() and add_cancellation_request() tests' => sub { is( $request_2->creation_date, $creation_date, 'Passed creation_date set' ); is( $hold->cancellation_requests->count, 2 ); + ok( $hold->cancellation_requested ); $schema->storage->txn_rollback; };