From 9148119695b65f83a306dc3896acbda4e338dbb1 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 26 Jun 2024 15:27:14 +0100 Subject: [PATCH] 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. --- Koha/Booking.pm | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/Koha/Booking.pm b/Koha/Booking.pm index 0d0d1fc8aac..e5297d8d17b 100644 --- a/Koha/Booking.pm +++ b/Koha/Booking.pm @@ -246,43 +246,36 @@ sub to_api_mapping { =head3 delete -$booking->delete(); + my $deleted = $booking->delete(); =cut sub delete { - my ( $self ) = @_; + 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 $patron = $self->patron; + my $pickup_library = $self->pickup_library; 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, + module => 'bookings', + letter_code => 'BOOKING_CANCELLATION', + 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', } ); + } - if ($letter) { - C4::Letters::EnqueueLetter( - { - letter => $letter, - borrowernumber => $patron->borrowernumber, - message_transport_type => 'email', - } - ); - } + my $deleted = $self->SUPER::delete($self); return $deleted; } -- 2.45.2