From 54dff2532d399cdaecf5b16f5eee997d4c269797 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 --- 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 92580725db..b25d30ab73 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1131,6 +1131,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.21.0 (Apple Git-122)