Bug 37803: Add patron notification when a new booking has been created successfully

To test:
1) Apply the patch
2) Include the sample notice, e.g. run 'reset_all' on ktd
3) Create a booking
4) Look into the borrower notifications
5) Confirm the notice has been generated
6) Run t/db_dependent/Koha/Booking.t

Signed-off-by: LEBSimonsen <simonsen@bz-sh.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Sponsored-by: Büchereizentrale Schleswig-Holstein <https://www.bz-sh.de/>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Paul Derscheid 2024-09-02 12:42:11 +02:00 committed by Katrin Fischer
parent ffd60727f1
commit 0146baf294
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
3 changed files with 121 additions and 26 deletions

View File

@ -153,35 +153,55 @@ sub store {
my $is_modification = $self->in_storage;
my $old_booking = $self->get_from_storage;
if ( $self =
$self->SUPER::store
and $is_modification
and any { $old_booking->$_ ne $self->$_ } qw(pickup_library_id start_date end_date) )
{
if ( $self = $self->SUPER::store ) {
my $patron = $self->patron;
my $pickup_library = $self->pickup_library;
my $branch = C4::Context->userenv->{'branch'};
my $letter = C4::Letters::GetPreparedLetter(
module => 'bookings',
letter_code => 'BOOKING_MODIFICATION',
message_transport_type => 'email',
branchcode => $branch,
lang => $patron->lang,
objects => {
old_booking => $old_booking,
booking => $self
},
);
if ($letter) {
C4::Letters::EnqueueLetter(
{
letter => $letter,
borrowernumber => $patron->borrowernumber,
message_transport_type => 'email',
}
if ( $is_modification
and any { $old_booking->$_ ne $self->$_ } qw(pickup_library_id start_date end_date) )
{
my $letter = C4::Letters::GetPreparedLetter(
module => 'bookings',
letter_code => 'BOOKING_MODIFICATION',
message_transport_type => 'email',
branchcode => $branch,
lang => $patron->lang,
objects => {
old_booking => $old_booking,
booking => $self
},
);
if ($letter) {
C4::Letters::EnqueueLetter(
{
letter => $letter,
borrowernumber => $patron->borrowernumber,
message_transport_type => 'email',
}
);
}
} elsif ( !$is_modification ) {
my $letter = C4::Letters::GetPreparedLetter(
module => 'bookings',
letter_code => 'BOOKING_CONFIRMATION',
message_transport_type => 'email',
branchcode => $branch,
lang => $patron->lang,
objects => { booking => $self },
);
if ($letter) {
C4::Letters::EnqueueLetter(
{
letter => $letter,
borrowernumber => $patron->borrowernumber,
message_transport_type => 'email',
}
);
}
}
}
}

View File

@ -90,6 +90,30 @@ tables:
- "<br>"
- "[% booking.pickup_library.branchname %]"
- module: bookings
code: BOOKING_CONFIRMATION
branchcode: ""
name: "Booking confirmation notice"
is_html: 1
title: "A library booking was confirmed"
message_transport_type: email
lang: default
content:
- "[%- PROCESS 'html_helpers.inc' -%]"
- "[%- USE KohaDates -%]"
- "Dear [%- INCLUDE 'patron-title.inc' patron => booking.patron -%],<br>"
- "<br>"
- "Your booking of [%- INCLUDE 'biblio-title.inc' biblio=booking.biblio link = 0 -%] has been confirmed.<br>"
- "<br>"
- "The details are:<br>"
- "<br>"
- "Dates: [% booking.start_date | $KohaDates %] to [% booking.end_date | $KohaDates %]<br>"
- "<br>"
- "Pickup at: [% booking.pickup_library.branchname %]<br>"
- "Kind regards<br>"
- "<br>"
- "[% booking.pickup_library.branchname %]"
- module: catalogue
code: TICKET_ACKNOWLEDGE
branchcode: ""

View File

@ -123,7 +123,7 @@ subtest 'Relation accessor tests' => sub {
};
subtest 'store() tests' => sub {
plan tests => 14;
plan tests => 15;
$schema->storage->txn_begin;
my $patron = $builder->build_object( { class => "Koha::Patrons" } );
@ -323,7 +323,7 @@ subtest 'store() tests' => sub {
# ✓ Any (1) |--|
};
subtest 'notice trigger' => sub {
subtest 'modification notice trigger' => sub {
plan tests => 3;
my $original_notices_count = Koha::Notice::Messages->search(
@ -405,6 +405,57 @@ subtest 'store() tests' => sub {
);
};
subtest 'confirmation notice trigger' => sub {
plan tests => 2;
my $original_notices_count = Koha::Notice::Messages->search(
{
letter_code => 'BOOKING_CONFIRMATION',
borrowernumber => $patron->borrowernumber,
}
)->count;
# Reuse previous booking to produce a clash
eval { $booking = Koha::Booking->new( $booking->unblessed )->store };
my $post_notices_count = Koha::Notice::Messages->search(
{
letter_code => 'BOOKING_CONFIRMATION',
borrowernumber => $patron->borrowernumber,
}
)->count;
is(
$post_notices_count,
$original_notices_count,
'Koha::Booking->store should not have enqueued a BOOKING_CONFIRMATION email if booking creation fails'
);
$start_1 = dt_from_string->add( months => 1 )->truncate( to => 'day' );
$end_1 = $start_1->clone()->add( days => 1 );
$booking = Koha::Booking->new(
{
patron_id => $patron->borrowernumber,
biblio_id => $biblio->biblionumber,
pickup_library_id => $item_2->homebranch,
start_date => $start_1->datetime(q{ }),
end_date => $end_1->datetime(q{ }),
}
)->store;
$post_notices_count = Koha::Notice::Messages->search(
{
letter_code => 'BOOKING_CONFIRMATION',
borrowernumber => $patron->borrowernumber,
}
)->count;
is(
$post_notices_count,
$original_notices_count + 1,
'Koha::Booking->store should have enqueued a BOOKING_CONFIRMATION email for a new booking'
);
};
$schema->storage->txn_rollback;
};