Bug 39233 - Non-patron guarantor info not dropped when patron category is updated
Summary: Non-patron guarantor info not dropped when patron category is updated
Status: In Discussion
Alias: None
Product: Koha
Classification: Unclassified
Component: Patrons (show other bugs)
Version: Main
Hardware: All All
: P5 - low minor
Assignee: Emmi Takkinen
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-03-04 10:47 UTC by Emmi Takkinen
Modified: 2025-05-20 11:46 UTC (History)
5 users (show)

See Also:
GIT URL:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
This fixes the misc/cronjobs/update_patrons_category.pl script so that non-patron guarantor information is removed when the patron category is changed (for example, from a child to an adult patron). This now matches what happens when changing the patron category when a patron has patron guarantors (that is, the guarantor information is removed).
Version(s) released in:
Circulation function:


Attachments
Bug 39233: Drop non-patron guarantor info when guarantee is updated as an adult via update_patrons_category.pl (3.18 KB, patch)
2025-04-23 10:27 UTC, Emmi Takkinen
Details | Diff | Splinter Review
Bug 39233: Drop non-patron guarantor info when guarantee is updated as an adult via update_patrons_category.pl (3.22 KB, patch)
2025-05-01 13:09 UTC, David Nind
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Emmi Takkinen 2025-03-04 10:47:31 UTC
When child patrons category is updated via update_patrons_category.pl patrons relationship with their guarantor is dropped from borrower_relationships table. But non-patron guarantees info is still kept in borrowers table.

To reproduce:
1. Find child patron with non-patron guarantor or create one.
2. Update patrons age so that their category is updated when you run following:
perl misc/cronjobs/update_patrons_category.pl --confirm --too_old --from K --to PT
3. Check patrons info from borrowers table.
=> Note that values in contactname, contactfirstname and relationship columns were not dropped.
Comment 1 Emmi Takkinen 2025-04-23 10:27:39 UTC
Created attachment 181364 [details] [review]
Bug 39233: Drop non-patron guarantor info when guarantee is updated as an adult via update_patrons_category.pl

When child patrons category is updated via update_patrons_category.pl
patrons relationship with their guarantor is dropped from
borrower_relationships table. But non-patron guarantees info
is still  kept in borrowers table. This patch fixes this by
setting non-patron guarantor columns in borrower table as
undefined when patron is stored.

To test:
1. Find child patron with non-patron guarantor or create one.
2. Update patrons age so that their category is updated when you run following:
perl misc/cronjobs/update_patrons_category.pl --confirm --too_old --from K --to PT
3. Check patrons info from patrons detail page.
=> Note that non-patron guarantors info was not dropped.
4. Apply this patch.
5. Run cronjob again.
=> Non-patron guarantors info should have now dropped.

Alsp prove t/db_dependent/Patrons.t.

Sponsored-by: Koha-Suomi Oy
Comment 2 David Nind 2025-05-01 13:09:01 UTC
Created attachment 181827 [details] [review]
Bug 39233: Drop non-patron guarantor info when guarantee is updated as an adult via update_patrons_category.pl

When child patrons category is updated via update_patrons_category.pl
patrons relationship with their guarantor is dropped from
borrower_relationships table. But non-patron guarantees info
is still  kept in borrowers table. This patch fixes this by
setting non-patron guarantor columns in borrower table as
undefined when patron is stored.

To test:
1. Find child patron with non-patron guarantor or create one.
2. Update patrons age so that their category is updated when you run following:
perl misc/cronjobs/update_patrons_category.pl --confirm --too_old --from K --to PT
3. Check patrons info from patrons detail page.
=> Note that non-patron guarantors info was not dropped.
4. Apply this patch.
5. Run cronjob again.
=> Non-patron guarantors info should have now dropped.

Alsp prove t/db_dependent/Patrons.t.

Sponsored-by: Koha-Suomi Oy
Signed-off-by: David Nind <david@davidnind.com>
Comment 3 David Nind 2025-05-01 13:18:00 UTC
Testing notes (using KTD):
1. If I try to update the patron's age in the staff interface, I get this message:
      The following fields are wrong. Please fix them.
      - Patron's age is incorrect for their category. Ages allowed are 5-17.
2. You can't save the patron until you fix the category.
3. Instead, I updated in the database: 
   update borrowers set dateofbirth="2000-05-01" where borrowernumber="37";
4. After the patch is applied, update the patron again using the database to set the patron category back to "K":
   update borrowers set categorycode="K" where borrowernumber="37";
Comment 4 Martin Renvoize (ashimema) 2025-05-02 10:41:33 UTC
I'm considering asking for a switch for this.. I could see cases where this cleanup being automated may not be wanted.
Comment 5 David Nind 2025-05-02 11:16:47 UTC
Is bug 32915 a duplicate?
Comment 6 Marcel de Rooy 2025-05-19 07:43:10 UTC
In view of comment4 and comment5 moving to In Discussion.

Please provide clarity.
Comment 7 Emmi Takkinen 2025-05-19 11:18:49 UTC
(In reply to David Nind from comment #5)
> Is bug 32915 a duplicate?

Did you mean to comment this on different bug maybe? This bug is about patron info and that bug about framework defaults.
Comment 8 Emmi Takkinen 2025-05-19 11:26:04 UTC
(In reply to Martin Renvoize (ashimema) from comment #4)
> I'm considering asking for a switch for this.. I could see cases where this
> cleanup being automated may not be wanted.

Can you provide an example when this info is still needed after guarantee is updated? I don't really see why we should keep this info around if we already drop it from patron guarantees. Is contact info used in some other situations apart from guarantee-guarantor cases?
Comment 9 David Nind 2025-05-19 13:56:31 UTC
(In reply to Emmi Takkinen from comment #7)
> (In reply to David Nind from comment #5)
> > Is bug 32915 a duplicate?
> 
> Did you mean to comment this on different bug maybe? This bug is about
> patron info and that bug about framework defaults.

Apologies, that was the wrong bug number - should have been bug 32195
Comment 10 Emmi Takkinen 2025-05-20 11:46:51 UTC
(In reply to David Nind from comment #9)
> (In reply to Emmi Takkinen from comment #7)
> > (In reply to David Nind from comment #5)
> > > Is bug 32915 a duplicate?
> > 
> > Did you mean to comment this on different bug maybe? This bug is about
> > patron info and that bug about framework defaults.
> 
> Apologies, that was the wrong bug number - should have been bug 32195

Hmm, I'm not sure if they are same or not. The way I read it in bug 32195 if you  have patron category A where "CanBeGuarantee" option is first set as Yes and then change that option as "No", the guarantor info is not dropped and it cannot be moved at all. Although... Recent change to the bugs title and Andrews comment suggest that it indeed is now a duplicate.