From 11198b6366a4e6945fdb93164fc2b1b8141cb046 Mon Sep 17 00:00:00 2001 From: Jason Etheridge Date: Wed, 17 Apr 2019 08:29:53 -0400 Subject: [PATCH] lp1811710: toward hopeless holds, backend and existing UI's Signed-off-by: Jason Etheridge Signed-off-by: Galen Charlton Signed-off-by: Terran McCanna Signed-off-by: Chris Sharp --- Open-ILS/examples/fm_IDL.xml | 4 ++ .../app/staff/share/holds/detail.component.html | 5 +- .../src/app/staff/share/holds/grid.component.html | 1 + .../Application/Storage/Publisher/action.pm | 2 +- .../src/perlmods/lib/OpenILS/Utils/HoldTargeter.pm | 62 ++++++++++++++++++++++ Open-ILS/src/sql/Pg/002.schema.config.sql | 3 +- Open-ILS/src/sql/Pg/090.schema.action.sql | 3 +- .../sql/Pg/upgrade/YYYY.schema.hopeless_holds.sql | 8 +++ .../src/templates/staff/cat/catalog/t_holds.tt2 | 1 + .../templates/staff/circ/holds/t_shelf_list.tt2 | 1 + .../templates/staff/circ/share/t_hold_details.tt2 | 9 ++++ 11 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/YYYY.schema.hopeless_holds.sql diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 11dcf07d36..5ec1ff4c79 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -4603,6 +4603,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + @@ -6574,6 +6575,7 @@ SELECT usr, + @@ -6739,6 +6741,7 @@ SELECT usr, + @@ -6810,6 +6813,7 @@ SELECT usr, + diff --git a/Open-ILS/src/eg2/src/app/staff/share/holds/detail.component.html b/Open-ILS/src/eg2/src/app/staff/share/holds/detail.component.html index daeeb8957c..bc7e4f6627 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/holds/detail.component.html +++ b/Open-ILS/src/eg2/src/app/staff/share/holds/detail.component.html @@ -91,9 +91,8 @@ {{hold.ucard_barcode}} - -
-
+
Hopeless Date
+
{{hold.hopeless_date | formatValue:'timestamp'}}
diff --git a/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.html b/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.html index 7a9aceb4ab..9cead96e0c 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.html +++ b/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.html @@ -172,6 +172,7 @@ + diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm index 5c2583cc17..7cf6e26cc1 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm @@ -2166,7 +2166,7 @@ SELECT h.id, h.request_time, h.capture_time, h.fulfillment_time, h.checkin_time h.request_lib, h.requestor, h.usr, h.selection_ou, h.selection_depth, h.pickup_lib, h.hold_type, h.holdable_formats, h.phone_notify, h.email_notify, h.sms_notify, h.sms_carrier, h.frozen, h.thaw_date, h.shelf_time, h.cut_in_line, h.mint_condition, - h.shelf_expire_time, h.current_shelf_lib, h.behind_desk, + h.shelf_expire_time, h.current_shelf_lib, h.behind_desk, h.hopeless_date, CASE WHEN h.cancel_time IS NOT NULL THEN 6 WHEN h.frozen AND h.capture_time IS NULL THEN 7 diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/HoldTargeter.pm b/Open-ILS/src/perlmods/lib/OpenILS/Utils/HoldTargeter.pm index 44685cff7c..3816822724 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/HoldTargeter.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/HoldTargeter.pm @@ -203,6 +203,11 @@ sub init { # Map of org id to 1. Any org in the map is closed. $self->{closed_orgs} = {map {$_ => 1} @closed_orgs}; + + my $hopeless_prone = $self->editor->search_config_copy_status({ + hopeless_prone => 't' + }); + $self->{hopeless_prone_status_ids} = { map { $_->id => 1} @{ $hopeless_prone } }; } @@ -628,6 +633,59 @@ sub update_copy_maps { return $self->exit_targeter("Error creating hold copy maps", 1); } +# Hopeless Date logic based on copy map +sub handle_hopeless_date { + my ($self) = @_; + my $e = $self->editor; + my $hold = $self->hold; + my $need_update = 0; + + # If copy map is empty and hopeless date is not already set, + # then set it. Otherwise, let's check the items for Hopeless + # Prone statuses. If all are hopeless then set the hopeless + # date if needed. If at least one is not hopeless, then + # clear the the hopeless date if not already unset. + + if (scalar(@{$self->copies}) == 0) { + $logger->debug('Hopeless Holds logic (hold id ' . $hold->id . '): no copies'); + if (!$hold->hopeless_date) { + $logger->debug('Hopeless Holds logic (hold id ' . $hold->id . '): setting hopeless_date'); + $hold->hopeless_date('now'); + $need_update = 1; + } + } else { + my $all_hopeless = 1; + foreach my $copy_hash (@{$self->copies}) { + if (!$self->parent->{hopeless_prone_status_ids}->{$copy_hash->{status}}) { + $all_hopeless = 0; + } + } + if ($all_hopeless) { + $logger->debug('Hopeless Holds logic (hold id ' . $hold->id . '): all copies have hopeless prone status'); + if (!$hold->hopeless_date) { + $logger->debug('Hopeless Holds logic (hold id ' . $hold->id . '): setting hopeless_date'); + $hold->hopeless_date('now'); + $need_update = 1; + } + } else { + $logger->debug('Hopeless Holds logic (hold id ' . $hold->id . '): at least one copy without a hopeless prone status'); + if ($hold->hopeless_date) { + $logger->debug('Hopeless Holds logic (hold id ' . $hold->id . '): clearing hopeless_date'); + $hold->clear_hopeless_date; + $need_update = 1; + } + } + } + + if ($need_update) { + $logger->debug('Hopeless Holds logic (hold id ' . $hold->id . '): attempting update'); + $e->update_action_hold_request($hold) + or return $self->exit_targeter( + "Error updating Hopeless Date for hold request", 1); + # FIXME: sanity-check, will a commit happen further down the line for all use cases? + } +} + # unique set of circ lib IDs for all in-progress copy blobs. sub get_copy_circ_libs { my $self = shift; @@ -1264,6 +1322,10 @@ sub target { return unless $self->get_hold_copies; return unless $self->update_copy_maps; + # Hopeless Date logic based on copy map + + $self->handle_hopeless_date; + # Confirm that we have something to work on. If we have no # copies at this point, there's also nothing to recall. return unless $self->handle_no_copies; diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 6dab77eea1..2978fe859b 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -442,7 +442,8 @@ CREATE TABLE config.copy_status ( opac_visible BOOL NOT NULL DEFAULT FALSE, copy_active BOOL NOT NULL DEFAULT FALSE, restrict_copy_delete BOOL NOT NULL DEFAULT FALSE, - is_available BOOL NOT NULL DEFAULT FALSE + is_available BOOL NOT NULL DEFAULT FALSE, + hopeless_prone BOOL NOT NULL DEFAULT FALSE ); COMMENT ON TABLE config.copy_status IS $$ Copy Statuses diff --git a/Open-ILS/src/sql/Pg/090.schema.action.sql b/Open-ILS/src/sql/Pg/090.schema.action.sql index 0a4bb2c6ad..f62a9fa7cd 100644 --- a/Open-ILS/src/sql/Pg/090.schema.action.sql +++ b/Open-ILS/src/sql/Pg/090.schema.action.sql @@ -469,7 +469,8 @@ CREATE TABLE action.hold_request ( mint_condition BOOL NOT NULL DEFAULT TRUE, shelf_expire_time TIMESTAMPTZ, current_shelf_lib INT REFERENCES actor.org_unit DEFERRABLE INITIALLY DEFERRED, - behind_desk BOOLEAN NOT NULL DEFAULT FALSE + behind_desk BOOLEAN NOT NULL DEFAULT FALSE, + hopeless_date TIMESTAMP WITH TIME ZONE ); ALTER TABLE action.hold_request ADD CONSTRAINT sms_check CHECK ( sms_notify IS NULL diff --git a/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.hopeless_holds.sql b/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.hopeless_holds.sql new file mode 100644 index 0000000000..7205a71dd7 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.hopeless_holds.sql @@ -0,0 +1,8 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('YYYY', :eg_version); + +ALTER TABLE config.copy_status ADD COLUMN hopeless_prone BOOL NOT NULL DEFAULT FALSE; -- 002.schema.config.sql +ALTER TABLE action.hold_request ADD COLUMN hopeless_date TIMESTAMP WITH TIME ZONE; -- 090.schema.action.sql + +COMMIT; diff --git a/Open-ILS/src/templates/staff/cat/catalog/t_holds.tt2 b/Open-ILS/src/templates/staff/cat/catalog/t_holds.tt2 index f50be4cd93..0579075ab0 100644 --- a/Open-ILS/src/templates/staff/cat/catalog/t_holds.tt2 +++ b/Open-ILS/src/templates/staff/cat/catalog/t_holds.tt2 @@ -129,6 +129,7 @@ + diff --git a/Open-ILS/src/templates/staff/circ/holds/t_shelf_list.tt2 b/Open-ILS/src/templates/staff/circ/holds/t_shelf_list.tt2 index bbd8679a17..c89823cff0 100644 --- a/Open-ILS/src/templates/staff/circ/holds/t_shelf_list.tt2 +++ b/Open-ILS/src/templates/staff/circ/holds/t_shelf_list.tt2 @@ -116,6 +116,7 @@ + diff --git a/Open-ILS/src/templates/staff/circ/share/t_hold_details.tt2 b/Open-ILS/src/templates/staff/circ/share/t_hold_details.tt2 index ab2b75291b..ece4719944 100644 --- a/Open-ILS/src/templates/staff/circ/share/t_hold_details.tt2 +++ b/Open-ILS/src/templates/staff/circ/share/t_hold_details.tt2 @@ -52,6 +52,15 @@
[% l('Cancel Note') %]
{{hold.cancel_note()}}
+
+
[% l('Hopeless Date') %]
+
{{hold.hopeless_date() | date:$root.egDateAndTimeFormat}}
+ +
+
+
+
+