Bug 15967: Use the email template if the print template does not exist
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 4 Apr 2016 10:31:21 +0000 (11:31 +0100)
committerBrendan A Gallagher <brendan@bywatersolutions.com>
Tue, 5 Apr 2016 15:14:48 +0000 (15:14 +0000)
From commit 581759e985c170db0edb4a895cda641930e5ac11
 Bug 14133: Print notices should be generated with the print
 template

"""
IMPORTANT NOTE: This test plan does not take into account the notices
generated for the staff ("These messages were not sent directly to the
patrons."). However the behavior will also change, the print template
will be used in all cases. Is it what we want?
"""

Yes, it is what we want. But if the print template does not exist, the
notice is not generated, we'd like to get the email template instead.

Test plan:
- Remove the print template for the letter you use for overdues
- Define an overdue rule to send an email
- Remove the email address for the patron which has overdues
- Execute the overdue_notices script
The staff should get an email notice and a print notice (using the
email template) should be generated for the patron

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Brendan A Gallagher <brendan@bywatersolutions.com>
misc/cronjobs/overdue_notices.pl

index 7b5de19..06fec8f 100755 (executable)
@@ -675,6 +675,8 @@ END_SQL
                         # email or sms is requested but not exist, do a print.
                         $effective_mtt = 'print';
                     }
+
+                    my $letter_exists = C4::Letters::getletter( 'circulation', $overdue_rules->{"letter$i"}, $branchcode, $effective_mtt ) ? 1 : 0;
                     my $letter = parse_overdues_letter(
                         {   letter_code     => $overdue_rules->{"letter$i"},
                             borrowernumber  => $borrowernumber,
@@ -685,7 +687,9 @@ END_SQL
                                                 'items.content' => $titles,
                                                 'count'         => $itemcount,
                                                },
-                            message_transport_type => $effective_mtt,
+                            # If there is no template defined for the requested letter
+                            # Fallback on email
+                            message_transport_type => $letter_exists ? $effective_mtt : 'email',
                         }
                     );
                     unless ($letter) {