Bug 38248 - Staff interface detail page item table lookup fails when item has lost status but no claims returned
Summary: Staff interface detail page item table lookup fails when item has lost status...
Status: RESOLVED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Staff interface (show other bugs)
Version: Main
Hardware: All All
: P5 - low major
Assignee: David Cook
QA Contact: Katrin Fischer
URL:
Keywords:
Depends on: 27919 33568
Blocks:
  Show dependency treegraph
 
Reported: 2024-10-23 19:55 UTC by David Nind
Modified: 2024-11-20 18:41 UTC (History)
6 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
24.11.00
Circulation function:


Attachments
Bug 38248: Fix condition when item has no return_claims in API response (2.38 KB, patch)
2024-10-23 22:36 UTC, David Cook
Details | Diff | Splinter Review
Bug 38248: Fix condition when item has no return_claims in API response (2.45 KB, patch)
2024-10-24 05:29 UTC, Phil Ringnalda
Details | Diff | Splinter Review
Bug 38248: Do not deal with return claims if pref is not set (2.07 KB, patch)
2024-10-30 08:57 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 38248: Do not deal with return claims if pref is not set (2.15 KB, patch)
2024-10-30 11:09 UTC, Matt Blenkinsop
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description David Nind 2024-10-23 19:55:21 UTC
If I set the lost status for an item to 1 (Lost), then when viewing the record in the staff interface, it sits on "Processing".

To replicate:
1. Find any record in the staff interface with an existing item and add a new item.
2. Note that when you select the "Normal" view, the holdings section lists the existing item and the new one that you created.
3. Edit the item you created and change "1 - Lost status" to "Lost".
4. Select the "Normal" view for the record again and note that a dialog box appears saying "Processing" and the holdings table does not list any items.
Comment 1 David Cook 2024-10-23 22:19:39 UTC
If you set "ClaimReturnedLostValue" to "Lost", you get a different error as well.

I get a JS alert() that says:

400: Bad Request.
Not in enum list: <with a long list that I'm not going to write out>

--

I'm guessing I might just need to rebuild my API files...
Comment 2 David Cook 2024-10-23 22:23:33 UTC
(In reply to David Cook from comment #1)
> If you set "ClaimReturnedLostValue" to "Lost", you get a different error as
> well.
> 
> I get a JS alert() that says:
> 
> 400: Bad Request.
> Not in enum list: <with a long list that I'm not going to write out>
> 
> --
> 
> I'm guessing I might just need to rebuild my API files...

Yep, rebuild the swagger spec and restarted, and now it's fine. This should be an easy fix...
Comment 3 David Cook 2024-10-23 22:36:50 UTC
Created attachment 173241 [details] [review]
Bug 38248: Fix condition when item has no return_claims in API response

This change just fixes a condition to not break when an item has no return_claims
in an API response.

Test plan:
0) Apply the patch and koha-plack --restart kohadev
NOTE: You may need to rebuild your swagger spec since bug 27919 was pushed
redocly bundle --ext json api/v1/swagger/swagger.yaml \
  --output api/v1/swagger/swagger_bundle.json
1) Go to http://localhost:8081/cgi-bin/koha/catalogue/detail.pl?biblionumber=29
2) Create an item with a status of "Lost"
3) Go to http://localhost:8081/cgi-bin/koha/catalogue/detail.pl?biblionumber=29
4) Note that the item table loads without a problem

5) In system preferences, set the ClaimReturnedLostValue syspref to any value
6) Checkout an item to a patron
7) Click "Claim returned" and make the claim
8) Go to http://localhost:8081/cgi-bin/koha/catalogue/detail.pl?biblionumber=29
9) Note that the item table loads without a problem and "(Claimed returned") appears
for the item that was claimed returned
Comment 4 Phil Ringnalda 2024-10-24 05:29:57 UTC
Created attachment 173250 [details] [review]
Bug 38248: Fix condition when item has no return_claims in API response

This change just fixes a condition to not break when an item has no return_claims
in an API response.

Test plan:
0) Apply the patch and koha-plack --restart kohadev
NOTE: You may need to rebuild your swagger spec since bug 27919 was pushed
redocly bundle --ext json api/v1/swagger/swagger.yaml \
  --output api/v1/swagger/swagger_bundle.json
1) Go to http://localhost:8081/cgi-bin/koha/catalogue/detail.pl?biblionumber=29
2) Create an item with a status of "Lost"
3) Go to http://localhost:8081/cgi-bin/koha/catalogue/detail.pl?biblionumber=29
4) Note that the item table loads without a problem

5) In system preferences, set the ClaimReturnedLostValue syspref to any value
6) Checkout an item to a patron
7) Click "Claim returned" and make the claim
8) Go to http://localhost:8081/cgi-bin/koha/catalogue/detail.pl?biblionumber=29
9) Note that the item table loads without a problem and "(Claimed returned") appears
for the item that was claimed returned

Signed-off-by: Phil Ringnalda <phil@chetcolibrary.org>
Comment 5 Katrin Fischer 2024-10-24 09:40:28 UTC
Simple change and tested it. PQA.
Comment 6 Katrin Fischer 2024-10-24 11:39:12 UTC
Pushed for 24.11!

Well done everyone, thank you!
Comment 7 Jonathan Druart 2024-10-28 10:24:49 UTC
I am wondering if the condition is correct. What would make sense IMO is to test for ClaimReturnedLostValue

We should have row.return_claims set if the pref is set

248     [% IF Koha.Preference('ClaimReturnedLostValue') %]
249         embed.push('return_claims');
250     [% END %]
Comment 8 Katrin Fischer 2024-10-28 10:27:58 UTC
(In reply to Jonathan Druart from comment #7)
> I am wondering if the condition is correct. What would make sense IMO is to
> test for ClaimReturnedLostValue
> 
> We should have row.return_claims set if the pref is set
> 
> 248     [% IF Koha.Preference('ClaimReturnedLostValue') %]
> 249         embed.push('return_claims');
> 250     [% END %]

We now have claimed returns items with LOST values other than the ClaimReturendLostValue. (See bug 27919) So this is why this needed to be adjusted.
Comment 9 Jonathan Druart 2024-10-28 10:55:32 UTC
Then remove the embed condition?

rows.return_claims won't be set if the pref is not set.

Should be on bug 27919 maybe.
Comment 10 David Cook 2024-10-29 00:53:33 UTC
(In reply to Jonathan Druart from comment #9)
> rows.return_claims won't be set if the pref is not set.

row.return_claims not being set is the whole problem resolved by this patch
Comment 11 Jonathan Druart 2024-10-29 08:52:20 UTC
(In reply to David Cook from comment #10)
> (In reply to Jonathan Druart from comment #9)
> > rows.return_claims won't be set if the pref is not set.
> 
> row.return_claims not being set is the whole problem resolved by this patch

Look at the code:

248     [% IF Koha.Preference('ClaimReturnedLostValue') %]
249         embed.push('return_claims');
250     [% END %]


497                         const hasReturnClaims = row.return_claims && row.return_claims.filter(rc => !rc.resolution).length > 0 ? true : false

This means that if the pref is not set, row.return_claims won't be set (the key will not exist).
If the pref is set, row.return_claims will be an array (eventually empty).

A correct logic would be surround the 'hasReturnClaims' code with test on ClaimReturnedLostValue.

if ( row.lost_status ) { 
    let lost_lib = av_lost.get(row.lost_status.toString()) || _("Unavailable (lost or missing");
    [% IF Koha.Preference('ClaimReturnedLostValue') %]
        const hasReturnClaims = row.return_claims.filter(rc => !rc.resolution).length > 0 ? true : false
        nodes += '<span class="lost">%s</span>'.format(escape_str(lost_lib));
        if(hasReturnClaims) {
            nodes += '<span class="claimed_returned">' + _("(Claimed returned)") + '</span>';
        }
    [% END %]
}

*BUT*

(In reply to Katrin Fischer from comment #8)
> (In reply to Jonathan Druart from comment #7)
> > I am wondering if the condition is correct. What would make sense IMO is to
> > test for ClaimReturnedLostValue
> > 
> > We should have row.return_claims set if the pref is set
> > 
> > 248     [% IF Koha.Preference('ClaimReturnedLostValue') %]
> > 249         embed.push('return_claims');
> > 250     [% END %]
> 
> We now have claimed returns items with LOST values other than the
> ClaimReturendLostValue. (See bug 27919) So this is why this needed to be
> adjusted.

Then following the above, there is a flaw in the logic.

If this is correct we should always embed return_claims, and remove the IF l.248
Comment 12 David Cook 2024-10-29 22:30:56 UTC
If you have the time to deal with it, I'd say go for it. Personally, I have bigger fish to fry...
Comment 13 Jonathan Druart 2024-10-30 08:52:23 UTC Comment hidden (obsolete)
Comment 14 Jonathan Druart 2024-10-30 08:57:12 UTC
Created attachment 173704 [details] [review]
Bug 38248: Do not deal with return claims if pref is not set

If the pref is not set we don't embed return_claims and so
row.return_claims will never be set.
When the pref is on, row.return_claims should always be an array.

Test plan:
Same as previous patch
Comment 15 Jonathan Druart 2024-10-30 08:57:52 UTC
(In reply to Jonathan Druart from comment #14)
> Created attachment 173704 [details] [review] [review]
> Bug 38248: Do not deal with return claims if pref is not set
> 
> If the pref is not set we don't embed return_claims and so
> row.return_claims will never be set.
> When the pref is on, row.return_claims should always be an array.
> 
> Test plan:
> Same as previous patch

Requesting Matt's signoff, please.
Comment 16 Matt Blenkinsop 2024-10-30 11:09:31 UTC
Created attachment 173708 [details] [review]
Bug 38248: Do not deal with return claims if pref is not set

If the pref is not set we don't embed return_claims and so
row.return_claims will never be set.
When the pref is on, row.return_claims should always be an array.

Test plan:
Same as previous patch

Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Comment 17 Matt Blenkinsop 2024-10-30 11:09:57 UTC
Good catch, patch works as advertised and the logic makes sense
Comment 18 Katrin Fischer 2024-10-30 13:03:05 UTC
Follow-up  Bug 38248: Do not deal with return claims if pref is not set grabbed for push to main.
Comment 19 Lucas Gass (lukeg) 2024-11-20 18:41:12 UTC
Missing 24.05.x dependencies, no backport.