From 7a120c31eac808708fdf58d09f1917ab915b4658 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 29 Aug 2018 17:19:07 -0400 Subject: [PATCH] LP#1779920 Circ auto-renewal repairs * Remove hard-coded granularity for auto-renewal notification event generation * Moved schema update changes from 950 seed file into schema files. * Added CircIsOpen validator to auto-renewal reactor on the off chance a circ is renewed by the patron in the middle of event processing. * Notification template formatting and language updates, and removed debugging content. Signed-off-by: Bill Erickson Signed-off-by: Cesar Velez Signed-off-by: Galen Charlton --- .../Trigger/Reactor/Circ/AutoRenew.pm | 5 +- Open-ILS/src/sql/Pg/002.schema.config.sql | 3 +- Open-ILS/src/sql/Pg/090.schema.action.sql | 4 +- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 61 +++++++++---------- ...XXX.autorenewals_acp_and_circ_duration.sql | 56 +++++++++-------- 5 files changed, 69 insertions(+), 60 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/Circ/AutoRenew.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/Circ/AutoRenew.pm index 71eeb65883..f06adc85e1 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/Circ/AutoRenew.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/Circ/AutoRenew.pm @@ -75,7 +75,10 @@ sub handler { old_due_date => !$is_renewed ? $_->due_date() : '', ); - $ses->request('open-ils.trigger.event.autocreate', 'autorenewal', $_, $_->circ_lib(), 'system_autorenewal', \%user_data); + # Create the event from the source circ instead of the + # new circ, since the renewal may have failed. + $ses->request('open-ils.trigger.event.autocreate', + 'autorenewal', $_, $_->circ_lib(), undef, \%user_data); } $ses->disconnect; diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 43c190361c..2269cd7780 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -333,7 +333,8 @@ CREATE TABLE config.rule_circ_duration ( extended INTERVAL NOT NULL, normal INTERVAL NOT NULL, shrt INTERVAL NOT NULL, - max_renewals INT NOT NULL + max_renewals INT NOT NULL, + max_auto_renewals INTEGER ); COMMENT ON TABLE config.rule_circ_duration IS $$ Circulation Duration rules diff --git a/Open-ILS/src/sql/Pg/090.schema.action.sql b/Open-ILS/src/sql/Pg/090.schema.action.sql index 2fb3659e6c..4ce492d0ef 100644 --- a/Open-ILS/src/sql/Pg/090.schema.action.sql +++ b/Open-ILS/src/sql/Pg/090.schema.action.sql @@ -147,7 +147,9 @@ CREATE TABLE action.circulation ( ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED, copy_location INT NOT NULL DEFAULT 1 REFERENCES asset.copy_location (id) DEFERRABLE INITIALLY DEFERRED, - checkin_scan_time TIMESTAMP WITH TIME ZONE + checkin_scan_time TIMESTAMP WITH TIME ZONE, + auto_renewal BOOLEAN, + auto_renewal_remaining INTEGER ) INHERITS (money.billable_xact); ALTER TABLE action.circulation ADD PRIMARY KEY (id); ALTER TABLE action.circulation diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index 841222555b..cf51b6007f 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -10293,49 +10293,46 @@ INSERT INTO action_trigger.hook (key,core_type,description) VALUES ( -- AUTORENEWAL Action Trigger definitions and email notification template -ALTER TABLE config.rule_circ_duration -ADD column max_auto_renewals INTEGER; - -ALTER TABLE action.circulation -ADD column auto_renewal BOOLEAN; - -ALTER TABLE action.circulation -ADD column auto_renewal_remaining INTEGER; - INSERT INTO action_trigger.validator values('CircIsAutoRenewable', 'Checks whether the circulation is able to be autorenewed.'); INSERT INTO action_trigger.reactor values('Circ::AutoRenew', 'Auto-Renews a circulation.'); INSERT INTO action_trigger.hook(key, core_type, description) values('autorenewal', 'circ', 'Item was auto-renewed to patron.'); -- AutoRenewer A/T Def: INSERT INTO action_trigger.event_definition(active, owner, name, hook, validator, reactor, delay, max_delay, delay_field, group_field) - values (false, 1, 'Autorenew', 'checkout.due', 'NOOP_True', 'Circ::AutoRenew', '-23 hours'::interval,'-1 minute'::interval, 'due_date', 'usr'); + values (false, 1, 'Autorenew', 'checkout.due', 'CircIsOpen', 'Circ::AutoRenew', '-23 hours'::interval,'-1 minute'::interval, 'due_date', 'usr'); -- AutoRenewal outcome Email notifier A/T Def: INSERT INTO action_trigger.event_definition(active, owner, name, hook, validator, reactor, group_field, template) values (false, 1, 'AutorenewNotify', 'autorenewal', 'NOOP_True', 'SendEmail', 'usr', - $$ - [%- USE date -%] - [%- user = target.0.usr -%] - To: [%- params.recipient_email || user.email %] - From: [%- params.sender_email || default_sender %] - Date: [%- date.format(date.now, '%a, %d %b %Y %T -0000', gmt => 1) %] - Subject: Items Out Auto-Renewal Notification Auto-Submitted: auto-generated - - Dear [% user.family_name %], [% user.first_given_name %] - Your library would like to let you know about your currently borrowed item(s): - - [% FOR circ IN target %] - [%- SET idx = loop.count - 1; SET udata = user_data.$idx -%] - Item# [%+ loop.count -%] - [%- SET cid = circ.target_copy || udata.copy -%] - [%- SET copy_details = helpers.get_copy_bib_basics(cid) +%] - Title: [% copy_details.title %] - Author: [% copy_details.author %] - Due Date: [% date.format(helpers.format_date(circ.due_date), '%Y-%m-%d') %] - Status: [%- IF udata.is_renewed %] Loan Renewed. Now Due: [%- date.format(helpers.format_date(udata.new_due_date), '%Y-%m-%d') %] - [% ELSE %] Not Renewed. Reason: [% udata.reason %] [% END %] +$$ +[%- USE date -%] +[%- user = target.0.usr -%] +To: [%- params.recipient_email || user.email %] +From: [%- params.sender_email || default_sender %] +Date: [%- date.format(date.now, '%a, %d %b %Y %T -0000', gmt => 1) %] +Subject: Items Out Auto-Renewal Notification +Auto-Submitted: auto-generated + +Dear [% user.family_name %], [% user.first_given_name %] +An automatic renewal attempt was made for the following items: + +[% FOR circ IN target %] + [%- SET idx = loop.count - 1; SET udata = user_data.$idx -%] + [%- SET cid = circ.target_copy || udata.copy -%] + [%- SET copy_details = helpers.get_copy_bib_basics(cid) -%] + Item# [% loop.count %] + Title: [% copy_details.title %] + Author: [% copy_details.author %] + [%- IF udata.is_renewed %] + Status: Loan Renewed + New Due Date: [% date.format(helpers.format_date(udata.new_due_date), '%Y-%m-%d') %] + [%- ELSE %] + Status: Not Renewed + Reason: [% udata.reason %] + Due Date: [% date.format(helpers.format_date(circ.due_date), '%Y-%m-%d') %] [% END %] - $$ +[% END %] +$$ ); INSERT INTO action_trigger.environment (event_def, path ) VALUES diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.autorenewals_acp_and_circ_duration.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.autorenewals_acp_and_circ_duration.sql index 9fb38e307f..0bb4a7e8cb 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.autorenewals_acp_and_circ_duration.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.autorenewals_acp_and_circ_duration.sql @@ -16,34 +16,40 @@ BEGIN; -- AutoRenewer A/T Def: INSERT INTO action_trigger.event_definition(active, owner, name, hook, validator, reactor, delay, max_delay, delay_field, group_field) - values (true, 1, 'Autorenew', 'checkout.due', 'NOOP_True', 'Circ::AutoRenew', '-23 hours'::interval,'-1 minute'::interval, 'due_date', 'usr'); + values (false, 1, 'Autorenew', 'checkout.due', 'CircIsOpen', 'Circ::AutoRenew', '-23 hours'::interval,'-1 minute'::interval, 'due_date', 'usr'); -- AutoRenewal outcome Email notifier A/T Def: INSERT INTO action_trigger.event_definition(active, owner, name, hook, validator, reactor, group_field, template) - values (true, 1, 'AutorenewNotify', 'autorenewal', 'NOOP_True', 'SendEmail', 'usr', - $$ - [%- USE date -%] - [%- user = target.0.usr -%] - To: [%- params.recipient_email || user.email %] - From: [%- params.sender_email || default_sender %] - Date: [%- date.format(date.now, '%a, %d %b %Y %T -0000', gmt => 1) %] - Subject: Items Out Auto-Renewal Notification Auto-Submitted: auto-generated - - Dear [% user.family_name %], [% user.first_given_name %] (UserID: [%- user.id +%]) - Your library would like to let you know about your currently borrowed item(s): - - [% FOR circ IN target %] - [%- SET idx = loop.count - 1; SET udata = user_data.$idx -%] - Item# [%+ loop.count -%] (circ_id: [%- circ.id -%]) - [%- SET cid = circ.target_copy || udata.copy -%] - [%- SET copy_details = helpers.get_copy_bib_basics(cid) +%] - Title: [% copy_details.title %] - Author: [% copy_details.author %] - Due Date: [% date.format(helpers.format_date(circ.due_date), '%Y-%m-%d') %] - Status: [%- IF udata.is_renewed %] Loan Renewed. Now Due: [%- date.format(helpers.format_date(udata.new_due_date), '%Y-%m-%d') %] - [% ELSE %] Not Renewed. Reason: [% udata.reason %] [% END %] - [% END %] - $$ + values (false, 1, 'AutorenewNotify', 'autorenewal', 'NOOP_True', 'SendEmail', 'usr', +$$ +[%- USE date -%] +[%- user = target.0.usr -%] +To: [%- params.recipient_email || user.email %] +From: [%- params.sender_email || default_sender %] +Date: [%- date.format(date.now, '%a, %d %b %Y %T -0000', gmt => 1) %] +Subject: Items Out Auto-Renewal Notification +Auto-Submitted: auto-generated + +Dear [% user.family_name %], [% user.first_given_name %] +An automatic renewal attempt was made for the following items: + +[% FOR circ IN target %] + [%- SET idx = loop.count - 1; SET udata = user_data.$idx -%] + [%- SET cid = circ.target_copy || udata.copy -%] + [%- SET copy_details = helpers.get_copy_bib_basics(cid) -%] + Item# [% loop.count %] + Title: [% copy_details.title %] + Author: [% copy_details.author %] + [%- IF udata.is_renewed %] + Status: Loan Renewed + New Due Date: [% date.format(helpers.format_date(udata.new_due_date), '%Y-%m-%d') %] + [%- ELSE %] + Status: Not Renewed + Reason: [% udata.reason %] + Due Date: [% date.format(helpers.format_date(circ.due_date), '%Y-%m-%d') %] + [% END %] +[% END %] +$$ ); INSERT INTO action_trigger.environment (event_def, path ) VALUES -- 2.43.2