Bug 14250 - Don't allow to generate discharges for patrons with fines
Summary: Don't allow to generate discharges for patrons with fines
Status: Signed Off
Alias: None
Product: Koha
Classification: Unclassified
Component: Patrons (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal
Assignee: Baptiste Wojtkowski (bwoj)
QA Contact: Kyle M Hall
URL:
Keywords: additional_work_needed
: 25986 (view as bug list)
Depends on: 8007
Blocks:
  Show dependency treegraph
 
Reported: 2015-05-21 16:47 UTC by Nicole C. Engard
Modified: 2024-09-10 16:50 UTC (History)
14 users (show)

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


Attachments
Bug 14250: Patron with fines cannot be discharged anymore (9.41 KB, patch)
2024-08-07 13:57 UTC, Baptiste Wojtkowski (bwoj)
Details | Diff | Splinter Review
Bug 14250: Patron with fines cannot be discharged anymore (9.93 KB, patch)
2024-08-12 10:06 UTC, Baptiste Wojtkowski (bwoj)
Details | Diff | Splinter Review
Bug 14250: Patron with fines cannot be discharged anymore (9.94 KB, patch)
2024-08-22 08:06 UTC, Baptiste Wojtkowski (bwoj)
Details | Diff | Splinter Review
Bug 14250: Patron with fines cannot be discharged anymore (10.02 KB, patch)
2024-08-22 12:48 UTC, Roman Dolny
Details | Diff | Splinter Review
Bug 14250: Patron with fines cannot be discharged anymore (10.10 KB, patch)
2024-08-23 18:12 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 14250: (QA follow-up) Deduplicate checks (12.16 KB, patch)
2024-08-23 18:12 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 14250: (QA follow-up) Tidy code (17.94 KB, patch)
2024-08-23 18:12 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 14250: Patron with fines cannot be discharged anymore (10.10 KB, patch)
2024-08-26 11:04 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 14250: (QA follow-up) Deduplicate checks (12.18 KB, patch)
2024-08-26 11:04 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 14250: (QA follow-up) Tidy code (17.68 KB, patch)
2024-08-26 11:04 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 14250: (follow-up) Update messages (5.44 KB, patch)
2024-08-26 11:20 UTC, David Nind
Details | Diff | Splinter Review
Bug 14250: (follow-up) Refacto the algorithm for discharge messages (4.59 KB, patch)
2024-09-04 13:09 UTC, Baptiste Wojtkowski (bwoj)
Details | Diff | Splinter Review
Bug 14250: (follow-up) Refacto discharge messages display (2.84 KB, patch)
2024-09-04 13:09 UTC, Baptiste Wojtkowski (bwoj)
Details | Diff | Splinter Review
Bug 14250: Patron with fines cannot be discharged anymore (10.14 KB, patch)
2024-09-10 16:49 UTC, Sukhmandeep
Details | Diff | Splinter Review
Bug 14250: (QA follow-up) Deduplicate checks (12.22 KB, patch)
2024-09-10 16:50 UTC, Sukhmandeep
Details | Diff | Splinter Review
Bug 14250: (QA follow-up) Tidy code (17.73 KB, patch)
2024-09-10 16:50 UTC, Sukhmandeep
Details | Diff | Splinter Review
Bug 14250: (follow-up) Update messages (5.51 KB, patch)
2024-09-10 16:50 UTC, Sukhmandeep
Details | Diff | Splinter Review
Bug 14250: (follow-up) Refacto the algorithm for discharge messages (4.67 KB, patch)
2024-09-10 16:50 UTC, Sukhmandeep
Details | Diff | Splinter Review
Bug 14250: (follow-up) Refacto discharge messages display (2.92 KB, patch)
2024-09-10 16:50 UTC, Sukhmandeep
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Nicole C. Engard 2015-05-21 16:47:46 UTC
I can generate a discharge for a patron with fines - shouldn't the patron have no checkouts and no fines?
Comment 1 Jamsheer N P 2017-12-08 05:24:47 UTC
Generating discharge to a patron having unpaid fine is a serious problem.
Comment 2 Jamsheer N P 2017-12-08 05:25:28 UTC
Generating discharge to a patron having unpaid fine is a serious problem.
Comment 3 Katrin Fischer 2020-07-15 05:25:23 UTC
*** Bug 25986 has been marked as a duplicate of this bug. ***
Comment 4 Jonathan Druart 2022-04-08 08:56:14 UTC
I have not tested but this fix should be as simple as:

diff --git a/Koha/Patron/Discharge.pm b/Koha/Patron/Discharge.pm
index 76e04e8533a..b9ebc7653af 100644
--- a/Koha/Patron/Discharge.pm
+++ b/Koha/Patron/Discharge.pm
@@ -39,7 +39,12 @@ sub can_be_discharged {
     return unless $patron;
 
     my $has_pending_checkouts = $patron->checkouts->count;
-    return $has_pending_checkouts ? 0 : 1;
+    return 0 if $has_pending_checkouts;
+
+    my $has_debt = $patron->account->outstanding_debits->total_outstanding
+    return 0 if $has_debt;
+
+    return 1;
 }
 
 sub is_discharged {
Comment 5 Caroline Cyr La Rose 2023-05-24 14:34:00 UTC
Still valid in master (22.12.00.048)
Comment 6 Theodoros Theodoropoulos 2024-07-23 11:41:40 UTC
Please take some time to consider Jonathan's solution and rebase/fix this (serious) issue!

It seems that original implementers of this feature believed that having a fine is not a blocking reason for issuing a discharge, but this concept should be reconsidered!

Also, at the same time, additional lines will be required in discharge.tt to handle inability to issue a discharge because of pending fines.
Comment 7 Fridolin Somers 2024-07-23 14:40:56 UTC
Maybe this can use :
  $patron->account_balance > 0
?
Comment 8 Baptiste Wojtkowski (bwoj) 2024-08-06 15:20:17 UTC
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14250#c4 -> this is part of the solution but I need to check further what code calls can_be_discharged.

For example, in discharge.tt: 
54 [% UNLESS can_be_discharged %]
55     <p>Cannot edit discharge: the patron has checked out items.</p>
Comment 9 Baptiste Wojtkowski (bwoj) 2024-08-07 13:57:05 UTC
Created attachment 170136 [details] [review]
Bug 14250: Patron with fines cannot be discharged anymore

TEST PLAN:
1 - In the intranet add fines to a client and ensure they have no checkout
2 - Set syspref useDischarge to 'Allow'
3 - On client profile click on "Discharge", see it is possible
4 - On the opac, go to the tab "Ask for discharge", see it is possible
5 - Apply patch
6 - Click on the button "Ask for discharge" -> it will not be possible
  and you will be propperly messaged
7 - Return to the tab "Ask for a discharge", there will be no button
  anymore
8 - On the intranet page, there will be no button anymore
9 - Check out a book
10 - Repeat 7 and 8 and see the message include issue with checkout
11 - Remove fine and repeat 7 & 8
Comment 10 Roman Dolny 2024-08-09 21:19:11 UTC
It seems to work as expected (without the ability to generate discharge), but the reason messages are not complete: when there are checkouts and fines in borrowers account only one reason is listed (variously: checkouts in STAFF, fines in OPAC).

QA script:
WARN   Koha/Patron/Discharge.pm
  WARN   tidiness
  The file is less tidy than before (bad/messy lines before: 47, now: 48)

WARN   members/discharge.pl
  WARN   tidiness
  The file is less tidy than before (bad/messy lines before: 30, now: 32)

 WARN   opac/opac-discharge.pl
  WARN   tidiness
  The file is less tidy than before (bad/messy lines before: 30, now: 35)

WARN   t/db_dependent/Patron/Borrower_Discharge.t
  WARN   tidiness
  The file is less tidy than before (bad/messy lines before: 59, now: 63)
Comment 11 Baptiste Wojtkowski (bwoj) 2024-08-12 10:06:42 UTC
Created attachment 170228 [details] [review]
Bug 14250: Patron with fines cannot be discharged anymore

TEST PLAN:
1 - In the intranet add fines to a client and ensure they have no checkout
2 - Set syspref useDischarge to 'Allow'
3 - On client profile click on "Discharge", see it is possible
4 - On the opac, go to the tab "Ask for discharge", see it is possible
5 - Apply patch
6 - Click on the button "Ask for discharge" -> it will not be possible
  and you will be propperly messaged
7 - Return to the tab "Ask for a discharge", there will be no button
  anymore
8 - On the intranet page, there will be no button anymore
9 - Check out a book
10 - Repeat 7 and 8 and see the message include issue with checkout
11 - Remove fine and repeat 7 & 8
Comment 12 Roman Dolny 2024-08-21 19:38:27 UTC
Thanks for update. It's almost done -- one more thing: when patron has no checkout but has fine (p. 8) there are two messages visible in STAFF: "They have unpaid fines" and "Patron cannot be discharged for an unknown reason, please contact a librarian for more information". But should be only first one.
In OPAC it is OK.

Is it because of 
 [% IF patron.checkouts.count == 0 and 
 (patron.account.outstanding_debits.total_outstanding > 0) %]
in koha-tmpl/intranet-tmpl/prog/en/modules/members/discharge.tt?
Comment 13 Baptiste Wojtkowski (bwoj) 2024-08-22 08:06:40 UTC
Created attachment 170581 [details] [review]
Bug 14250: Patron with fines cannot be discharged anymore

TEST PLAN:
1 - In the intranet add fines to a client and ensure they have no checkout
2 - Set syspref useDischarge to 'Allow'
3 - On client profile click on "Discharge", see it is possible
4 - On the opac, go to the tab "Ask for discharge", see it is possible
5 - Apply patch
6 - Click on the button "Ask for discharge" -> it will not be possible
  and you will be propperly messaged
7 - Return to the tab "Ask for a discharge", there will be no button
  anymore
8 - On the intranet page, there will be no button anymore
9 - Check out a book
10 - Repeat 7 and 8 and see the message include issue with checkout
11 - Remove fine and repeat 7 & 8
Comment 14 Roman Dolny 2024-08-22 12:48:44 UTC
Created attachment 170607 [details] [review]
Bug 14250: Patron with fines cannot be discharged anymore

TEST PLAN:
1 - In the intranet add fines to a client and ensure they have no checkout
2 - Set syspref useDischarge to 'Allow'
3 - On client profile click on "Discharge", see it is possible
4 - On the opac, go to the tab "Ask for discharge", see it is possible
5 - Apply patch
6 - Click on the button "Ask for discharge" -> it will not be possible
  and you will be propperly messaged
7 - Return to the tab "Ask for a discharge", there will be no button
  anymore
8 - On the intranet page, there will be no button anymore
9 - Check out a book
10 - Repeat 7 and 8 and see the message include issue with checkout
11 - Remove fine and repeat 7 & 8

Signed-off-by: Roman Dolny <roman.dolny@jezuici.pl>
Comment 15 Kyle M Hall 2024-08-23 18:12:45 UTC
Created attachment 170662 [details] [review]
Bug 14250: Patron with fines cannot be discharged anymore

TEST PLAN:
1 - In the intranet add fines to a client and ensure they have no checkout
2 - Set syspref useDischarge to 'Allow'
3 - On client profile click on "Discharge", see it is possible
4 - On the opac, go to the tab "Ask for discharge", see it is possible
5 - Apply patch
6 - Click on the button "Ask for discharge" -> it will not be possible
  and you will be propperly messaged
7 - Return to the tab "Ask for a discharge", there will be no button
  anymore
8 - On the intranet page, there will be no button anymore
9 - Check out a book
10 - Repeat 7 and 8 and see the message include issue with checkout
11 - Remove fine and repeat 7 & 8

Signed-off-by: Roman Dolny <roman.dolny@jezuici.pl>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 16 Kyle M Hall 2024-08-23 18:12:56 UTC
Created attachment 170663 [details] [review]
Bug 14250: (QA follow-up) Deduplicate checks

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 17 Kyle M Hall 2024-08-23 18:12:59 UTC
Created attachment 170664 [details] [review]
Bug 14250: (QA follow-up) Tidy code
Comment 18 Katrin Fischer 2024-08-26 08:30:31 UTC
Please rebase:

Apply? [(y)es, (n)o, (i)nteractive] y
Applying: Bug 14250: Patron with fines cannot be discharged anymore
Using index info to reconstruct a base tree...
M	koha-tmpl/intranet-tmpl/prog/en/modules/members/discharge.tt
M	koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-discharge.tt
M	t/db_dependent/Patron/Borrower_Discharge.t
Falling back to patching base and 3-way merge...
Auto-merging t/db_dependent/Patron/Borrower_Discharge.t
Auto-merging koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-discharge.tt
Auto-merging koha-tmpl/intranet-tmpl/prog/en/modules/members/discharge.tt
Applying: Bug 14250: (QA follow-up) Deduplicate checks
Applying: Bug 14250: (QA follow-up) Tidy code
error: sha1 information is lacking or useless (t/db_dependent/Patron/Borrower_Discharge.t).
error: could not build fake ancestor
Comment 19 David Nind 2024-08-26 09:48:58 UTC
I was just been about to say the same (that the patch no longer applies). 8-)

I was testing last week, and hadn't finished before it was signed off.

I had some suggested text changes - I am happy to add a follow-up once the patches apply again. This is so that it makes more sense if there are multiple reasons for not discharging.

Suggested text changes for the OPAC
===================================

You cannot be discharged because:
. You have unpaid charges of X. Please pay your charges before reapplying.
. You have X item(s) checked out. Please return your checked out items before reapplying.
. You cannot be discharged for an unknown reason. Please contact library staff for more information.

Suggested text changes for the staff interface
==============================================

A discharge cannot be generated for this patron because:
. The patron has unpaid charges of X.
. The patron has X item(s) checked out.
. The patron cannot be discharged for an unknown reason. Please review the patron's account to determine why. (Not sure about this one.)

The patron has holds. These will be cancelled if the discharge is generated.

Testing notes
=============

1. In the staff interface, set up these scenarios for some patrons:
   - Patron A: check out an item and add a manual fee (I used Henry Acevedo)
   - Patron B: add a manual fee (I used Mary Burton)
   - Patron C: check out an item (I used Lisa Charles)
   - Patron D: add a manual fee (I used Bobbie Middleton)
2. Edit the patrons so that they have a password and that you can log in to their accounts in the OPAC.
3. Set the useDischarge system preference to 'Allow'.
4. Attempt to request a discharge for the patrons (OPAC > You account > Ask for a discharge):
   - Patron A (Manual fee and a checked out item) (Henry): Message is "You cannot be discharged, you have checked out items. Please return items before asking for a discharge."
   - Patron B (Manual fee) (Mary): "Ask for a discharge" button is available and a discharge can be requested. Message "Your discharge request has been sent. Your discharge will be available on this page within a few days."
   - Patron C (A checked out item (Lisa)): Message is "You cannot be discharged, you have checked out items. Please return items before asking for a discharge."
5. Apply the patches and restart everything (restart_all).
6. Attempt to request a discharge for the patrons from their OPAC accounts (OPAC > You account > Ask for a discharge):

   - Patron A (Manual fee and a checked out item)(Henry): Message is now
        You cannot be discharged for following reasons:
        . You have 1 item(s) checked out. Please return them before reapplying. 
        . They have unpaid fines totaling 5.00. Please pay your fines before reapplying. 

   - Patron C (A checked out item) (Lisa):  Message is now
        You cannot be discharged for following reasons:
        . You have 1 item(s) checked out. Please return them before reapplying. 
        
   - Patron D (A manual fee)(Bobbie): 
        You cannot be discharged for following reasons:
        . They have unpaid fines totaling 5.00. Please pay your fines before reapplying. 

7. Attempt to discharge the patrons from the staff interface, from their patron account:

   - Patron A (Manual fee and a checked out item)(Henry): Message is now
        Cannot edit discharge for following reasons:
        . They have 1 item(s) checked out
        . They have unpaid fines totaling 5.00

   - Patron C (A checked out item) (Lisa):  Message is now
        Cannot edit discharge for following reasons:
        . They have 1 item(s) checked out

   - Patron D (A manual fee)(Bobbie): 
        Cannot edit discharge for following reasons:
        . They have unpaid fines totaling 5.00

OPAC discharge text
===================

I've created bug 37729 for the discharge text on the OPAC "Ask for a discharge" page, suggesting that this is changed to an HTML customization - so that the text can be customised and translated.

Current hard coded text
-----------------------

Discharge

What is a discharge?

This document certifies that you have returned all borrowed items. It is sometimes asked during a file transfer from a school to another. The discharge is sent by us to your school. You will also find it available on your reader account.
  
Warning: This request is only valid if you are in good standing with the library. Once the application is made, you can not borrow library materials.
Comment 20 Kyle M Hall 2024-08-26 11:04:05 UTC
Created attachment 170705 [details] [review]
Bug 14250: Patron with fines cannot be discharged anymore

TEST PLAN:
1 - In the intranet add fines to a client and ensure they have no checkout
2 - Set syspref useDischarge to 'Allow'
3 - On client profile click on "Discharge", see it is possible
4 - On the opac, go to the tab "Ask for discharge", see it is possible
5 - Apply patch
6 - Click on the button "Ask for discharge" -> it will not be possible
  and you will be propperly messaged
7 - Return to the tab "Ask for a discharge", there will be no button
  anymore
8 - On the intranet page, there will be no button anymore
9 - Check out a book
10 - Repeat 7 and 8 and see the message include issue with checkout
11 - Remove fine and repeat 7 & 8

Signed-off-by: Roman Dolny <roman.dolny@jezuici.pl>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 21 Kyle M Hall 2024-08-26 11:04:19 UTC
Created attachment 170706 [details] [review]
Bug 14250: (QA follow-up) Deduplicate checks

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 22 Kyle M Hall 2024-08-26 11:04:22 UTC
Created attachment 170707 [details] [review]
Bug 14250: (QA follow-up) Tidy code
Comment 23 Kyle M Hall 2024-08-26 11:05:36 UTC
(In reply to David Nind from comment #19)
> I was just been about to say the same (that the patch no longer applies). 8-)
> 
> I was testing last week, and hadn't finished before it was signed off.
> 
> I had some suggested text changes - I am happy to add a follow-up once the
> patches apply again. This is so that it makes more sense if there are
> multiple reasons for not discharging.
> 
> Suggested text changes for the OPAC
> ===================================
> 
> You cannot be discharged because:
> . You have unpaid charges of X. Please pay your charges before reapplying.
> . You have X item(s) checked out. Please return your checked out items
> before reapplying.
> . You cannot be discharged for an unknown reason. Please contact library
> staff for more information.
> 
> Suggested text changes for the staff interface
> ==============================================
> 
> A discharge cannot be generated for this patron because:
> . The patron has unpaid charges of X.
> . The patron has X item(s) checked out.
> . The patron cannot be discharged for an unknown reason. Please review the
> patron's account to determine why. (Not sure about this one.)
> 
> The patron has holds. These will be cancelled if the discharge is generated.
> 
> Testing notes
> =============
> 
> 1. In the staff interface, set up these scenarios for some patrons:
>    - Patron A: check out an item and add a manual fee (I used Henry Acevedo)
>    - Patron B: add a manual fee (I used Mary Burton)
>    - Patron C: check out an item (I used Lisa Charles)
>    - Patron D: add a manual fee (I used Bobbie Middleton)
> 2. Edit the patrons so that they have a password and that you can log in to
> their accounts in the OPAC.
> 3. Set the useDischarge system preference to 'Allow'.
> 4. Attempt to request a discharge for the patrons (OPAC > You account > Ask
> for a discharge):
>    - Patron A (Manual fee and a checked out item) (Henry): Message is "You
> cannot be discharged, you have checked out items. Please return items before
> asking for a discharge."
>    - Patron B (Manual fee) (Mary): "Ask for a discharge" button is available
> and a discharge can be requested. Message "Your discharge request has been
> sent. Your discharge will be available on this page within a few days."
>    - Patron C (A checked out item (Lisa)): Message is "You cannot be
> discharged, you have checked out items. Please return items before asking
> for a discharge."
> 5. Apply the patches and restart everything (restart_all).
> 6. Attempt to request a discharge for the patrons from their OPAC accounts
> (OPAC > You account > Ask for a discharge):
> 
>    - Patron A (Manual fee and a checked out item)(Henry): Message is now
>         You cannot be discharged for following reasons:
>         . You have 1 item(s) checked out. Please return them before
> reapplying. 
>         . They have unpaid fines totaling 5.00. Please pay your fines before
> reapplying. 
> 
>    - Patron C (A checked out item) (Lisa):  Message is now
>         You cannot be discharged for following reasons:
>         . You have 1 item(s) checked out. Please return them before
> reapplying. 
>         
>    - Patron D (A manual fee)(Bobbie): 
>         You cannot be discharged for following reasons:
>         . They have unpaid fines totaling 5.00. Please pay your fines before
> reapplying. 
> 
> 7. Attempt to discharge the patrons from the staff interface, from their
> patron account:
> 
>    - Patron A (Manual fee and a checked out item)(Henry): Message is now
>         Cannot edit discharge for following reasons:
>         . They have 1 item(s) checked out
>         . They have unpaid fines totaling 5.00
> 
>    - Patron C (A checked out item) (Lisa):  Message is now
>         Cannot edit discharge for following reasons:
>         . They have 1 item(s) checked out
> 
>    - Patron D (A manual fee)(Bobbie): 
>         Cannot edit discharge for following reasons:
>         . They have unpaid fines totaling 5.00
> 
> OPAC discharge text
> ===================
> 
> I've created bug 37729 for the discharge text on the OPAC "Ask for a
> discharge" page, suggesting that this is changed to an HTML customization -
> so that the text can be customised and translated.
> 
> Current hard coded text
> -----------------------
> 
> Discharge
> 
> What is a discharge?
> 
> This document certifies that you have returned all borrowed items. It is
> sometimes asked during a file transfer from a school to another. The
> discharge is sent by us to your school. You will also find it available on
> your reader account.
>   
> Warning: This request is only valid if you are in good standing with the
> library. Once the application is made, you can not borrow library materials.

Those sound like good changes. Will you add a follow-up for those?
Comment 24 David Nind 2024-08-26 11:20:22 UTC
Created attachment 170708 [details] [review]
Bug 14250: (follow-up) Update messages

Update the text for the reasons the patron cannot be discharged.
Comment 25 David Nind 2024-08-26 11:21:38 UTC
Have added a follow-up patch to update the messages.
Comment 26 Katrin Fischer 2024-08-27 09:11:47 UTC
I think this will always show the note about checkouts:

-                    [% ELSIF has_issues %]
-                        <p>You cannot be discharged, you have checked out items. Please return items before asking for a discharge.</p>
+                    [% ELSIF failure %]
+                        <p>You cannot be discharged because you have checked out items. Please return your checked out items before asking for a discharge.</p>
+                        <ul>
+                        [% IF has_debt %]
+                            <li>You have unpaid charges. Please pay your charges before reapplying.</li>
+                        [% END %]
+                        [% IF has_issues %]
+                            <li>You have checked out items. Please return your checked out items before reapplying.</li>
+                        [% END %]
+                        [% IF !has_issue and !has_debt %]
+                            <li>You cannot be discharged for an unknown reason. Please contact library staff for more information.</li>
+                        [% END %]
+                        </ul>

I believe we should remove/rephrase the <p> line?
Comment 27 Katrin Fischer 2024-08-27 09:16:02 UTC
Why do we have almost the same errors/messages appear twice in the OPAC template?
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-discharge.tt

[% ELSIF failure %]
...

[% UNLESS can_be_discharged %]
...

I like that this makes the code cleaner looking and I also like to see this fixed. Please have a look at this and my previous comment for the template changes.
Comment 28 David Nind 2024-08-28 00:30:29 UTC
I wondered myself. 

I thought it was odd that the messages were repeated in the code, and I couldn't get the text from (I think) the earlier set of messages to display in the OPAC. (See c#19 - step 6 - which has the different scenarios and the messages displayed, before my follow-up patch to change the text.)
Comment 29 Baptiste Wojtkowski (bwoj) 2024-09-02 07:56:19 UTC
(In reply to Katrin Fischer from comment #27)
> Why do we have almost the same errors/messages appear twice in the OPAC
> template?
> koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-discharge.tt
> 
> [% ELSIF failure %]
> ...
> 
> [% UNLESS can_be_discharged %]
> ...
> 
> I like that this makes the code cleaner looking and I also like to see this
> fixed. Please have a look at this and my previous comment for the template
> changes.

I also found it was weird while developing. The business of the function is quite complex and if I'm not mistaken, the lonely way to go through the second one is to load the page for discharge while being allowed to discharge, then disallow the user to get discharged.
Comment 30 Baptiste Wojtkowski (bwoj) 2024-09-02 07:57:56 UTC
(In reply to Katrin Fischer from comment #26)
> I think this will always show the note about checkouts:
> 
> -                    [% ELSIF has_issues %]
> -                        <p>You cannot be discharged, you have checked out
> items. Please return items before asking for a discharge.</p>
> +                    [% ELSIF failure %]
> +                        <p>You cannot be discharged because you have
> checked out items. Please return your checked out items before asking for a
> discharge.</p>
> +                        <ul>
> +                        [% IF has_debt %]
> +                            <li>You have unpaid charges. Please pay your
> charges before reapplying.</li>
> +                        [% END %]
> +                        [% IF has_issues %]
> +                            <li>You have checked out items. Please return
> your checked out items before reapplying.</li>
> +                        [% END %]
> +                        [% IF !has_issue and !has_debt %]
> +                            <li>You cannot be discharged for an unknown
> reason. Please contact library staff for more information.</li>
> +                        [% END %]
> +                        </ul>
> 
> I believe we should remove/rephrase the <p> line?

If I understand well, these sentences have been rephrased here (https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=170708&action=diff), right ?
Comment 31 Katrin Fischer 2024-09-02 11:52:56 UTC
As the both text blocks appear to be added by this patch set - could we reuse the same text block for both, defined in one spot?
Comment 32 Baptiste Wojtkowski (bwoj) 2024-09-02 12:22:56 UTC Comment hidden (obsolete)
Comment 33 Baptiste Wojtkowski (bwoj) 2024-09-04 13:09:00 UTC
Created attachment 171025 [details] [review]
Bug 14250: (follow-up) Refacto the algorithm for discharge messages

TEST PLAN:
1 - In the intranet add fines to a client and ensure they have no checkout
2 - Set syspref useDischarge to 'Allow'
3 - On client profile click on "Discharge", see it is possible
4 - On the opac, go to the tab "Ask for discharge", see it is possible
5 - Apply patch
6 - Click on the button "Ask for discharge" -> it will not be possible
  and you will be propperly messaged
7 - Return to the tab "Ask for a discharge", there will be no button
  anymore
8 - On the intranet page, there will be no button anymore
9 - Check out a book
10 - Repeat 7 and 8 and see the message include issue with checkout
11 - Remove fine and repeat 7 & 8

Note: removing the useless has_checkout and has_debt
Comment 34 Baptiste Wojtkowski (bwoj) 2024-09-04 13:09:04 UTC
Created attachment 171026 [details] [review]
Bug 14250: (follow-up) Refacto discharge messages display

The script that determines if one should display messages to the user,
informing him whether they are allowed or not to ask for a discharge is
quite hard to understand.

For sake of readability, transforming the unless to an if since the
error behaviour was in the unless and the success in the else.
Changing to success behaviour in the if and failure in the else.
Comment 35 Sukhmandeep 2024-09-10 16:49:58 UTC
Created attachment 171271 [details] [review]
Bug 14250: Patron with fines cannot be discharged anymore

TEST PLAN:
1 - In the intranet add fines to a client and ensure they have no checkout
2 - Set syspref useDischarge to 'Allow'
3 - On client profile click on "Discharge", see it is possible
4 - On the opac, go to the tab "Ask for discharge", see it is possible
5 - Apply patch
6 - Click on the button "Ask for discharge" -> it will not be possible
  and you will be propperly messaged
7 - Return to the tab "Ask for a discharge", there will be no button
  anymore
8 - On the intranet page, there will be no button anymore
9 - Check out a book
10 - Repeat 7 and 8 and see the message include issue with checkout
11 - Remove fine and repeat 7 & 8

Signed-off-by: Roman Dolny <roman.dolny@jezuici.pl>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Sukhmandeep Benipal <sukhmandeep.benipal@inLibro.com>
Comment 36 Sukhmandeep 2024-09-10 16:50:04 UTC
Created attachment 171272 [details] [review]
Bug 14250: (QA follow-up) Deduplicate checks

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Sukhmandeep Benipal <sukhmandeep.benipal@inLibro.com>
Comment 37 Sukhmandeep 2024-09-10 16:50:10 UTC
Created attachment 171273 [details] [review]
Bug 14250: (QA follow-up) Tidy code

Signed-off-by: Sukhmandeep Benipal <sukhmandeep.benipal@inLibro.com>
Comment 38 Sukhmandeep 2024-09-10 16:50:13 UTC
Created attachment 171274 [details] [review]
Bug 14250: (follow-up) Update messages

Update the text for the reasons the patron cannot be discharged.

Signed-off-by: Sukhmandeep Benipal <sukhmandeep.benipal@inLibro.com>
Comment 39 Sukhmandeep 2024-09-10 16:50:16 UTC
Created attachment 171275 [details] [review]
Bug 14250: (follow-up) Refacto the algorithm for discharge messages

TEST PLAN:
1 - In the intranet add fines to a client and ensure they have no checkout
2 - Set syspref useDischarge to 'Allow'
3 - On client profile click on "Discharge", see it is possible
4 - On the opac, go to the tab "Ask for discharge", see it is possible
5 - Apply patch
6 - Click on the button "Ask for discharge" -> it will not be possible
  and you will be propperly messaged
7 - Return to the tab "Ask for a discharge", there will be no button
  anymore
8 - On the intranet page, there will be no button anymore
9 - Check out a book
10 - Repeat 7 and 8 and see the message include issue with checkout
11 - Remove fine and repeat 7 & 8

Note: removing the useless has_checkout and has_debt
Signed-off-by: Sukhmandeep Benipal <sukhmandeep.benipal@inLibro.com>
Comment 40 Sukhmandeep 2024-09-10 16:50:19 UTC
Created attachment 171276 [details] [review]
Bug 14250: (follow-up) Refacto discharge messages display

The script that determines if one should display messages to the user,
informing him whether they are allowed or not to ask for a discharge is
quite hard to understand.

For sake of readability, transforming the unless to an if since the
error behaviour was in the unless and the success in the else.
Changing to success behaviour in the if and failure in the else.

Signed-off-by: Sukhmandeep Benipal <sukhmandeep.benipal@inLibro.com>