From 862b84555ae2d7189a5f85f04aafd73fc45cb48f Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 5 Jun 2023 13:53:18 -0300 Subject: [PATCH] Bug 21983: Add Koha::Biblio->ill_requests This patch adds a new method, used for retrieving the linked ill requests for a biblio. To test: 1. Apply this patch and run: $ ktd --shell k$ prove t/db_dependent/Koha/Biblio.t => SUCCESS: Tests pass! Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi (cherry picked from commit a9759b3b0e1b9f4812f994012c109d99f9a9aa89) --- Koha/Biblio.pm | 30 ++++++++++++++++++++++++++++++ Koha/Schema/Result/Biblio.pm | 7 +++++++ t/db_dependent/Koha/Biblio.t | 28 +++++++++++++++++++++++++++- 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 9819e68e42..131e1effb7 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -39,6 +39,7 @@ use Koha::Cache::Memory::Lite; use Koha::Checkouts; use Koha::CirculationRules; use Koha::Exceptions; +use Koha::Illrequests; use Koha::Item::Transfer::Limits; use Koha::Items; use Koha::Libraries; @@ -135,6 +136,35 @@ sub active_orders { return $self->orders->search({ datecancellationprinted => undef }); } +=head3 tickets + + my $tickets = $biblio->tickets(); + +Returns all tickets linked to the biblio + +=cut + +sub tickets { + my ( $self ) = @_; + my $rs = $self->_result->tickets; + return Koha::Tickets->_new_from_dbic( $rs ); +} + +=head3 ill_requests + + my $ill_requests = $biblio->ill_requests(); + +Returns a Koha::Illrequests object + +=cut + +sub ill_requests { + my ( $self ) = @_; + + my $ill_requests = $self->_result->ill_requests; + return Koha::Illrequests->_new_from_dbic($ill_requests); +} + =head3 item_groups my $item_groups = $biblio->item_groups(); diff --git a/Koha/Schema/Result/Biblio.pm b/Koha/Schema/Result/Biblio.pm index f7dd7a39d0..d35987a1f2 100644 --- a/Koha/Schema/Result/Biblio.pm +++ b/Koha/Schema/Result/Biblio.pm @@ -596,6 +596,13 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +__PACKAGE__->has_many( + "ill_requests", + "Koha::Schema::Result::Illrequest", + { "foreign.biblio_id" => "self.biblionumber" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + __PACKAGE__->has_one( "metadata", "Koha::Schema::Result::BiblioMetadata", diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index ebbfcf9a34..ee3a7290ac 100755 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 22; # +1 +use Test::More tests => 23; use Test::Exception; use Test::Warn; @@ -1033,6 +1033,32 @@ subtest 'Recalls tests' => sub { $schema->storage->txn_rollback; }; +subtest 'ill_requests() tests' => sub { + + plan tests => 3; + + $schema->storage->txn_begin; + + my $biblio = $builder->build_sample_biblio; + + my $rs = $biblio->ill_requests; + is( ref($rs), 'Koha::Illrequests' ); + is( $rs->count, 0, 'No linked requests' ); + + foreach ( 1..10 ) { + $builder->build_object( + { + class => 'Koha::Illrequests', + value => { biblio_id => $biblio->id } + } + ); + } + + is( $biblio->ill_requests->count, 10, 'Linked requests are present' ); + + $schema->storage->txn_rollback; +}; + subtest 'item_groups() tests' => sub { plan tests => 6; -- 2.39.2