From cbea412e98ecbe85e206bbad81627b078c53a40f Mon Sep 17 00:00:00 2001 From: William Lavoie Date: Tue, 15 Apr 2025 16:20:19 -0400 Subject: [PATCH] Bug 39646: Send overdue notice to guarantor when guarantee has no email Test plan: 1. Have a patron with no email address and an overdue item. 2. Add a guarantor to this patron. The guarantor must have an email address. 3. Run the script overdue_notices.pl. 4. On the staff interface, go to the guarantee patron > Notices. 5. Notice that only a print notice has been created. 6. Apply the patch. 7. Repeat steps 3 and 4. 8. Notice that an email message has been created. 9. Run the script process_message_queue.pl. 10. Verify that the email has been sent to the guarantor's address. --- misc/cronjobs/overdue_notices.pl | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl index 7d3fd8796d..22b3c80dd2 100755 --- a/misc/cronjobs/overdue_notices.pl +++ b/misc/cronjobs/overdue_notices.pl @@ -722,10 +722,28 @@ END_SQL unless @message_transport_types; my $print_sent = 0; # A print notice is not yet sent for this patron + + my $guarantor_has_address; + if ( C4::Context->preference('RedirectGuaranteeEmail') && $patron ) { + + # Get guarantor addresses + my $guarantor_relationships = $patron->guarantor_relationships; + my @guarantors = $guarantor_relationships->guarantors->as_list; + foreach my $guarantor (@guarantors) { + my $address = $guarantor->notice_email_address; + if ($address) { + $guarantor_has_address = 1; + } + } + } + if ($guarantor_has_address || scalar @emails_to_use) { + $print_sent = 1; + } + for my $mtt (@message_transport_types) { next if $mtt eq 'itiva'; my $effective_mtt = $mtt; - if ( ( $mtt eq 'email' and not scalar @emails_to_use ) + if ( ( $mtt eq 'email' and not scalar @emails_to_use and not $guarantor_has_address ) or ( $mtt eq 'sms' and not $data->{smsalertnumber} ) ) { # email or sms is requested but not exist, do a print. @@ -808,7 +826,7 @@ END_SQL } ); } else { - if ( ( $mtt eq 'email' and not scalar @emails_to_use ) + if ( ( $mtt eq 'email' and not scalar @emails_to_use and not $guarantor_has_address) or ( $mtt eq 'sms' and not $data->{smsalertnumber} ) ) { push @output_chunks, -- 2.43.0