Bug 18532: Add individual issues to digest notice and hide auto_renewals messaging preference when not needed

This patch enhances auto_renewals message, removes auto_renewals messaging preference when AutoRenewalNotices is not set to ‘preferences’ and uses that preference to send notices in automatic_renewals.pl script.

To test:

1. Apply patches
2. updatedatabase
3. make sure automatic renewals are allowed in circ rules, have a positive number of allowed renewals and a positive number for renewal period
4. Check AutoRenewalNotices preference
SUCCESS => AutoRenewalNotices has the value ‘cron’ (means that It keeps the usual behaviour)
5. Checkout two items for a patron, and set them as automatic renewal and set due date as your current yesterday
6. perl misc/cronjobs/automatic_renewals.pl -c -v
SUCCESS => items were renewed, but there is no message in message_queue table in mysql
7. Repeat step 5
8. perl misc/cronjobs/automatic_renewals.pl -c -s -v
SUCCESS => items were renewed, and there is one message per item in message_queue table in mysql
9. Change AutoRenewalNotices to ‘never’
10. Repeat step 5
11. perl misc/cronjobs/automatic_renewals.pl -c -s -v
SUCCESS => items were renewed, but there is no message in message_queue table in mysql, even with the -s switch
12. Check any patron’s category, and any detail page in staff or OPAC interface, and in any of them you should find Auto Renewals messaging preference
13. Change AutoRenewalNotices to ‘preferences’
14. Repeat step 12, but this time all of them shows the Auto Renewals messaging preference.
15. Repeat step 5 with a patron that has no messaging preference setted
16. perl misc/cronjobs/automatic_renewals.pl -c -s -v
SUCCESS => items were renewed, but there is no message in message_queue table in mysql, because patron didn’t choose to receive messages
17. Grab a category and modify auto renewals messaging preferences, and save
18. Create a new patron from that category.
SUCCESS => created patron has the same messaging preference for auto renewals
19. Grab that patron and change auto renewals messaging preference to email but not digest
20. Repeat step 5 for that last patron.
21. perl misc/cronjobs/automatic_renewals.pl -c -v
SUCCESS => Items were renewed, and there is a message for each item in message_queue table in mysql.
22. Change auto renewals messaging preference from the same patron and set to email and digest.
23. Repeat step 5.
24. perl misc/cronjobs/automatic_renewals.pl -c -v
SUCCESS => items where renewed, and now there is only one message in message_queue table with the details of both renewed items.
25. Check that any changes to a patron’s auto renewals messaging preference in staff is reflected in OPAC, and the other way arround too.
26. Sign off

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Nick Clemens 2020-05-14 13:21:22 +00:00 committed by Jonathan Druart
parent 14896e2032
commit 39faff6606
5 changed files with 38 additions and 17 deletions

View file

@ -4,11 +4,19 @@ if( CheckVersion( $DBversion ) ) {
$dbh->do( qq{
INSERT IGNORE INTO letter (module, code, name, title, content, message_transport_type) VALUES ('circulation', 'AUTO_RENEWALS_DGST', 'notification on auto renewing', 'Auto renewals (Digest)',
"Dear [% borrower.firstname %] [% borrower.surname %],
[% IF checkout.auto_renew_errors %]
There were [% checkout.auto_renew_errors %] items that where not correctly renewed.
[% IF error %]
There were [% error %] items that were not correctly renewed.
[% END %]
[% IF success %]
There were [% success %] items that where correctly renewed.
[% END %]
[% FOREACH checkout IN checkouts %]
[% checkout.item.biblio.title %] : [% checkout.item.barcode %]
[% IF !checkout.auto_renew_error %]
was renewed until [% checkout.date_due %]
[% ELSE %]
was not renewed with error: [% checkout.auto_renew_error %]
[% END %]
[% IF checkout.auto_renew %]
There were [% checkout.auto_renew %] items that where correctly renewed.
[% END %]
", 'email');
});

View file

@ -427,11 +427,20 @@ This item must be renewed at the library.
The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]
[% END %]", 'email');
INSERT INTO letter (module, code, name, title, content, message_transport_type) VALUES ('circulation', 'AUTO_RENEWALS_DGST', 'Notification on auto renewing', 'Auto renewals (Digest)',
INSERT IGNORE INTO letter (module, code, name, title, content, message_transport_type) VALUES ('circulation', 'AUTO_RENEWALS_DGST', 'Notification on auto renewing', 'Auto renewals (Digest)',
"Dear [% borrower.firstname %] [% borrower.surname %],
[% IF <<error>> %]
There were <<error>> items that where not correctly renewed.
[% IF error %]
There were [% error %] items that were not correctly renewed.
[% END %]
[% IF <<success>> %]
There were <<success>> items that where correctly renewed.
[% END %]", 'email');
[% IF success %]
There were [% success %] items that where correctly renewed.
[% END %]
[% FOREACH checkout IN checkouts %]
[% checkout.item.biblio.title %] : [% checkout.item.barcode %]
[% IF !checkout.auto_renew_error %]
was renewed until [% checkout.date_due | $KohaDates %]
[% ELSE %]
was not renewed with error: [% checkout.auto_renew_error %]
[% END %]
[% END %]
", 'email');

View file

@ -14,10 +14,10 @@
</tr>
[% FOREACH messaging_preference IN messaging_preferences %]
[% NEXT IF !Koha.Preference( 'ILLModule' ) && messaging_preference.message_name.match('^Ill_') %]
[% NEXT IF messaging_preference.Auto_Renewals && Koha.Preference('AutoRenewalNotices') != 'preferences' %]
<tr>
<td>[% IF ( messaging_preference.Item_Due ) %]Item due
[% ELSIF ( messaging_preference.Advance_Notice ) %]Advance notice
[% ELSIF ( messaging_preference.Upcoming_Events ) %]Upcoming events
[% ELSIF ( messaging_preference.Hold_Filled ) %]Hold filled
[% ELSIF ( messaging_preference.Item_Check_in ) %]Item check-in
[% ELSIF ( messaging_preference.Item_Checkout ) %]
@ -28,7 +28,6 @@
[% END %]
[% ELSIF ( messaging_preference.Ill_ready ) %]Interlibrary loan ready
[% ELSIF ( messaging_preference.Ill_unavailable ) %]Interlibrary loan unavailable
[% ELSIF ( messaging_preference.Auto_Renewals ) %]Auto renewals
[% ELSE %]Unknown [% END %]</td>
[% IF ( messaging_preference.takes_days ) %]
<td>

View file

@ -56,6 +56,7 @@
<tbody>
[% FOREACH messaging_preference IN messaging_preferences %]
[% NEXT IF !Koha.Preference( 'ILLModule' ) && messaging_preference.message_name.match('^Ill_') %]
[% NEXT IF messaging_preference.Auto_Renewals && Koha.Preference('AutoRenewalNotices') != 'preferences' %]
<tr>
<td>[% IF ( messaging_preference.Item_Due ) %]Item due
[% ELSIF ( messaging_preference.Advance_Notice ) %]Advance notice
@ -69,7 +70,6 @@
[% END %]
[% ELSIF ( messaging_preference.Ill_ready ) %]Interlibrary loan ready
[% ELSIF ( messaging_preference.Ill_unavailable ) %]Interlibrary loan unavailable
[% ELSIF ( messaging_preference.Auto_Renewals ) %]Auto renewals
[% ELSE %]Unknown [% END %]</td>
[% IF ( messaging_preference.takes_days ) %]
<td><select class="input-mini" name="[% messaging_preference.message_attribute_id | html %]-DAYS">

View file

@ -98,8 +98,8 @@ GetOptions(
pod2usage(0) if $help;
my $send_notices_pref = C4::Context->preference('AutoRenewalNotices')
if ( $send_notices_pref = 'cron' ) {
my $send_notices_pref = C4::Context->preference('AutoRenewalNotices');
if ( $send_notices_pref eq 'cron' ) {
warn <<'END_WARN';
The "AutoRenewalNotices" syspref is set to 'Follow the cron switch'.
@ -144,6 +144,8 @@ while ( my $auto_renew = $auto_renews->next ) {
$borrower_preferences = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $auto_renew->borrowernumber,
message_name => 'auto_renewals' } ) if $send_notices_pref eq 'preferences';
$send_notices = 1 if !$send_notices && $send_notices_pref eq 'preferences' && $borrower_preferences && $borrower_preferences->{transports} && $borrower_preferences->{transports}->{email};
# CanBookBeRenewed returns 'auto_renew' when the renewal should be done by this script
my ( $ok, $error ) = CanBookBeRenewed( $auto_renew->borrowernumber, $auto_renew->itemnumber, undef, 1 );
if ( $error eq 'auto_renew' ) {
@ -155,7 +157,7 @@ while ( my $auto_renew = $auto_renews->next ) {
my $date_due = AddRenewal( $auto_renew->borrowernumber, $auto_renew->itemnumber, $auto_renew->branchcode, undef, undef, undef, 0 );
$auto_renew->auto_renew_error(undef)->store;
}
push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew unless $borrower_preferences && (!$borrower_preferences->{transports} || !$borrower_preferences->{transports}->{email} || $borrower_preferences->{'wants_digest'});
push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew unless $send_notices_pref ne 'cron' && (!$borrower_preferences || !$borrower_preferences->{transports} || !$borrower_preferences->{transports}->{email} || $borrower_preferences->{'wants_digest'});
} elsif ( $error eq 'too_many'
or $error eq 'on_reserve'
or $error eq 'restriction'
@ -173,7 +175,7 @@ while ( my $auto_renew = $auto_renews->next ) {
if ( not $auto_renew->auto_renew_error or $error ne $auto_renew->auto_renew_error ) {
$auto_renew->auto_renew_error($error)->store if $confirm;
push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew
if $error ne 'auto_too_soon' && (!$borrower_preferences || ($borrower_preferences->{transports} && $borrower_preferences->{transports}->{email} && !$borrower_preferences->{'wants_digest'})); # Do not notify if it's too soon
if $error ne 'auto_too_soon' && ($send_notices_pref eq 'cron' || ($borrower_preferences && $borrower_preferences->{transports} && $borrower_preferences->{transports}->{email} && !$borrower_preferences->{'wants_digest'})); # Do not notify if it's too soon
}
}
@ -182,9 +184,11 @@ while ( my $auto_renew = $auto_renews->next ) {
if ($digest_per_branch) {
$renew_digest->{ $auto_renew->branchcode }->{ $auto_renew->borrowernumber }->{success}++ if $error eq 'auto_renew';
$renew_digest->{ $auto_renew->branchcode }->{ $auto_renew->borrowernumber }->{error}++ unless $error eq 'auto_renew' || $error == 'auto_too_soon' ;
push @{$renew_digest->{ $auto_renew->branchcode }->{ $auto_renew->borrowernumber }->{issues}}, $auto_renew->itemnumber;
} else {
$renew_digest->{ $auto_renew->borrowernumber }->{success} ++ if $error eq 'auto_renew';
$renew_digest->{ $auto_renew->borrowernumber }->{error}++ unless $error eq 'auto_renew' || $error eq 'auto_too_soon' ;
push @{$renew_digest->{ $auto_renew->borrowernumber }->{issues}}, $auto_renew->itemnumber;
}
}
@ -293,6 +297,7 @@ sub send_digests {
error => $digest->{error}||0,
success => $digest->{success}||0,
},
loops => { issues => \@{$digest->{issues}} },
tables => {
borrowers => $patron->borrowernumber,
},