From a7408bbf4ca1232b2ff726c1212f532db449dda1 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 16 Oct 2024 16:45:18 +0100 Subject: [PATCH] Bug 37204: (QA follow-up) Consistently pick notice library We should use the notice from the library that initiated the action that triggered the notice. This should be available to us always in the userenv. Signed-off-by: Martin Renvoize --- Koha/Booking.pm | 6 ++++-- t/db_dependent/Koha/Booking.t | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Koha/Booking.pm b/Koha/Booking.pm index f3376af918d..c849c07e9ec 100644 --- a/Koha/Booking.pm +++ b/Koha/Booking.pm @@ -160,12 +160,13 @@ sub 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 => $pickup_library->branchcode, + branchcode => $branch, lang => $patron->lang, objects => { old_booking => $old_booking, @@ -286,6 +287,7 @@ sub to_api_mapping { sub delete { my ($self) = @_; + my $branch = C4::Context->userenv->{'branch'}; my $patron = $self->patron; my $pickup_library = $self->pickup_library; @@ -293,7 +295,7 @@ sub delete { module => 'bookings', letter_code => 'BOOKING_CANCELLATION', message_transport_type => 'email', - branchcode => $pickup_library->branchcode, + branchcode => $branch, lang => $patron->lang, objects => { booking => $self } ); diff --git a/t/db_dependent/Koha/Booking.t b/t/db_dependent/Koha/Booking.t index 9eef67069d5..cfb9764a6eb 100755 --- a/t/db_dependent/Koha/Booking.t +++ b/t/db_dependent/Koha/Booking.t @@ -126,7 +126,8 @@ subtest 'store() tests' => sub { plan tests => 14; $schema->storage->txn_begin; - my $patron = $builder->build_object( { class => "Koha::Patrons" } ); + my $patron = $builder->build_object( { class => "Koha::Patrons" } ); + t::lib::Mocks::mock_userenv( { patron => $patron } ); my $biblio = $builder->build_sample_biblio(); my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); my $start_0 = dt_from_string->subtract( days => 2 )->truncate( to => 'day' ); @@ -412,7 +413,8 @@ subtest 'delete() tests' => sub { $schema->storage->txn_begin; - my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + t::lib::Mocks::mock_userenv( { patron => $patron } ); my $biblio = $builder->build_sample_biblio; my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); my $start_0 = dt_from_string->subtract( days => 2 )->truncate( to => 'day' ); -- 2.47.0