From 15d95a74e4712139ae7b377a5879d66e6d0d5277 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 29 Oct 2019 12:28:53 -0300 Subject: [PATCH] Bug 14697: Add Koha::Patron->return_claims Adds the ability to get a list of a patron's return claims directly from the Patron object. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Lisette Scheer Signed-off-by: Martin Renvoize --- Koha/Patron.pm | 12 +++++++ t/db_dependent/Circulation/ReturnClaims.t | 42 ++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 55855247e9..8e501fcfb1 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1129,6 +1129,18 @@ sub old_holds { return Koha::Old::Holds->_new_from_dbic($old_holds_rs); } +=head3 return_claims + +my $return_claims = $patron->return_claims + +=cut + +sub return_claims { + my ($self) = @_; + my $return_claims = $self->_result->return_claims_borrowernumbers; + return Koha::Checkouts::ReturnClaims->_new_from_dbic( $return_claims ); +} + =head3 notice_email_address my $email = $patron->notice_email_address; diff --git a/t/db_dependent/Circulation/ReturnClaims.t b/t/db_dependent/Circulation/ReturnClaims.t index 5b094ef626..3681650464 100644 --- a/t/db_dependent/Circulation/ReturnClaims.t +++ b/t/db_dependent/Circulation/ReturnClaims.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 1; +use Test::More tests => 2; use Test::MockModule; use Test::Warn; @@ -93,4 +93,44 @@ subtest 'Test Koha::Checkout::claim_returned' => sub { ok( $claim->created_on, "Claim created_on is set" ); }; +subtest 'Test Koha::Patronn::return_claims' => sub { + plan tests => 7; + + t::lib::Mocks::mock_preference( 'ClaimReturnedLostValue', 1 ); + my $biblio = $builder->build_object( { class => 'Koha::Biblios' } ); + my $item = $builder->build_object( + { + class => 'Koha::Items', + value => { + biblionumber => $biblio->biblionumber, + notforloan => 0, + itemlost => 0, + withdrawn => 0, + } + } + ); + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + my $checkout = AddIssue( $patron->unblessed, $item->barcode ); + + $checkout->claim_returned( + { + created_by => $patron->id, + notes => "Test note", + } + ); + + my $claims = $patron->return_claims; + + is( $claims->count, 1, "Got back correct number of claims" ); + + my $claim = $claims->next; + + is( $claim->issue_id, $checkout->id, "Claim issue id matches" ); + is( $claim->itemnumber, $item->id, "Claim itemnumber matches" ); + is( $claim->borrowernumber, $patron->id, "Claim borrowernumber matches" ); + is( $claim->notes, "Test note", "Claim notes match" ); + is( $claim->created_by, $patron->id, "Claim created_by matches" ); + ok( $claim->created_on, "Claim created_on is set" ); +}; + $schema->storage->txn_rollback; -- 2.39.5