From aff2a0163104a2cae3374f17e7d0fe79412b200a Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 23 Apr 2025 12:08:55 -0300 Subject: [PATCH] Bug 38340: Add Koha::Patron->ill_requests() accessor Signed-off-by: Tomas Cohen Arazi --- Koha/Patron.pm | 14 ++++++++++++++ Koha/Schema/Result/Borrower.pm | 7 +++++++ t/db_dependent/Koha/Patron.t | 24 +++++++++++++++++++++++- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index e7a35e57f11..56df7f9b8da 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -46,6 +46,7 @@ use Koha::Encryption; use Koha::Exceptions; use Koha::Exceptions::Password; use Koha::Holds; +use Koha::ILL::Requests; use Koha::Old::Checkouts; use Koha::OverdueRules; use Koha::Patron::Attributes; @@ -1481,6 +1482,19 @@ sub checkouts { return Koha::Checkouts->_new_from_dbic($checkouts); } +=head3 ill_requests + + my $ill_requests = $patron->ill_requests(); + +Method that returns the related I iterator. + +=cut + +sub ill_requests { + my ($self) = @_; + return Koha::ILL::Requests->_new_from_dbic( scalar $self->_result->ill_requests ); +} + =head3 pending_checkouts my $pending_checkouts = $patron->pending_checkouts diff --git a/Koha/Schema/Result/Borrower.pm b/Koha/Schema/Result/Borrower.pm index 5621f628c9d..a24aaca0ba5 100644 --- a/Koha/Schema/Result/Borrower.pm +++ b/Koha/Schema/Result/Borrower.pm @@ -2230,6 +2230,13 @@ __PACKAGE__->add_columns( '+protected' => { is_boolean => 1 }, ); +__PACKAGE__->has_many( + "ill_requests", + "Koha::Schema::Result::Illrequest", + { "foreign.borrowernumber" => "self.borrowernumber" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 koha_objects_class Missing POD for koha_objects_class. diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t index 5197e53468f..dc2ed4dca07 100755 --- a/t/db_dependent/Koha/Patron.t +++ b/t/db_dependent/Koha/Patron.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 38; +use Test::More tests => 39; use Test::Exception; use Test::Warn; use Time::Fake; @@ -2846,3 +2846,25 @@ subtest 'preferred_name' => sub { is( $patron->preferred_name, "Preferred again", "Preferred name set on update when passed" ); }; + +subtest 'ill_requests() tests' => sub { + + plan tests => 3; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + + my $reqs_rs = $patron->ill_requests(); + is( ref($reqs_rs), 'Koha::ILL::Requests', 'Returned object type is correct' ); + is( $reqs_rs->count, 0, 'No linked ILL requests for the patron' ); + + # add two requests + $builder->build_object( { class => 'Koha::ILL::Requests', value => { borrowernumber => $patron->id } } ); + $builder->build_object( { class => 'Koha::ILL::Requests', value => { borrowernumber => $patron->id } } ); + + $reqs_rs = $patron->ill_requests(); + is( $reqs_rs->count, 2, 'Two linked ILL requests for the patron' ); + + $schema->storage->txn_rollback; +}; -- 2.49.0