From 08867c49eff9739e587803dc3f1ec497313553b5 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). --- Koha/REST/V1/ReturnClaims.pm | 9 +++++++-- .../prog/en/includes/checkouts-table.inc | 9 +++++++++ koha-tmpl/intranet-tmpl/prog/js/checkouts.js | 2 ++ t/db_dependent/api/v1/return_claims.t | 19 ++++++++++++++++++- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/Koha/REST/V1/ReturnClaims.pm b/Koha/REST/V1/ReturnClaims.pm index d33a326e55e..5cabd034ac3 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; @@ -173,6 +174,10 @@ sub resolve_claim { resolved_on => \'NOW()', } )->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 9a2f74d43fc..2f9bf6cb172 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 fc67a264881..452e247a8ae 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js +++ b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js @@ -1142,6 +1142,7 @@ $(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(); @@ -1149,6 +1150,7 @@ $(document).ready(function() { params = { resolution: resolution, + new_lost_status: new_lost_status, updated_by: logged_in_user_borrowernumber }; diff --git a/t/db_dependent/api/v1/return_claims.t b/t/db_dependent/api/v1/return_claims.t index 1664102c6fa..82345530d77 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 => 8; + plan tests => 12; $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( @@ -219,6 +223,19 @@ subtest 'resolve_claim() tests' => sub { is( $claim->resolved_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.20.1