From 8228c2165fab8d06a8585723952d470d5b096e19 Mon Sep 17 00:00:00 2001 From: Michele Morgan Date: Wed, 15 Mar 2017 16:31:06 -0400 Subject: [PATCH] LP#1427392 - Allow deletion of Hard Due Date Values. Also, don't update hard due dates to ceiling dates that have passed. Fixes two related issues with hard due dates. - Exposes the selector in the Hard Due Date Values interface so past entries that are no longer valid can be deleted via the client. - Prevents the current ceiling date from being updated to a past date based on an old hard due date value. Testing plan: To reproduce the issue: - Create a Hard Due Date with a Current Ceiling Date in the future - Create an associated Hard Due Date Value with an active date earlier than the current date and a ceiling date earlier than the current date. - Run the hard due date updater Note that: - The Current Ceiling Date is updated to an earlier date based on the Hard Due Date Value entry. - It is not possible to select and delete the Hard Due Date Value entry. Apply the patch and retest Note that: - The Current Ceiling Date has not been updated to the past date. - Past Hard Due Date Values can now be selected and deleted. Signed-off-by: Michele Morgan Signed-off-by: Ben Shum --- Open-ILS/src/sql/Pg/002.schema.config.sql | 3 ++- ...nfig_update_hard_due_dates_ceiling_date_fix.sql | 29 ++++++++++++++++++++++ .../conify/global/config/hard_due_date_values.tt2 | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/xxxx.function.config_update_hard_due_dates_ceiling_date_fix.sql diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 97ef039fbc..c74e22388e 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -340,7 +340,8 @@ BEGIN UPDATE config.hard_due_date SET ceiling_date = temp_value.ceiling_date WHERE id = temp_value.hard_due_date - AND ceiling_date <> temp_value.ceiling_date; -- Time is equal if we've already updated the chdd + AND ceiling_date <> temp_value.ceiling_date -- Time is equal if we've already updated the chdd + AND temp_value.ceiling_date >= NOW(); -- Don't update ceiling dates to the past IF FOUND THEN updated := updated + 1; diff --git a/Open-ILS/src/sql/Pg/upgrade/xxxx.function.config_update_hard_due_dates_ceiling_date_fix.sql b/Open-ILS/src/sql/Pg/upgrade/xxxx.function.config_update_hard_due_dates_ceiling_date_fix.sql new file mode 100644 index 0000000000..33ec9e3747 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/xxxx.function.config_update_hard_due_dates_ceiling_date_fix.sql @@ -0,0 +1,29 @@ +BEGIN; + +CREATE OR REPLACE FUNCTION config.update_hard_due_dates () RETURNS INT AS $func$ +DECLARE + temp_value config.hard_due_date_values%ROWTYPE; + updated INT := 0; +BEGIN + FOR temp_value IN + SELECT DISTINCT ON (hard_due_date) * + FROM config.hard_due_date_values + WHERE active_date <= NOW() -- We've passed (or are at) the rollover time + ORDER BY hard_due_date, active_date DESC -- Latest (nearest to us) active time + LOOP + UPDATE config.hard_due_date + SET ceiling_date = temp_value.ceiling_date + WHERE id = temp_value.hard_due_date + AND ceiling_date <> temp_value.ceiling_date -- Time is equal if we've already updated the chdd + AND temp_value.ceiling_date >= NOW(); -- Don't update ceiling dates to the past + + IF FOUND THEN + updated := updated + 1; + END IF; + END LOOP; + + RETURN updated; +END; +$func$ LANGUAGE plpgsql; + +COMMIT; diff --git a/Open-ILS/src/templates/conify/global/config/hard_due_date_values.tt2 b/Open-ILS/src/templates/conify/global/config/hard_due_date_values.tt2 index b1ba77cbfb..91fbe2e7c2 100644 --- a/Open-ILS/src/templates/conify/global/config/hard_due_date_values.tt2 +++ b/Open-ILS/src/templates/conify/global/config/hard_due_date_values.tt2 @@ -65,7 +65,7 @@ suppressFields="['hard_due_date']" suppressEditFields="['id']" fmClass="chddv" - hideSelector="true" + hideSelector="false" editOnEnter="true"> -- 2.11.0