From 3db1985149770ec27e5760c36dc10b396f1dd03b 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. Signed-off-by: David Nind Signed-off-by: Owen Leonard Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- Koha/Booking.pm | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/Koha/Booking.pm b/Koha/Booking.pm index 0d0d1fc8aa..e5297d8d17 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.39.5