From 0865898724d622e42b5e9b0f8173fb46d8594d75 Mon Sep 17 00:00:00 2001 From: Thibaud Guillot Date: Wed, 22 May 2024 09:59:51 +0200 Subject: [PATCH] Bug 36915: Send email notification when a booking is cancelled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- Koha/Booking.pm | 47 +++++++++++++++++++ .../prog/en/modules/tools/letter.tt | 7 +++ tools/letter.pl | 2 + 3 files changed, 56 insertions(+) diff --git a/Koha/Booking.pm b/Koha/Booking.pm index f1004ae1f73..0d0d1fc8aac 100644 --- a/Koha/Booking.pm +++ b/Koha/Booking.pm @@ -21,6 +21,11 @@ use Modern::Perl; use Koha::Exceptions::Booking; use Koha::DateUtils qw( dt_from_string ); +use Koha::Items; +use Koha::Patrons; +use Koha::Libraries; + +use C4::Letters; use base qw(Koha::Object); @@ -239,6 +244,48 @@ sub to_api_mapping { return {}; } +=head3 delete + +$booking->delete(); + +=cut + +sub delete { + my ( $self ) = @_; + + my $deleted = $self->SUPER::delete($self); + my $patron = Koha::Patrons->find( $self->patron_id ); + my $item = Koha::Items->find( $self->item_id ); + my $library = Koha::Libraries->find( $self->pickup_library_id ); + + my $letter = C4::Letters::GetPreparedLetter( + module => 'bookings', + letter_code => 'BOOKING_CANCELLATION', + message_transport_type => 'email', + branchcode => $patron->branchcode, + lang => $patron->lang, + tables => { + branches => $library->branchcode, + borrowers => $patron->borrowernumber, + items => $item->itemnumber, + biblio => $item->biblionumber, + biblioitems => $item->biblionumber, + bookings => $self->unblessed, + } + ); + + if ($letter) { + C4::Letters::EnqueueLetter( + { + letter => $letter, + borrowernumber => $patron->borrowernumber, + message_transport_type => 'email', + } + ); + } + return $deleted; +} + =head2 Internal methods =head3 _type diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt index 22379532e50..eb6e0a3e9d2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt @@ -182,6 +182,7 @@
  • Suggestions
  • Point of sale
  • Reports
  • +
  • Bookings
  • @@ -243,6 +244,7 @@ [% CASE 'suggestions' %]Suggestions [% CASE 'pos' %]Point of sale [% CASE 'report' %]Reports + [% CASE 'bookings' %]Bookings [% CASE %][% lette.module | html %] [% END %] @@ -441,6 +443,11 @@ [% ELSE %] [% END %] + [% IF ( module == "bookings" ) %] + + [% ELSE %] + + [% END %]
  • diff --git a/tools/letter.pl b/tools/letter.pl index 9e9b9e386fa..c3ed7e432fd 100755 --- a/tools/letter.pl +++ b/tools/letter.pl @@ -254,6 +254,8 @@ sub add_form { add_fields( 'branches', 'biblio', 'biblioitems', 'borrowers', 'subscription', 'serial' ); } elsif ( $module eq 'suggestions' ) { push @{$field_selection}, add_fields( 'suggestions', 'borrowers', 'biblio' ); + } elsif ( $module eq 'bookings' ) { + push @{$field_selection}, add_fields( 'borrowers', 'bookings', 'biblio', 'biblioitems', 'items' ); } else { push @{$field_selection}, add_fields( 'biblio', 'biblioitems' ), add_fields('items'), -- 2.45.2