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>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Thibaud Guillot 2024-05-22 09:59:51 +02:00 committed by Katrin Fischer
parent 0cdfb10f37
commit 0ba56480a5
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
3 changed files with 56 additions and 0 deletions

View File

@ -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

View File

@ -203,6 +203,7 @@
<li><a class="dropdown-item" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=suggestions">Suggestions</a></li>
<li><a class="dropdown-item" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=pos">Point of sale</a></li>
<li><a class="dropdown-item" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=report">Reports</a></li>
<li><a class="dropdown-item" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;module=bookings">Bookings</a></li>
</ul>
</div>
</div> <!-- /#toolbar -->
@ -264,6 +265,7 @@
[% CASE 'suggestions' %]<span>Suggestions</span>
[% CASE 'pos' %]<span>Point of sale</span>
[% CASE 'report' %]<span>Reports</span>
[% CASE 'bookings' %]<span>Bookings</span>
[% CASE %]<span>[% lette.module | html %]</span>
[% END %]
</td>
@ -460,6 +462,11 @@
[% ELSE %]
<option value="report">Reports</option>
[% END %]
[% IF ( module == "bookings" ) %]
<option value="bookings" selected="selected">Bookings</option>
[% ELSE %]
<option value="bookings" >Bookings</option>
[% END %]
</select>
</li>
<li>

View File

@ -267,6 +267,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'),