Bug 37204: Add a booking has changed notice to update a patron should a booking be updated

This is a first draft. When reading your initial statement again I'm asking myself whether
a changed itemnumber is relevant to the patron.
The way I see it, the relevant fields are:
- pickup_library_id
- start_date
- end_date

But maybe I'm not seeing it.

To test:
1) Apply the patch
2) Make an item bookable
3) Add a booking for a given patron
4) Check the patron notices tab, should not contain any notices
5) Change either start date, end date or pickup library and save
6) Check the patron notices tab, should contain a notice with the updated details
7) Run the tests under t/db_dependent/Koha/Booking.t
8) Sign off

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-08-28 13:22:00 +02:00 committed by Katrin Fischer
parent 650d419a74
commit d2c8bbd7cb
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
3 changed files with 138 additions and 2 deletions

View File

@ -27,6 +27,8 @@ use Koha::Libraries;
use C4::Letters;
use List::Util qw(any);
use base qw(Koha::Object);
=head1 NAME
@ -149,7 +151,35 @@ sub store {
$self->_assign_item_for_booking;
}
$self = $self->SUPER::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) )
{
my $patron = $self->patron;
my $pickup_library = $self->pickup_library;
my $letter = C4::Letters::GetPreparedLetter(
module => 'bookings',
letter_code => 'BOOKING_MODIFICATION',
message_transport_type => 'email',
branchcode => $pickup_library->branchcode,
lang => $patron->lang,
objects => { booking => $self },
);
if ($letter) {
C4::Letters::EnqueueLetter(
{
letter => $letter,
borrowernumber => $patron->borrowernumber,
message_transport_type => 'email',
}
);
}
}
}
);

View File

@ -66,6 +66,30 @@ tables:
- "<br>"
- "[% booking.pickup_library.branchname %]"
- module: bookings
code: BOOKING_MODIFICATION
branchcode: ""
name: "Booking modification notice"
is_html: 1
title: "A library booking was modified"
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 modified.<br>"
- "<br>"
- "The new 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 => 13;
plan tests => 14;
$schema->storage->txn_begin;
my $patron = $builder->build_object( { class => "Koha::Patrons" } );
@ -322,6 +322,88 @@ subtest 'store() tests' => sub {
# ✓ Any (1) |--|
};
subtest 'notice trigger' => sub {
plan tests => 3;
my $original_notices_count = Koha::Notice::Messages->search(
{
letter_code => 'BOOKING_MODIFICATION',
borrowernumber => $patron->borrowernumber,
}
)->count;
$start_1 = dt_from_string->add( months => 1 )->truncate( to => 'day' );
$end_1 = $start_1->clone()->add( days => 1 );
# Use datetime formatting so that we don't get DateTime objects
$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;
my $post_notices_count = Koha::Notice::Messages->search(
{
letter_code => 'BOOKING_MODIFICATION',
borrowernumber => $patron->borrowernumber,
}
)->count;
is(
$post_notices_count,
$original_notices_count,
'Koha::Booking->store should not have enqueued a BOOKING_MODIFICATION email for a new booking'
);
my $item_4 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 1 } );
$booking->update(
{
item_id => $item_4->itemnumber,
}
);
$post_notices_count = Koha::Notice::Messages->search(
{
letter_code => 'BOOKING_MODIFICATION',
borrowernumber => $patron->borrowernumber,
}
)->count;
is(
$post_notices_count,
$original_notices_count,
'Koha::Booking->store should not have enqueued a BOOKING_MODIFICATION email for a booking with modified item_id'
);
$booking->update(
{
start_date => $start_1->clone()->add( days => 1 )->datetime(q{ }),
}
);
# start_date, end_date and pickup_library_id should behave identical
$post_notices_count = Koha::Notice::Messages->search(
{
letter_code => 'BOOKING_MODIFICATION',
borrowernumber => $patron->borrowernumber,
}
)->count;
is(
$post_notices_count,
$original_notices_count + 1,
'Koha::Booking->store should have enqueued a BOOKING_MODIFICATION email for a booking with modified start_date'
);
$booking->update(
{
end_date => $end_1->clone()->add( days => 1 )->datetime(q{ }),
}
);
};
$schema->storage->txn_rollback;
};