From be2bffe512cc68cedc6c9560e376449c77366988 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 | 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 6ef16c71f8..3c3da8ceef 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js +++ b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js @@ -1142,14 +1142,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.32.0