Bug 26689

Summary: Monetary accounts notices should be definable at the credit_type/debit_type level
Product: Koha Reporter: Martin Renvoize (ashimema) <martin.renvoize>
Component: NoticesAssignee: Martin Renvoize (ashimema) <martin.renvoize>
Status: CLOSED FIXED QA Contact: Kyle M Hall (khall) <kyle>
Severity: enhancement    
Priority: P5 - low CC: caroline.cyr-la-rose, joonas.kylmala, kyle, lucas, sally.healey, victor
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Trivial patch
Documentation contact: Caroline Cyr La Rose Documentation submission: https://gitlab.com/koha-community/koha-manual/-/merge_requests/678
Text to go in the release notes:
**Sponsored by** *PTFS Europe* This enhancement allows end users to define their account notices (print receipt and print invoice for example) at the debit type and credit type level. Simply add a new notice with code 'DEBIT_your_debit_type_code' or 'CREDIT_your_credit_type_code' to the notices and we will pick that over the existing default 'ACCOUNT_DEBIT' and 'ACCOUNT_CREDIT' notices.
Version(s) released in:
22.11.00,21.11, 22.05.05
Circulation function:
Bug Depends on: 26734    
Bug Blocks: 24381    
Attachments: Bug 26686: Fix sorting of "updated on" and "time created" on notices tab
Bug 26689: Check for specific template then fallback
Bug 26689: Check for specific template then fallback - printfeercpt
Bug 26689: Check for specific template then fallback - printinvoice
Bug 26689: Check for specific template then fallback - printfeercpt
Bug 26689: Check for specific template then fallback - printinvoice
Bug 26689: Check for specific template then fallback - printfeercpt
Bug 26689: Check for specific template then fallback - printinvoice
Bug 26689: Check for specific template then fallback - printfeercpt
Bug 26689: Check for specific template then fallback - printinvoice
Bug 26689: Check for specific template then fallback - printfeercpt
Bug 26689: Check for specific template then fallback - printinvoice
Bug 26689: Prepend letter codes.

Description Martin Renvoize (ashimema) 2020-10-15 10:04:21 UTC
Currently, the print and email notices associated with account actions (receipts, invoices, credit notes etc) are confusingly named and are generalised for all types.

We should allow for per-type notices to be assigned to credit/debit types to enable a more accurate approach to these notices.
Comment 1 Katrin Fischer 2020-10-20 23:55:13 UTC
Created attachment 112081 [details] [review]
Bug 26686: Fix sorting of "updated on" and "time created" on notices tab

In the patron's account in the staff interface there is a tab
'Notices' that shows all notices sent out to a patron. The
updated on column would not sort at all, but there was also some
markup missing for the time created column.

To test:
- Make sure you have a patron account with some notices, ideally
  with different times and dates
- Verify that the updated on column doesn't sort at all
- Apply patch
- Verify both date columns now sort correctly for different
  DateFormat settings
Comment 2 Martin Renvoize (ashimema) 2021-03-12 14:40:51 UTC
Created attachment 118204 [details] [review]
Bug 26689: Check for specific template then fallback

This patch adds a check for a more specific ACCOUNT_CREDIT template
(named to match the credit_type_code of the credit line) prior to
falling back to the ACCOUNT_CREDIT template.
Comment 3 Martin Renvoize (ashimema) 2021-03-12 16:18:49 UTC
Created attachment 118211 [details] [review]
Bug 26689: Check for specific template then fallback - printfeercpt

This patch adds a check for a more specific ACCOUNT_CREDIT template
(named to match the credit_type_code of the credit line) prior to
falling back to the ACCOUNT_CREDIT template.

Test plan
1/ On a patrons account page use the print option on a series of credit
lines with differing credit types (Payment, Lost Item Return, Writeoff)
2/ Note that the same template 'ACCOUNT_CREDIT' is used for all types
3/ Apply the patch
4/ Run step 1 again and note all still print using ACCOUNT_CREDIT
5/ Add a new notice template under the 'circulation' module with a code
that matches one of your account credit types (PAYMENT, WRITEOFF,
LOST_FOUND)
6/ Run step 1 again and note that where you have added a specific notice
for that credit type it has been used.
Comment 4 Martin Renvoize (ashimema) 2021-03-12 16:18:52 UTC
Created attachment 118212 [details] [review]
Bug 26689: Check for specific template then fallback - printinvoice

This patch adds a check for a more specific ACCOUNT_DEBIT template
(named to match the debit_type_code of the credit line) prior to
falling back to the ACCOUNT_DEBIT template.

Test plan
1/ On a patrons account page use the print option on a series of debit
lines with differing credit types (Overdue, Payout)
2/ Note that the same template 'ACCOUNT_DEBIT' is used for all types
3/ Apply the patch
4/ Run step 1 again and note all still print using ACCOUNT_DEBIT
5/ Add a new notice template under the 'circulation' module with a code
that matches one of your account debit types (OVERDUE, PAYOUT)
6/ Run step 1 again and note that where you have added a specific notice
for that debit type it has been used.
Comment 5 Martin Renvoize (ashimema) 2021-03-12 16:22:53 UTC
Where this becomes really cool is for where a debit type or credit type doesn't entirely fit with the expected...

Examples:

* WRITEOFF is a credit type but it's not a payment.. so doesn't make sense to have 'Thanks for your payment'
* CREDIT is a credit type for credit notes.. it makes sense to have it's own notice
* PAYOUT is a debit type.. but it really doesn't make sense to print it the same way as other debit types.
Comment 6 Joonas Kylmälä 2021-04-12 13:48:43 UTC
Martin, this doesn't apply anymore, could you now do re-do this as the missing dependency was just pushed to master?
Comment 7 Martin Renvoize (ashimema) 2021-04-14 13:06:58 UTC
Created attachment 119572 [details] [review]
Bug 26689: Check for specific template then fallback - printfeercpt

This patch adds a check for a more specific ACCOUNT_CREDIT template
(named to match the credit_type_code of the credit line) prior to
falling back to the ACCOUNT_CREDIT template.

Test plan
1/ On a patrons account page use the print option on a series of credit
lines with differing credit types (Payment, Lost Item Return, Writeoff)
2/ Note that the same template 'ACCOUNT_CREDIT' is used for all types
3/ Apply the patch
4/ Run step 1 again and note all still print using ACCOUNT_CREDIT
5/ Add a new notice template under the 'circulation' module with a code
that matches one of your account credit types (PAYMENT, WRITEOFF,
LOST_FOUND)
6/ Run step 1 again and note that where you have added a specific notice
for that credit type it has been used.
Comment 8 Martin Renvoize (ashimema) 2021-04-14 13:07:02 UTC
Created attachment 119573 [details] [review]
Bug 26689: Check for specific template then fallback - printinvoice

This patch adds a check for a more specific ACCOUNT_DEBIT template
(named to match the debit_type_code of the credit line) prior to
falling back to the ACCOUNT_DEBIT template.

Test plan
1/ On a patrons account page use the print option on a series of debit
lines with differing credit types (Overdue, Payout)
2/ Note that the same template 'ACCOUNT_DEBIT' is used for all types
3/ Apply the patch
4/ Run step 1 again and note all still print using ACCOUNT_DEBIT
5/ Add a new notice template under the 'circulation' module with a code
that matches one of your account debit types (OVERDUE, PAYOUT)
6/ Run step 1 again and note that where you have added a specific notice
for that debit type it has been used.
Comment 9 Martin Renvoize (ashimema) 2021-04-14 13:11:55 UTC
Created attachment 119574 [details] [review]
Bug 26689: Check for specific template then fallback - printfeercpt

This patch adds a check for a more specific ACCOUNT_CREDIT template
(named to match the credit_type_code of the credit line) prior to
falling back to the ACCOUNT_CREDIT template.

Test plan
1/ On a patrons account page use the print option on a series of credit
lines with differing credit types (Payment, Lost Item Return, Writeoff)
2/ Note that the same template 'ACCOUNT_CREDIT' is used for all types
3/ Apply the patch
4/ Run step 1 again and note all still print using ACCOUNT_CREDIT
5/ Add a new notice template under the 'circulation' module with a code
that matches one of your account credit types (PAYMENT, WRITEOFF,
LOST_FOUND)
6/ Run step 1 again and note that where you have added a specific notice
for that credit type it has been used.
Comment 10 Martin Renvoize (ashimema) 2021-04-14 13:11:59 UTC
Created attachment 119575 [details] [review]
Bug 26689: Check for specific template then fallback - printinvoice

This patch adds a check for a more specific ACCOUNT_DEBIT template
(named to match the debit_type_code of the credit line) prior to
falling back to the ACCOUNT_DEBIT template.

Test plan
1/ On a patrons account page use the print option on a series of debit
lines with differing credit types (Overdue, Payout)
2/ Note that the same template 'ACCOUNT_DEBIT' is used for all types
3/ Apply the patch
4/ Run step 1 again and note all still print using ACCOUNT_DEBIT
5/ Add a new notice template under the 'circulation' module with a code
that matches one of your account debit types (OVERDUE, PAYOUT)
6/ Run step 1 again and note that where you have added a specific notice
for that debit type it has been used.
Comment 11 Martin Renvoize (ashimema) 2021-04-14 13:19:43 UTC
It seems bug 26734 hasn't actually been pushed.. just the first patch from it accidentally made it in.. as such I've undone my rebase and unobsoleted the two patches.
Comment 12 Martin Renvoize (ashimema) 2021-04-27 15:17:33 UTC
This applies nicely again now as is :)
Comment 13 Biblibre Sandboxes 2022-05-18 13:57:11 UTC
Created attachment 135113 [details] [review]
Bug 26689: Check for specific template then fallback - printfeercpt

This patch adds a check for a more specific ACCOUNT_CREDIT template
(named to match the credit_type_code of the credit line) prior to
falling back to the ACCOUNT_CREDIT template.

Test plan
1/ On a patrons account page use the print option on a series of credit
lines with differing credit types (Payment, Lost Item Return, Writeoff)
2/ Note that the same template 'ACCOUNT_CREDIT' is used for all types
3/ Apply the patch
4/ Run step 1 again and note all still print using ACCOUNT_CREDIT
5/ Add a new notice template under the 'circulation' module with a code
that matches one of your account credit types (PAYMENT, WRITEOFF,
LOST_FOUND)
6/ Run step 1 again and note that where you have added a specific notice
for that credit type it has been used.

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 14 Biblibre Sandboxes 2022-05-18 13:57:16 UTC
Created attachment 135114 [details] [review]
Bug 26689: Check for specific template then fallback - printinvoice

This patch adds a check for a more specific ACCOUNT_DEBIT template
(named to match the debit_type_code of the credit line) prior to
falling back to the ACCOUNT_DEBIT template.

Test plan
1/ On a patrons account page use the print option on a series of debit
lines with differing credit types (Overdue, Payout)
2/ Note that the same template 'ACCOUNT_DEBIT' is used for all types
3/ Apply the patch
4/ Run step 1 again and note all still print using ACCOUNT_DEBIT
5/ Add a new notice template under the 'circulation' module with a code
that matches one of your account debit types (OVERDUE, PAYOUT)
6/ Run step 1 again and note that where you have added a specific notice
for that debit type it has been used.

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 15 Sally 2022-05-18 13:58:01 UTC
This is a really nice development - works great, signing off.
Comment 16 Kyle M Hall (khall) 2022-06-03 16:32:41 UTC
Created attachment 135685 [details] [review]
Bug 26689: Check for specific template then fallback - printfeercpt

This patch adds a check for a more specific ACCOUNT_CREDIT template
(named to match the credit_type_code of the credit line) prior to
falling back to the ACCOUNT_CREDIT template.

Test plan
1/ On a patrons account page use the print option on a series of credit
lines with differing credit types (Payment, Lost Item Return, Writeoff)
2/ Note that the same template 'ACCOUNT_CREDIT' is used for all types
3/ Apply the patch
4/ Run step 1 again and note all still print using ACCOUNT_CREDIT
5/ Add a new notice template under the 'circulation' module with a code
that matches one of your account credit types (PAYMENT, WRITEOFF,
LOST_FOUND)
6/ Run step 1 again and note that where you have added a specific notice
for that credit type it has been used.

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 17 Kyle M Hall (khall) 2022-06-03 16:32:53 UTC
Created attachment 135686 [details] [review]
Bug 26689: Check for specific template then fallback - printinvoice

This patch adds a check for a more specific ACCOUNT_DEBIT template
(named to match the debit_type_code of the credit line) prior to
falling back to the ACCOUNT_DEBIT template.

Test plan
1/ On a patrons account page use the print option on a series of debit
lines with differing credit types (Overdue, Payout)
2/ Note that the same template 'ACCOUNT_DEBIT' is used for all types
3/ Apply the patch
4/ Run step 1 again and note all still print using ACCOUNT_DEBIT
5/ Add a new notice template under the 'circulation' module with a code
that matches one of your account debit types (OVERDUE, PAYOUT)
6/ Run step 1 again and note that where you have added a specific notice
for that debit type it has been used.

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 18 Katrin Fischer 2022-06-25 12:53:14 UTC
I am a little worried that there could be an overlap with existing notice template codes resulting in 'strange' behaviour.

5/ Add a new notice template under the 'circulation' module with a code
that matches one of your account debit types (OVERDUE, PAYOUT)

OVERDUE and circulation seems a super likely candidate, even if the standard notice is ODUE, but this can be configured as libraries like... 

Maybe it would be a little safer to use these with a prefix? Something like ACCOUNT_ could be a good fit.
Comment 19 Martin Renvoize (ashimema) 2022-06-29 16:29:04 UTC
Created attachment 136744 [details] [review]
Bug 26689: Prepend letter codes.

This patch prepends the credit_type_code and debit_type_code with
CREDIT_ and DEBIT_ respectively when doing a lookup on the notice letter
code.

Test plan
1) As previous patches, however instead of just naming your notice to
   match the credit_type_code or debit_type_code use
   CREDIT_credit_type_code and DEBIT_debit_type_code respectively.
Comment 20 Martin Renvoize (ashimema) 2022-06-29 16:31:58 UTC
Nice catch Katrin.. added a follow-up and added notes for the release notes.
Comment 21 Katrin Fischer 2022-07-02 22:09:20 UTC
(In reply to Martin Renvoize from comment #20)
> Nice catch Katrin.. added a follow-up and added notes for the release notes.

Thanks!
Comment 22 Tomás Cohen Arazi (tcohen) 2022-07-22 18:19:05 UTC
Pushed to master for 22.11.

Nice work everyone, thanks!
Comment 23 Lucas Gass (lukeg) 2022-09-02 17:54:36 UTC
Backported to 22.05.x for 22.05.05
Comment 24 Arthur Suzuki 2022-09-14 12:58:23 UTC
Thanks!

Pushed to 21.11 for 21.11.12
Comment 25 Victor Grousset/tuxayo 2022-09-20 18:28:36 UTC
Not backported to oldoldstable (21.05.x). Feel free to ask if it's needed.