Bug 32604 - Patron categories upper age limit not respected when creating a patron
Summary: Patron categories upper age limit not respected when creating a patron
Status: Pushed to main
Alias: None
Product: Koha
Classification: Unclassified
Component: Patrons (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal
Assignee: Bernard
QA Contact: Emmi Takkinen
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-01-10 12:36 UTC by Emmi Takkinen
Modified: 2025-03-20 08:04 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:
25.05.00
Circulation function:


Attachments
Bug 32604: Correct boundary calculation for birthdate (1.65 KB, patch)
2025-03-17 18:10 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 32604: Correct boundary calculation for birthdate (1.65 KB, patch)
2025-03-18 09:22 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 32604: Unit tests (13.43 KB, patch)
2025-03-18 09:22 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 32604: Correct boundary calculation for birthdate (1.71 KB, patch)
2025-03-18 10:39 UTC, Emmi Takkinen
Details | Diff | Splinter Review
Bug 32604: Unit tests (13.49 KB, patch)
2025-03-18 10:39 UTC, Emmi Takkinen
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Emmi Takkinen 2023-01-10 12:36:18 UTC
Koha treats patron categories upper age limit inconsistently. E.g. if child patron category's upper age limit is 18, one is still able to add child patron who is 18 years old. However, when cronjob update_patrons_category.pl is run, patrons over and exactly aged 18 are considered overaged and their categorycode is updated. We should either fix patron creation or cronjob to avoid confusion.

To test:
1. Add upper age limit as 18 for child patron category. 
2. Create a child patron whose age is 18.
3. Save.
=> Patron is saved successfully.
4. Run cronjob update_patrons_category.pl with verbose option.
perl update_patrons_category.pl --too_old --from CHILD --to ADULT -v
=> Note that patron is reported as updated (or would have updated) as an adult patron.
Comment 1 Hannah Dunne-Howrie 2025-02-07 12:33:16 UTC
We need this functionality. We had this in our previous library system so moving to Koha and this not working correctly is a problem for us as it has created a manual task for system admins.
Comment 2 Bernard 2025-02-10 14:19:58 UTC
This is because the calculation of whether a user is over the upperagelimit or not in Patrons.pm is incorrect. For example, a user is not over the age of 11 until their 12th birthday. See this url for a patch that I think would resolve this which I've tested on 24.11:

https://github.com/kbwhizz/kohafixes/commit/087ca86dc12d6d42242732dce86bd6a34d685a07
Comment 3 Martin Renvoize (ashimema) 2025-03-17 18:10:06 UTC
Created attachment 179417 [details] [review]
Bug 32604: Correct boundary calculation for birthdate

Add 1 to upperagelimit to make it calculate birthday boundaries correctly
for patrons_to_update_category search

To test:
1. Add upper age limit as 18 for child patron category.
2. Create a child patron whose age is 18.
3. Save.
=> Patron is saved successfully.
4. Run cronjob update_patrons_category.pl with verbose option.
   perl update_patrons_category.pl --too_old --from CHILD --to ADULT -v
=> Note that patron is reported as updated (or would have updated)
   as an adult patron.
5. Apply patch
6. Re-run steps 1 to 5 and note we no long update the 18 year olds.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 4 Martin Renvoize (ashimema) 2025-03-18 09:22:46 UTC
Created attachment 179422 [details] [review]
Bug 32604: Correct boundary calculation for birthdate

Add 1 to upperagelimit to make it calculate birthday boundaries correctly
for patrons_to_update_category search

To test:
1. Add upper age limit as 18 for child patron category.
2. Create a child patron whose age is 18.
3. Save.
=> Patron is saved successfully.
4. Run cronjob update_patrons_category.pl with verbose option.
   perl update_patrons_category.pl --too_old --from CHILD --to ADULT -v
=> Note that patron is reported as updated (or would have updated)
   as an adult patron.
5. Apply patch
6. Re-run steps 1 to 5 and note we no long update the 18 year olds.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 5 Martin Renvoize (ashimema) 2025-03-18 09:22:49 UTC
Created attachment 179423 [details] [review]
Bug 32604: Unit tests

Add unit tests to more thoroughly and specifically cover the
search_patrons_to_update_category method including specific date
handling tests.

We also add some notes to the POD that were highlighted by writing
comprehensive tests.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 6 Martin Renvoize (ashimema) 2025-03-18 09:24:16 UTC
Bernard wrote the original work here, I just tidied it up for submission and then added unit tests.

Leaving it as assigned (and committed) by him so he gets the recognition and adding my own signoff as I've thoroughly tested it.
Comment 7 Emmi Takkinen 2025-03-18 10:39:31 UTC
Created attachment 179434 [details] [review]
Bug 32604: Correct boundary calculation for birthdate

Add 1 to upperagelimit to make it calculate birthday boundaries correctly
for patrons_to_update_category search

To test:
1. Add upper age limit as 18 for child patron category.
2. Create a child patron whose age is 18.
3. Save.
=> Patron is saved successfully.
4. Run cronjob update_patrons_category.pl with verbose option.
   perl update_patrons_category.pl --too_old --from CHILD --to ADULT -v
=> Note that patron is reported as updated (or would have updated)
   as an adult patron.
5. Apply patch
6. Re-run steps 1 to 5 and note we no long update the 18 year olds.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Emmi Takkinen <emmi.takkinen@koha-suomi.fi>
Comment 8 Emmi Takkinen 2025-03-18 10:39:56 UTC
Created attachment 179435 [details] [review]
Bug 32604: Unit tests

Add unit tests to more thoroughly and specifically cover the
search_patrons_to_update_category method including specific date
handling tests.

We also add some notes to the POD that were highlighted by writing
comprehensive tests.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Emmi Takkinen <emmi.takkinen@koha-suomi.fi>
Comment 9 Emmi Takkinen 2025-03-18 10:40:12 UTC
Tested and everything works as expected.
Comment 10 Martin Renvoize (ashimema) 2025-03-20 07:22:18 UTC
Promoting Emmi's Signoff to a PQA.. two solid sets of eyes on this :)
Comment 11 Katrin Fischer 2025-03-20 07:49:27 UTC
 FAIL	Koha/Patrons.pm
   FAIL	  spelling
		 precidence ==> precedence

Fixed inline.
Comment 12 Katrin Fischer 2025-03-20 08:04:23 UTC
Pushed for 25.05!

Well done everyone, thank you!