From 9964bd4b58bd114e052d5448a5a2fe4c1dfcf3d3 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 18 Jun 2021 16:15:15 -0300 Subject: [PATCH] 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 Signed-off-by: David Nind Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart --- Koha/Checkouts/ReturnClaim.pm | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/Koha/Checkouts/ReturnClaim.pm b/Koha/Checkouts/ReturnClaim.pm index 624c725949..3488e51626 100644 --- a/Koha/Checkouts/ReturnClaim.pm +++ b/Koha/Checkouts/ReturnClaim.pm @@ -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 -- 2.39.5