From e3437ae7bd0c06d583233140985bb5ad3af66e98 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 --- 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 542e52a7ccc..dc7e6b7037f 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 b5c12b7e6bf..c3121bb954d 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.25.1