From 01843430460daf3268b8b07aafe32fcc3363b6d3 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 30 Apr 2021 15:13:26 +0200 Subject: [PATCH] Bug 28271: Add the ability to set a new lost status when a claim is resolved When a claim is resolved the librarian should be able to edit the lost status of the item. It is also letting a way out when BlockReturnOfLostItems is set (the lost status is stuck on ClaimReturnedLostValue as we remove the option to edit itemlost on the item edit form). Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Jonathan Druart (cherry picked from commit 58db137c0aeda1f0a1d5f1972f1f415c31be62ed) Signed-off-by: Andrew Fuerste-Henry --- Koha/REST/V1/ReturnClaims.pm | 9 +++++++-- .../prog/en/includes/checkouts-table.inc | 9 +++++++++ koha-tmpl/intranet-tmpl/prog/js/checkouts.js | 6 ++++-- t/db_dependent/api/v1/return_claims.t | 19 ++++++++++++++++++- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/Koha/REST/V1/ReturnClaims.pm b/Koha/REST/V1/ReturnClaims.pm index 118e11782a..bcc210902a 100644 --- a/Koha/REST/V1/ReturnClaims.pm +++ b/Koha/REST/V1/ReturnClaims.pm @@ -160,8 +160,9 @@ sub resolve_claim { return try { - my $resolved_by = $body->{resolved_by}; - my $resolution = $body->{resolution}; + my $resolved_by = $body->{resolved_by}; + my $resolution = $body->{resolution}; + my $new_lost_status = $body->{new_lost_status}; my $user = $c->stash('koha.user'); $resolved_by //= $user->borrowernumber; @@ -174,6 +175,10 @@ sub resolve_claim { updated_by => $resolved_by, } )->store; + + if ( defined $new_lost_status ) { + $claim->checkout->item->itemlost($new_lost_status)->store; + } $claim->discard_changes; return $c->render( diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table.inc index 9a2f74d43f..2f9bf6cb17 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table.inc @@ -145,6 +145,15 @@ [% END %] + + + [% SET itemlost = AuthorisedValues.GetAuthValueDropbox('LOST') %] + diff --git a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js index c52d72bca8..0716d72363 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js +++ b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js @@ -1195,14 +1195,16 @@ $(document).ready(function() { $(document).on('click', '#claims-returned-resolved-modal-btn-submit', function(e) { let resolution = $('#claims-returned-resolved-modal-resolved-code').val(); + let new_lost_status = $('#new_lost_status').val(); let id = $('#claims-returned-resolved-modal-id').val(); $('#claims-returned-resolved-modal-btn-submit-spinner').show(); $('#claims-returned-resolved-modal-btn-submit-icon').hide(); params = { - resolution: resolution, - resolved_by: logged_in_user_borrowernumber + resolution: resolution, + resolved_by: logged_in_user_borrowernumber, + new_lost_status: new_lost_status }; $.ajax({ diff --git a/t/db_dependent/api/v1/return_claims.t b/t/db_dependent/api/v1/return_claims.t index aac1a3db5e..2123b5e0ae 100755 --- a/t/db_dependent/api/v1/return_claims.t +++ b/t/db_dependent/api/v1/return_claims.t @@ -175,7 +175,7 @@ subtest 'update_notes() tests' => sub { subtest 'resolve_claim() tests' => sub { - plan tests => 9; + plan tests => 13; $schema->storage->txn_begin; @@ -193,6 +193,10 @@ subtest 'resolve_claim() tests' => sub { t::lib::Mocks::mock_userenv( { branchcode => $item->homebranch } ); # needed by AddIssue + # Picking 1 that should exist + my $ClaimReturnedLostValue = 1; + t::lib::Mocks::mock_preference('ClaimReturnedLostValue', $ClaimReturnedLostValue); + my $issue = AddIssue( $librarian->unblessed, $item->barcode, dt_from_string->add( weeks => 2 ) ); my $claim = $issue->claim_returned( @@ -225,6 +229,19 @@ subtest 'resolve_claim() tests' => sub { is( $claim->updated_by, $librarian->id ); ok( $claim->resolved_on ); + is( $claim->checkout->item->itemlost, $ClaimReturnedLostValue ); + + $claim->update({resolution => undef, resolved_by => undef, resolved_on => undef }); + $t->put_ok( + "//$userid:$password@/api/v1/return_claims/$claim_id/resolve" => json => { + resolved_by => $librarian->id, + resolution => "FOUNDINLIB", + new_lost_status => 0, + } + )->status_is(200); + is( $claim->get_from_storage->checkout->item->itemlost, 0 ); + + # Make sure the claim doesn't exist on the DB anymore $claim->delete; -- 2.39.5