Bug 36915

Summary: Send email notification when a booking is cancelled
Product: Koha Reporter: Thibaud Guillot <thibaud.guillot>
Component: CirculationAssignee: Thibaud Guillot <thibaud.guillot>
Status: Failed QA --- QA Contact: Martin Renvoize <martin.renvoize>
Severity: enhancement    
Priority: P5 - low CC: david, gmcharlt, jonathan.druart, kyle.m.hall, martin.renvoize
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=37198
Change sponsored?: Sponsored Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Bug Depends on: 29002    
Bug Blocks: 36666, 36789, 37034    
Attachments: Bug 36915: Send email notification when a booking is cancelled
Bug 36915: Send email notification when a booking is cancelled
Bug 36915: Send email notification when a booking is cancelled
Bug 36915: (follow-up) Pass object to GetPreparedLetter
Bug 36915: (follow-up) Basic sample notice

Description Thibaud Guillot 2024-05-22 08:11:14 UTC
Hello :)

I purpose to add an email notification to patron when a booking is cancelled.
Comment 1 Thibaud Guillot 2024-05-22 08:13:14 UTC
Created attachment 167010 [details] [review]
Bug 36915: Send email notification when a booking is cancelled

When a booking is cancelled, patron received an email based on specific
letter.

Test plan:

1) Create a letter with code "BOOKING_CANCELLATION" on "Notices and
   slips" tool.
2) Add booking or go on item already booked in advance.
3) Cancel it
4) Verify in message_queue table directly or go on patron page and click
   on "Notices" tab section.

Sponsored by: Association de Gestion des Œuvres Sociales d'Inria (AGOS)
Comment 2 Jonathan Druart 2024-05-22 08:34:47 UTC
Shouldn't this be in $booking->delete instead?
Comment 3 Thibaud Guillot 2024-05-22 09:05:24 UTC
Created attachment 167013 [details] [review]
Bug 36915: Send email notification when a booking is cancelled

When a booking is cancelled, patron received an email based on specific
letter.

Test plan:

1) Create a letter with code "BOOKING_CANCELLATION" on "Notices and
   slips" tool.
2) Add booking or go on item already booked in advance.
3) Cancel it
4) Verify in message_queue table directly or go on patron page and click
   on "Notices" tab section.

Sponsored by: Association de Gestion des Œuvres Sociales d'Inria (AGOS)
Comment 4 Thibaud Guillot 2024-05-22 09:06:25 UTC
(In reply to Jonathan Druart from comment #2)
> Shouldn't this be in $booking->delete instead?

Thanks for your feedback, you're right.. I was wrong :)
Comment 5 Jonathan Druart 2024-05-22 09:11:55 UTC
And please provide tests ;)
Comment 6 Martin Renvoize 2024-06-20 10:50:08 UTC
I like this, and it was indeed on my enhancements list ;)

Couple of comments, however.. 

1) Could we pass the bookings object into GetPreparedLetter instead of passing various individual pieces. (Bug 19966 adds this functionality to GetPreperaredLetter, you'd want to pass the object and then call delete at the end of the method after GetPreparredLetter has returned)
2) Could we add a sample notice template too.
Comment 7 Martin Renvoize 2024-06-26 14:39:03 UTC
Created attachment 168149 [details] [review]
Bug 36915: Send email notification when a booking is cancelled

When a booking is cancelled, patron received an email based on specific
letter.

Test plan:

1) Create a letter with code "BOOKING_CANCELLATION" on "Notices and
   slips" tool.
2) Add booking or go on item already booked in advance.
3) Cancel it
4) Verify in message_queue table directly or go on patron page and click
   on "Notices" tab section.

Sponsored by: Association de Gestion des Œuvres Sociales d'Inria (AGOS)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 8 Martin Renvoize 2024-06-26 14:39:06 UTC
Created attachment 168150 [details] [review]
Bug 36915: (follow-up) Pass object to GetPreparedLetter

This patch updates the logic to pass the object to be deleted through to
GetPreparedLetter.

This way, as we add fields and accessors to the object in the future,
they will automatically become available to the notices.
Comment 9 Martin Renvoize 2024-06-26 14:42:24 UTC
I added the suggested follow-up to utilise the 'objects' option in GetPreparedLetter.

Still needs unit tests.. I'll try to take a look at adding those when I can.

I'm also working on a default notice template to ship.

I do wonder if we really want to tie this to 'delete'.. I'd be tempted to introduce a 'cancel' method to be more explicit. Then if we later introduce database cleanup or other workflows that include deletions we can call the standard delete method without having to work around the cancellation message handling.
Comment 10 Martin Renvoize 2024-06-26 14:57:30 UTC
Created attachment 168155 [details] [review]
Bug 36915: (follow-up) Basic sample notice
Comment 11 David Nind 2024-07-04 21:17:38 UTC
I've Failed QA because when you preview the notice, there is a huge amount of white space before the actual message.

I'm not sure whether this is because of the sample notice, or something else.

Either way, I don't know how to fix this (otherwise I would have added a follow-up).

Suggestion:
- Change the title of the notice to "A library booking was cancelled"
- In the notice change "You library" to "Your library"

Do we do database updates for new sample notices?

Testing notes (using KTD):

1. Apply the patches.
2. Reset everything (so the sample notice is available): reset_all
3. Add an email address to the patron you will make the booking for (for example, Mary Burton, mary@example.com)
4. Add a booking:
   . Find a record
   . Go to Items > Priority
   . Change "Bookable" to "Yes" then click "Update"
   . Use the "Place booking" action for the record
   . Enter the details to create a booking (using the patron you added an email address to)
5. Cancel a booking:
   . Go to the record
   . Select the Bookings section
   . Click "Cancel" for the booking you made in step 4
   . Click "Confirm" in the pop-up window to cancel the booking
6. Check that a notice was generated:
   . Go to the notices section for the patron
   OR
   . Check the message queue in the database:
     - koha-mysql kohadev
     - select * from message_queue;