Bug 38254 - Patron auto-complete search explodes when dateexpiry is NULL
Summary: Patron auto-complete search explodes when dateexpiry is NULL
Status: RESOLVED DUPLICATE of bug 36454
Alias: None
Product: Koha
Classification: Unclassified
Component: Patrons (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal
Assignee: Lucas Gass (lukeg)
QA Contact: Aleisha Amohia
URL:
Keywords:
Depends on: 36454
Blocks:
  Show dependency treegraph
 
Reported: 2024-10-24 09:13 UTC by Katrin Fischer
Modified: 2025-01-06 10:34 UTC (History)
7 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Trivial patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
This fixes patron autocomplete searching so that it continues to work if there are patron accounts without an account expiry date, instead of failing. This could happen because of incorrect data, including from migration or previous upgrades - Koha now expects a date, where it may not have in the past.
Version(s) released in:
Circulation function:


Attachments
Bug 38254: Treat NULL dateexpity as not expired in patron autocomplete (1.86 KB, patch)
2024-11-15 17:32 UTC, Lucas Gass (lukeg)
Details | Diff | Splinter Review
Bug 38254: Treat NULL dateexpity as not expired in patron autocomplete (1.91 KB, patch)
2024-11-15 19:48 UTC, David Nind
Details | Diff | Splinter Review
Bug 38254: Treat NULL dateexpiry as not expired in patron autocomplete (1.97 KB, patch)
2024-11-18 00:38 UTC, Aleisha Amohia
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Katrin Fischer 2024-10-24 09:13:52 UTC
This was moved from bug 31143:

> We either need to fix the auto-complete patron search or have the 
> script re-calculate the dateexpiry from the patron category. I am 
> leaning towards making the patron search deal with NULL.

borrowers.dateexpiry can be NULL so the code needs to be fixed.

I have not tried it but this would be the idea:

iff --git a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js
b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js
index 73a4a0251e1..28060fb35da 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js
+++ b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js
@@ -694,10 +694,13 @@ function patron_autocomplete(node, options) {
         }
         let new_date = new Date();
         let today = Date.parse($date_to_rfc3339($date(new_date.toString())));
-        let expiration = Date.parse(
-            $date_to_rfc3339($date(item.expiry_date.toString()))
-        );
-        let expired = today > expiration;
+        let expired = false;
+        if (item.expiry_date){
+            let expiration = Date.parse(
+                $date_to_rfc3339($date(item.expiry_date.toString()))
+            );
+            expired = today > expiration;
+        }
         return $("<li></li>")
             .addClass(loggedInClass)
             .data("ui-autocomplete-item", item)
Comment 1 Lucas Gass (lukeg) 2024-11-15 17:32:31 UTC
Created attachment 174632 [details] [review]
Bug 38254: Treat NULL dateexpity as not expired in patron autocomplete

To test:
1. Add some NULL patron dateexpiry dates.
2. Make sure PatronAutoComplete is on.
3. Try searching for some patrons with NULL patron dateexpiry dates.
4. Search doesn't complete, see JS error in console.
5. APPLY PATCH and try again
6. Now NULL dateexpiry patrons should be returned in the autocomplete.
7. Make sure patrons with dateexpiry in past still show the 'Expired' badge.
8. Patrons with a dateexpiry in the future or a NULL dateexpiry should not shhow the 'Expired' badge.
Comment 2 David Nind 2024-11-15 19:48:43 UTC
Created attachment 174633 [details] [review]
Bug 38254: Treat NULL dateexpity as not expired in patron autocomplete

To test:
1. Add some NULL patron dateexpiry dates.
2. Make sure PatronAutoComplete is on.
3. Try searching for some patrons with NULL patron dateexpiry dates.
4. Search doesn't complete, see JS error in console.
5. APPLY PATCH and try again
6. Now NULL dateexpiry patrons should be returned in the autocomplete.
7. Make sure patrons with dateexpiry in past still show the 'Expired' badge.
8. Patrons with a dateexpiry in the future or a NULL dateexpiry should not shhow the 'Expired' badge.

Signed-off-by: David Nind <david@davidnind.com>
Comment 3 David Nind 2024-11-15 19:57:56 UTC
Testing notes (using KTD):
1. For step 1, I used this SQL query to update the expiry date for Mary to NULL:
   update borrowers set dateexpiry=NULL where borrowernumber=49;
2. PatronAutoComplete is already set to "Try" in KTD.
3. To see the 'Expired' badge, edit Mary's acccount so that 'Expiry date' is blank, then do a search in the search bar at the top.
Comment 4 Aleisha Amohia 2024-11-18 00:38:15 UTC
Created attachment 174653 [details] [review]
Bug 38254: Treat NULL dateexpiry as not expired in patron autocomplete

To test:
1. Add some NULL patron dateexpiry dates.
2. Make sure PatronAutoComplete is on.
3. Try searching for some patrons with NULL patron dateexpiry dates.
4. Search doesn't complete, see JS error in console.
5. APPLY PATCH and try again
6. Now NULL dateexpiry patrons should be returned in the autocomplete.
7. Make sure patrons with dateexpiry in past still show the 'Expired' badge.
8. Patrons with a dateexpiry in the future or a NULL dateexpiry should not shhow the 'Expired' badge.

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Aleisha Amohia <aleishaamohia@hotmail.com>
Comment 5 Jonathan Druart 2024-11-18 09:44:33 UTC
Don't push, wait a bit.
Comment 6 Jonathan Druart 2024-11-18 09:45:20 UTC
I don't understand why you would need this in 24.05, it's caused by bug 36454 
only in main.
Comment 7 Katrin Fischer 2024-11-18 09:45:33 UTC
Waiting to push this as we have some ongoing work on the same code on bug 36454.
Comment 8 Pedro Amorim 2024-11-18 12:47:24 UTC
(In reply to Katrin Fischer from comment #7)
> Waiting to push this as we have some ongoing work on the same code on bug
> 36454.

The follow-up from bug 36454:
https://bugs.koha-community.org/bugzilla3/page.cgi?id=splinter.html&bug=36454&attachment=174671

Fixes/prevents the issue described here.
Comment 9 Katrin Fischer 2024-11-18 15:03:21 UTC
(In reply to Pedro Amorim from comment #8)
> (In reply to Katrin Fischer from comment #7)
> > Waiting to push this as we have some ongoing work on the same code on bug
> > 36454.
> 
> The follow-up from bug 36454:
> https://bugs.koha-community.org/bugzilla3/page.cgi?id=splinter.
> html&bug=36454&attachment=174671
> 
> Fixes/prevents the issue described here.

Thanks Pedro!
Comment 10 Jonathan Druart 2025-01-06 10:34:29 UTC
Changing status as it's not pushed.

*** This bug has been marked as a duplicate of bug 36454 ***