Bug 28588: Add Koha::Checkouts::ReturnClaim->resolve

This patch introduces a high-level method for resolving claims.
The behavior intends to replace the code in the API controller that is
used for resolving a claim.

To test:
1. Apply this patches
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Checkouts/ReturnClaim.t
=> SUCCESS: Tests pass
3. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Tomás Cohen Arazi 2021-06-18 16:15:15 -03:00 committed by Jonathan Druart
parent 471fb27313
commit 9964bd4b58

View file

@ -22,6 +22,7 @@ use Modern::Perl;
use base qw(Koha::Object);
use Koha::Checkouts;
use Koha::Exceptions;
use Koha::Exceptions::Checkouts::ReturnClaims;
use Koha::Old::Checkouts;
use Koha::Patrons;
@ -79,6 +80,50 @@ sub patron {
return Koha::Patron->_new_from_dbic( $borrower ) if $borrower;
}
=head3 resolve
$claim->resolve(
{
resolution => $resolution,
resolved_by => $patron_id,
[ resolved_on => $dt
new_lost_status => $status, ]
}
);
Resolve the claim.
=cut
sub resolve {
my ( $self, $params ) = @_;
my @mandatory = ( 'resolution', 'resolved_by' );
for my $param (@mandatory) {
unless ( defined( $params->{$param} ) ) {
Koha::Exceptions::MissingParameter->throw( error => "The $param parameter is mandatory" );
}
}
$self->_result->result_source->schema->txn_do(
sub {
$self->set(
{ resolution => $params->{resolution},
resolved_by => $params->{resolved_by},
resolved_on => $params->{resolved_on} // \'NOW()',
updated_by => $params->{resolved_by}
}
)->store;
if ( defined $params->{new_lost_status} ) {
$self->checkout->item->itemlost( $params->{new_lost_status} )->store;
}
}
);
return $self;
}
=head3 to_api_mapping
This method returns the mapping for representing a Koha::Checkouts::ReturnClaim object