Bugzilla – Attachment 94846 Details for
Bug 14697
Extend and enhance "Claims returned" lost status
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14697: Add Koha::Checkout->claim_returned
Bug-14697-Add-KohaCheckout-claimreturned.patch (text/plain), 6.04 KB, created by
Kyle M Hall (khall)
on 2019-10-29 19:20:42 UTC
(
hide
)
Description:
Bug 14697: Add Koha::Checkout->claim_returned
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2019-10-29 19:20:42 UTC
Size:
6.04 KB
patch
obsolete
>From 2e8a05b842c43488836c0fe9b338bc65a22d5271 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Tue, 29 Oct 2019 12:28:36 -0300 >Subject: [PATCH] Bug 14697: Add Koha::Checkout->claim_returned > >Adds the ability to generate a return claim from a Checkout object. > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> > >Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com> > >Signed-off-by: Lisette Scheer <lisetteslatah@gmail.com> >--- > Koha/Checkout.pm | 56 ++++++++++++- > t/db_dependent/Circulation/ReturnClaims.t | 96 +++++++++++++++++++++++ > 2 files changed, 150 insertions(+), 2 deletions(-) > create mode 100644 t/db_dependent/Circulation/ReturnClaims.t > >diff --git a/Koha/Checkout.pm b/Koha/Checkout.pm >index 1cba41ea3f..f789de6d8d 100644 >--- a/Koha/Checkout.pm >+++ b/Koha/Checkout.pm >@@ -21,9 +21,11 @@ package Koha::Checkout; > use Modern::Perl; > > use Carp; >+use DateTime; >+use Try::Tiny; > >+use Koha::Checkouts::ReturnClaims; > use Koha::Database; >-use DateTime; > use Koha::DateUtils; > use Koha::Items; > >@@ -35,7 +37,7 @@ Koha::Checkout - Koha Checkout object class > > =head1 API > >-=head2 Class Methods >+=head2 Class methods > > =cut > >@@ -109,6 +111,56 @@ sub to_api_mapping { > }; > } > >+=head3 claim_returned >+ >+my $return_claim = $checkout->claim_returned(); >+ >+=cut >+ >+sub claim_returned { >+ my ( $self, $params ) = @_; >+ >+ my $charge_lost_fee = $params->{charge_lost_fee}; >+ >+ try { >+ $self->_result->result_source->schema->txn_do( >+ sub { >+ my $claim = Koha::Checkouts::ReturnClaim->new( >+ { >+ issue_id => $self->id, >+ itemnumber => $self->itemnumber, >+ borrowernumber => $self->borrowernumber, >+ notes => $params->{notes}, >+ created_by => $params->{created_by}, >+ created_on => dt_from_string, >+ } >+ )->store(); >+ >+ my $ClaimReturnedLostValue = C4::Context->preference('ClaimReturnedLostValue'); >+ C4::Items::ModItem( { itemlost => $ClaimReturnedLostValue }, undef, $self->itemnumber ); >+ >+ my $ClaimReturnedChargeFee = C4::Context->preference('ClaimReturnedChargeFee'); >+ $charge_lost_fee = >+ $ClaimReturnedChargeFee eq 'charge' ? 1 >+ : $ClaimReturnedChargeFee eq 'no_charge' ? 0 >+ : $charge_lost_fee; # $ClaimReturnedChargeFee eq 'ask' >+ C4::Circulation::LostItem( $self->itemnumber, 'claim_returned' ) if $charge_lost_fee; >+ >+ return $claim; >+ } >+ ); >+ } >+ catch { >+ if ( $_->isa('Koha::Exceptions::Exception') ) { >+ $_->rethrow(); >+ } >+ else { >+ # ? >+ Koha::Exceptions::Exception->throw( "Unhandled exception" ); >+ } >+ }; >+} >+ > =head2 Internal methods > > =head3 _type >diff --git a/t/db_dependent/Circulation/ReturnClaims.t b/t/db_dependent/Circulation/ReturnClaims.t >new file mode 100644 >index 0000000000..5b094ef626 >--- /dev/null >+++ b/t/db_dependent/Circulation/ReturnClaims.t >@@ -0,0 +1,96 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 1; >+use Test::MockModule; >+use Test::Warn; >+ >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+ >+use C4::Circulation; >+ >+#Â Mock userenv, used by AddIssue >+my $branch; >+my $manager_id; >+my $context = Test::MockModule->new('C4::Context'); >+$context->mock( >+ 'userenv', >+ sub { >+ return { >+ branch => $branch, >+ number => $manager_id, >+ firstname => "Adam", >+ surname => "Smaith" >+ }; >+ } >+); >+ >+my $schema = Koha::Database->schema; >+$schema->storage->txn_begin; >+ >+my $builder = t::lib::TestBuilder->new(); >+Koha::IssuingRules->search->delete; >+my $rule = Koha::IssuingRule->new( >+ { >+ categorycode => '*', >+ itemtype => '*', >+ branchcode => '*', >+ issuelength => 1, >+ } >+); >+$rule->store(); >+ >+$branch = $builder->build( { source => 'Branch' } )->{branchcode}; >+ >+subtest 'Test Koha::Checkout::claim_returned' => sub { >+ plan tests => 6; >+ >+ 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 ); >+ >+ my $claim = $checkout->claim_returned( >+ { >+ created_by => $patron->id, >+ notes => "Test note", >+ } >+ ); >+ >+ 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)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14697
:
92407
|
92408
|
92409
|
92410
|
92962
|
92963
|
92964
|
92965
|
93005
|
93006
|
93007
|
93008
|
93012
|
93013
|
93014
|
93015
|
93017
|
93038
|
93039
|
93040
|
93041
|
93042
|
93061
|
93062
|
93063
|
93064
|
93065
|
93952
|
93953
|
93954
|
93955
|
93956
|
93957
|
93959
|
94842
|
94843
|
94844
|
94845
| 94846 |
94847
|
94848
|
94849
|
94850
|
94851
|
94852
|
94853
|
94854
|
94857
|
94877
|
94878