Bug 42723: Purchase suggestion 500 when EmailPurchaseSuggestions is set to BranchEmailAddress

Testing plan:
- Set EmailPurchaseSuggestions to BranchEmailAddress
- Go to create suggestion on the staff side /suggestion/suggestion.pl?op=add_form
- Create a suggestion with Library: Any
- 500 error: inbound_email_address is not a method of undef
- Apply patch & repeat
- Suggestion created

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 33a8dc5d6f)
Signed-off-by: Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com>
Signed-off-by: Wainui Witika-Park <wainuiwitikapark@catalyst.net.nz>
This commit is contained in:
Eric Phetteplace 2026-05-29 18:57:46 -07:00 committed by Wainui Witika-Park
parent 88a131b777
commit f699bb4c50
No known key found for this signature in database
GPG Key ID: 2D0A6AB5DAF1B78D
2 changed files with 25 additions and 6 deletions

View File

@ -96,8 +96,12 @@ sub store {
my $toaddress;
if ( $emailpurchasesuggestions eq "BranchEmailAddress" ) {
# can be undef for branch=any suggestions
my $library = $result->library;
if ( $library && $library->inbound_email_address ) {
$toaddress = $library->inbound_email_address;
}
} elsif ( $emailpurchasesuggestions eq "KohaAdminEmailAddress" ) {
$toaddress = C4::Context->preference('ReplytoDefault')
|| C4::Context->preference('KohaAdminEmailAddress');

View File

@ -600,7 +600,7 @@ subtest 'DelSuggestionsOlderThan' => sub {
};
subtest 'EmailPurchaseSuggestions' => sub {
plan tests => 11;
plan tests => 13;
$dbh->do(q|DELETE FROM message_queue|);
@ -661,6 +661,21 @@ subtest 'EmailPurchaseSuggestions' => sub {
'BranchEmailAddress uses branchreplyto in preference to branchemail when set'
);
my $branchless_suggestion = { %{$my_suggestion}, branchcode => undef };
t::lib::Mocks::mock_preference( "ReplytoDefault", undef );
# must eval to test itself dying, then check $@ for error
eval { Koha::Suggestion->new($branchless_suggestion)->store; };
is( $@, '', 'BranchEmailAddress does not die when suggestion has no library branch' );
$newsuggestions_messages = C4::Letters::GetQueuedMessages( { letter_code => 'NEW_SUGGESTION' } );
my $message_branchless =
C4::Letters::GetMessage( $newsuggestions_messages->[4]->{message_id} );
is(
$message_branchless->{to_address}, undef,
'BranchEmailAddress sets no to_address when suggestion has no branch'
);
# EmailPurchaseSuggestions set to KohaAdminEmailAddress
t::lib::Mocks::mock_preference(
"EmailPurchaseSuggestions",
@ -675,13 +690,13 @@ subtest 'EmailPurchaseSuggestions' => sub {
$newsuggestions_messages = C4::Letters::GetQueuedMessages( { letter_code => 'NEW_SUGGESTION' } );
my $message5 =
C4::Letters::GetMessage( $newsuggestions_messages->[4]->{message_id} );
C4::Letters::GetMessage( $newsuggestions_messages->[5]->{message_id} );
is(
$message5->{to_address},
'noreply@hosting.com', 'KohaAdminEmailAddress uses KohaAdminEmailAddress when ReplytoDefault is not set'
);
my $message6 =
C4::Letters::GetMessage( $newsuggestions_messages->[5]->{message_id} );
C4::Letters::GetMessage( $newsuggestions_messages->[6]->{message_id} );
is(
$message6->{to_address},
'library@b.c', 'KohaAdminEmailAddress uses ReplytoDefualt when ReplytoDefault is set'
@ -707,7 +722,7 @@ subtest 'EmailPurchaseSuggestions' => sub {
$newsuggestions_messages = C4::Letters::GetQueuedMessages( { letter_code => 'NEW_SUGGESTION' } );
my $message7 =
C4::Letters::GetMessage( $newsuggestions_messages->[6]->{message_id} );
C4::Letters::GetMessage( $newsuggestions_messages->[7]->{message_id} );
is(
$message7->{to_address},
'noreply@hosting.com',
@ -715,14 +730,14 @@ subtest 'EmailPurchaseSuggestions' => sub {
);
my $message8 =
C4::Letters::GetMessage( $newsuggestions_messages->[7]->{message_id} );
C4::Letters::GetMessage( $newsuggestions_messages->[8]->{message_id} );
is(
$message8->{to_address},
'library@b.c', 'EmailAddressForSuggestions uses ReplytoDefault when EmailAddressForSuggestions is not set'
);
my $message9 =
C4::Letters::GetMessage( $newsuggestions_messages->[8]->{message_id} );
C4::Letters::GetMessage( $newsuggestions_messages->[9]->{message_id} );
is(
$message9->{to_address},
'suggestions@b.c', 'EmailAddressForSuggestions uses EmailAddressForSuggestions when set'