From 0e0d1f134db7e464bff6cc109324976dab4a99f4 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 9 May 2023 11:00:48 +0200 Subject: [PATCH] Bug 32894: (follow-up) Koha::Item->last_returned_by Signed-off-by: Nick Clemens (cherry picked from commit 9ad94cf3e06836da81cfef272f65ae9d9fe9cf3e) Signed-off-by: Martin Renvoize --- Koha/Item.pm | 16 ++++++++++++---- t/db_dependent/Circulation/StoreLastBorrower.t | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index 024cc2a14a..6012846c52 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -596,17 +596,25 @@ sub get_transfers { =head3 last_returned_by -Gets the last borrower to return an item. +Gets and sets the last patron to return an item. -$last_returned_by = $item->last_returned_by(); +Accepts a patron's id (borrowernumber) and returns Koha::Patron objects + +$item->last_returned_by( $borrowernumber ); + +my $patron = $item->last_returned_by(); =cut sub last_returned_by { - my ( $self ) = @_; + my ( $self, $borrowernumber ) = @_; + if ( $borrowernumber ) { + $self->_result->update_or_create_related('last_returned_by', + { borrowernumber => $borrowernumber, itemnumber => $self->itemnumber } ); + } my $rs = $self->_result->last_returned_by; return unless $rs; - return Koha::Patron->_new_from_dbic($rs); + return Koha::Patron->_new_from_dbic($rs->borrowernumber); } =head3 can_article_request diff --git a/t/db_dependent/Circulation/StoreLastBorrower.t b/t/db_dependent/Circulation/StoreLastBorrower.t index b5c12b7e6b..c3121bb954 100755 --- a/t/db_dependent/Circulation/StoreLastBorrower.t +++ b/t/db_dependent/Circulation/StoreLastBorrower.t @@ -98,7 +98,7 @@ subtest 'Test StoreLastBorrower' => sub { ); $patron_object = Koha::Patrons->find( $patron->{borrowernumber} ); - $item->last_returned_by($patron_object); + $item->last_returned_by($patron_object->borrowernumber); $item = $item->get_from_storage; my $patron_object2 = $item->last_returned_by(); is( $patron_object->id, $patron_object2->id, -- 2.39.5