Bug 32894: (follow-up) Koha::Item->last_returned_by
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
parent
70d7bb57d8
commit
9ad94cf3e0
2 changed files with 13 additions and 5 deletions
16
Koha/Item.pm
16
Koha/Item.pm
|
@ -596,17 +596,25 @@ sub get_transfers {
|
||||||
|
|
||||||
=head3 last_returned_by
|
=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
|
=cut
|
||||||
|
|
||||||
sub last_returned_by {
|
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;
|
my $rs = $self->_result->last_returned_by;
|
||||||
return unless $rs;
|
return unless $rs;
|
||||||
return Koha::Patron->_new_from_dbic($rs);
|
return Koha::Patron->_new_from_dbic($rs->borrowernumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
=head3 can_article_request
|
=head3 can_article_request
|
||||||
|
|
|
@ -98,7 +98,7 @@ subtest 'Test StoreLastBorrower' => sub {
|
||||||
);
|
);
|
||||||
$patron_object = Koha::Patrons->find( $patron->{borrowernumber} );
|
$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;
|
$item = $item->get_from_storage;
|
||||||
my $patron_object2 = $item->last_returned_by();
|
my $patron_object2 = $item->last_returned_by();
|
||||||
is( $patron_object->id, $patron_object2->id,
|
is( $patron_object->id, $patron_object2->id,
|
||||||
|
|
Loading…
Reference in a new issue