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> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
parent
e97887bcbb
commit
f08de08858
2 changed files with 151 additions and 3 deletions
|
@ -21,9 +21,11 @@ package Koha::Checkout;
|
|||
use Modern::Perl;
|
||||
|
||||
use Carp;
|
||||
|
||||
use Koha::Database;
|
||||
use DateTime;
|
||||
use Try::Tiny;
|
||||
|
||||
use Koha::Checkouts::ReturnClaims;
|
||||
use Koha::Database;
|
||||
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
|
||||
|
|
96
t/db_dependent/Circulation/ReturnClaims.t
Normal file
96
t/db_dependent/Circulation/ReturnClaims.t
Normal file
|
@ -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;
|
Loading…
Reference in a new issue