Bug 36915 - Send email notification when a booking is cancelled
Summary: Send email notification when a booking is cancelled
Status: Needs documenting
Alias: None
Product: Koha
Classification: Unclassified
Component: Circulation (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Thibaud Guillot (thibaud_g)
QA Contact: Martin Renvoize (ashimema)
URL:
Keywords:
Depends on: 29002
Blocks: 36666 36789 37034 37202 37203 37204 38490
  Show dependency treegraph
 
Reported: 2024-05-22 08:11 UTC by Thibaud Guillot (thibaud_g)
Modified: 2024-11-20 10:28 UTC (History)
8 users (show)

See Also:
Change sponsored?: Sponsored
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
This enhancement sends a notice to a patron when a booking is cancelled using the new BOOKING_CANCELLATION notice. **Sponsored by** *BibLibre*
Version(s) released in:
24.11.00
Circulation function: bookings


Attachments
Bug 36915: Send email notification when a booking is cancelled (5.79 KB, patch)
2024-05-22 08:13 UTC, Thibaud Guillot (thibaud_g)
Details | Diff | Splinter Review
Bug 36915: Send email notification when a booking is cancelled (5.62 KB, patch)
2024-05-22 09:05 UTC, Thibaud Guillot (thibaud_g)
Details | Diff | Splinter Review
Bug 36915: Send email notification when a booking is cancelled (5.68 KB, patch)
2024-06-26 14:39 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 36915: (follow-up) Pass object to GetPreparedLetter (2.86 KB, patch)
2024-06-26 14:39 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 36915: (follow-up) Basic sample notice (1.60 KB, patch)
2024-06-26 14:57 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 36915: (follow-up) Make basic sample notice html and add breaks (2.09 KB, patch)
2024-08-05 12:13 UTC, Paul Derscheid
Details | Diff | Splinter Review
Bug 36915: Send email notification when a booking is cancelled (5.73 KB, patch)
2024-08-06 07:47 UTC, David Nind
Details | Diff | Splinter Review
Bug 36915: (follow-up) Pass object to GetPreparedLetter (2.90 KB, patch)
2024-08-06 07:47 UTC, David Nind
Details | Diff | Splinter Review
Bug 36915: (follow-up) Basic sample notice (1.64 KB, patch)
2024-08-06 07:48 UTC, David Nind
Details | Diff | Splinter Review
Bug 36915: (follow-up) Make basic sample notice html and add breaks (2.14 KB, patch)
2024-08-06 07:48 UTC, David Nind
Details | Diff | Splinter Review
Bug 36915: (follow-up) Include branchname in sample notice (1.52 KB, patch)
2024-08-06 13:24 UTC, Paul Derscheid
Details | Diff | Splinter Review
Bug 36915: (follow-up) Add tests (2.78 KB, patch)
2024-08-08 10:36 UTC, Paul Derscheid
Details | Diff | Splinter Review
Bug 36915: Send email notification when a booking is cancelled (5.77 KB, patch)
2024-08-09 15:39 UTC, Owen Leonard
Details | Diff | Splinter Review
Bug 36915: (follow-up) Pass object to GetPreparedLetter (2.95 KB, patch)
2024-08-09 15:39 UTC, Owen Leonard
Details | Diff | Splinter Review
Bug 36915: (follow-up) Basic sample notice (1.69 KB, patch)
2024-08-09 15:39 UTC, Owen Leonard
Details | Diff | Splinter Review
Bug 36915: (follow-up) Make basic sample notice html and add breaks (2.19 KB, patch)
2024-08-09 15:40 UTC, Owen Leonard
Details | Diff | Splinter Review
Bug 36915: (follow-up) Include branchname in sample notice (1.57 KB, patch)
2024-08-09 15:40 UTC, Owen Leonard
Details | Diff | Splinter Review
Bug 36915: (follow-up) Add tests (2.83 KB, patch)
2024-08-09 15:40 UTC, Owen Leonard
Details | Diff | Splinter Review
Bug 36915: Send email notification when a booking is cancelled (5.84 KB, patch)
2024-08-15 14:37 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 36915: (follow-up) Pass object to GetPreparedLetter (3.02 KB, patch)
2024-08-15 14:37 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 36915: (follow-up) Basic sample notice (1.76 KB, patch)
2024-08-15 14:37 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 36915: (follow-up) Make basic sample notice html and add breaks (2.25 KB, patch)
2024-08-15 14:37 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 36915: (follow-up) Include branchname in sample notice (1.64 KB, patch)
2024-08-15 14:37 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 36915: (follow-up) Add tests (2.89 KB, patch)
2024-08-15 14:37 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 36915: (QA follow-up) Passing less to encourage traversal (1.74 KB, patch)
2024-08-15 14:37 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Thibaud Guillot (thibaud_g) 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 (thibaud_g) 2024-05-22 08:13:14 UTC Comment hidden (obsolete)
Comment 2 Jonathan Druart 2024-05-22 08:34:47 UTC
Shouldn't this be in $booking->delete instead?
Comment 3 Thibaud Guillot (thibaud_g) 2024-05-22 09:05:24 UTC Comment hidden (obsolete)
Comment 4 Thibaud Guillot (thibaud_g) 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 (ashimema) 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 (ashimema) 2024-06-26 14:39:03 UTC Comment hidden (obsolete)
Comment 8 Martin Renvoize (ashimema) 2024-06-26 14:39:06 UTC Comment hidden (obsolete)
Comment 9 Martin Renvoize (ashimema) 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 (ashimema) 2024-06-26 14:57:30 UTC Comment hidden (obsolete)
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;
Comment 12 Martin Renvoize (ashimema) 2024-07-08 09:17:10 UTC
Speaking to ByWater and their partners using Bookings, they would indeed want to keep the booking around for reports down the line. I think we should add a 'status' field to bookings to track that they have been placed, cancelled, fulfilled and add a 'cancel' method to set it with an optional 'delete' that can be passed would you want to remove the booking rather than just set to cancelled.

I'll look into the notice issue highlighted by David too.
Comment 13 Paul Derscheid 2024-08-05 12:13:57 UTC Comment hidden (obsolete)
Comment 14 Paul Derscheid 2024-08-05 12:16:33 UTC
Making the sample notice html by setting is_html to true fixes the whitespace problem.

I also added David's suggestions to the sample notice while I was at it.
Comment 15 David Nind 2024-08-06 07:47:55 UTC
Created attachment 170077 [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>
Signed-off-by: David Nind <david@davidnind.com>
Comment 16 David Nind 2024-08-06 07:47:58 UTC
Created attachment 170078 [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.

Signed-off-by: David Nind <david@davidnind.com>
Comment 17 David Nind 2024-08-06 07:48:01 UTC
Created attachment 170079 [details] [review]
Bug 36915: (follow-up) Basic sample notice

Signed-off-by: David Nind <david@davidnind.com>
Comment 18 David Nind 2024-08-06 07:48:03 UTC
Created attachment 170080 [details] [review]
Bug 36915: (follow-up) Make basic sample notice html and add breaks

Signed-off-by: David Nind <david@davidnind.com>
Comment 19 Nick Clemens (kidclamp) 2024-08-06 12:15:50 UTC
Blockers:
Unit tests still needed

Questions:
Should this notice always be sent? Hold cancellations have a 'reason' and nothing is sent when the reason is skipped. I think we should have something similar here - suppose the library just wants to move the booking to a new edition etc.

Should there be a messaging preference? Patrons may not want to receive these notices, are they mandatory?

Suggestion:
"Your library" in notice is somewhat unclear - is this notice coming from the library who owns the material, or the patron's library? We should use a template "branchname" and display the actual library
Comment 20 Paul Derscheid 2024-08-06 13:24:41 UTC
Created attachment 170099 [details] [review]
Bug 36915: (follow-up) Include branchname in sample notice
Comment 21 Paul Derscheid 2024-08-06 13:46:07 UTC
That last patch adds the missing branchname of the pickup library to the notice.

Other sample notices include a lot of fields of the library object, not sure whether we should do this here as well or the branchname is sufficient.
Comment 22 Paul Derscheid 2024-08-08 10:36:20 UTC
Created attachment 170155 [details] [review]
Bug 36915: (follow-up) Add tests
Comment 23 Paul Derscheid 2024-08-08 10:40:23 UTC
Questions:
> Should this notice always be sent? Hold cancellations have a 'reason' and nothing is sent when the reason is skipped. I think we should have something similar here - suppose the library just wants to move the booking to a new edition etc.

I'd like to get this thing through and move the cancellation via a cancel method into two follow-up bugs.
  1. Add a status column to the bookings table. 
  2. Move the the notification from delete into cancel and also change the status to 'cancelled' (Child of 1).

> Should there be a messaging preference? Patrons may not want to receive these notices, are they mandatory?

This should probably also be it's own bug (Child or 2).
Comment 24 Owen Leonard 2024-08-09 15:39:54 UTC
Created attachment 170203 [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>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Comment 25 Owen Leonard 2024-08-09 15:39:57 UTC
Created attachment 170204 [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.

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Comment 26 Owen Leonard 2024-08-09 15:39:59 UTC
Created attachment 170205 [details] [review]
Bug 36915: (follow-up) Basic sample notice

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Comment 27 Owen Leonard 2024-08-09 15:40:01 UTC
Created attachment 170206 [details] [review]
Bug 36915: (follow-up) Make basic sample notice html and add breaks

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Comment 28 Owen Leonard 2024-08-09 15:40:04 UTC
Created attachment 170207 [details] [review]
Bug 36915: (follow-up) Include branchname in sample notice

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Comment 29 Owen Leonard 2024-08-09 15:40:06 UTC
Created attachment 170208 [details] [review]
Bug 36915: (follow-up) Add tests

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Comment 30 Martin Renvoize (ashimema) 2024-08-15 14:37:09 UTC
Created attachment 170385 [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>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 31 Martin Renvoize (ashimema) 2024-08-15 14:37:12 UTC
Created attachment 170386 [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.

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 32 Martin Renvoize (ashimema) 2024-08-15 14:37:15 UTC
Created attachment 170387 [details] [review]
Bug 36915: (follow-up) Basic sample notice

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 33 Martin Renvoize (ashimema) 2024-08-15 14:37:18 UTC
Created attachment 170388 [details] [review]
Bug 36915: (follow-up) Make basic sample notice html and add breaks

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 34 Martin Renvoize (ashimema) 2024-08-15 14:37:22 UTC
Created attachment 170389 [details] [review]
Bug 36915: (follow-up) Include branchname in sample notice

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 35 Martin Renvoize (ashimema) 2024-08-15 14:37:25 UTC
Created attachment 170390 [details] [review]
Bug 36915: (follow-up) Add tests

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 36 Martin Renvoize (ashimema) 2024-08-15 14:37:28 UTC
Created attachment 170391 [details] [review]
Bug 36915: (QA follow-up) Passing less to encourage traversal

I generally push for contextual use of accessors in TT notices and try
to reduce extra lookups.

In this case we can access the pickup library branchname directly using
the pickup_library relation available to us in the booking object we
pass.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 37 Martin Renvoize (ashimema) 2024-08-15 14:38:05 UTC
More great teamwork and it's great to see bookings edging forward now.

All works really nicely now, no regressions and well tested.

Passing QA
Comment 38 Katrin Fischer 2024-08-27 09:24:35 UTC
Are there any plans to make this a patron messaging preference?
It seems at the moment this feature can only be turned on/off by adding or deleting the notice.
Comment 39 Paul Derscheid 2024-08-27 09:41:43 UTC
Yes, there are plans, but we wanted to move the control aspect into follow-up bugs.
Comment 40 Katrin Fischer 2024-08-27 09:45:44 UTC
(In reply to Paul Derscheid from comment #39)
> Yes, there are plans, but we wanted to move the control aspect into
> follow-up bugs.

Is it an option to have it for this release?

I think than we could also do a database update to add the notice by default, as we'd not turn it on for the patrons automatically. Makes it cleaner.

Also update path:

If we introduce the messaging preference later, we will need to deal with creating "checkboxes" if the notice exists, assuming the library is using it not to deactivate it by accident. Also checking where the notice exists and matching that to the home libraries of the patrons... messier to do later.
Comment 41 Katrin Fischer 2024-08-27 10:15:08 UTC
Pushed for 24.11!

Well done everyone, thank you!
Comment 42 Katrin Fischer 2024-11-14 15:26:08 UTC
(In reply to Katrin Fischer from comment #40)
> (In reply to Paul Derscheid from comment #39)
> > Yes, there are plans, but we wanted to move the control aspect into
> > follow-up bugs.
> 
> Is it an option to have it for this release?
> 
> I think than we could also do a database update to add the notice by
> default, as we'd not turn it on for the patrons automatically. Makes it
> cleaner.
> 
> Also update path:
> 
> If we introduce the messaging preference later, we will need to deal with
> creating "checkboxes" if the notice exists, assuming the library is using it
> not to deactivate it by accident. Also checking where the notice exists and
> matching that to the home libraries of the patrons... messier to do later.

Never got a reply :( This will make an update later on harder.