Add and use two YAOUS to allow hold targeting on copies at closed OUs
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 28 Sep 2011 18:28:35 +0000 (14:28 -0400)
committerMike Rylander <mrylander@gmail.com>
Fri, 28 Oct 2011 15:07:40 +0000 (11:07 -0400)
One YAOUS completely ignores the closedness of the circ lib of the copy
being tested for potential targeting.

The other YAOUS ignores the closedness of the circ lib IFF the circ lib of
the copy being tested matches the pickup lib of the hold request.

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.data.YAOUS-target-when-closed.sql [new file with mode: 0644]

index eff589c..fb58c35 100644 (file)
@@ -2,7 +2,7 @@ package OpenILS::Application::Storage::Publisher::action;
 use parent qw/OpenILS::Application::Storage::Publisher/;
 use strict;
 use warnings;
-use OpenSRF::Utils::Logger qw/:level/;
+use OpenSRF::Utils::Logger qw/:level :logger/;
 use OpenSRF::Utils qw/:datetime/;
 use OpenSRF::Utils::JSON;
 use OpenSRF::AppSession;
@@ -23,6 +23,24 @@ sub isTrue {
        return 0;
 }
 
+sub ou_ancestor_setting_value_or_cache {
+       # cache should be specific to setting
+       my ($actor, $org_id, $setting, $cache) = @_;
+
+       if (not exists $cache->{$org_id}) {
+               my $r = $actor->request(
+                       'open-ils.actor.ou_setting.ancestor_default', $org_id, $setting
+               )->gather(1);
+
+               if ($r) {
+                       $cache->{$org_id} = $r->{value};
+               } else {
+                       $cache->{$org_id} = undef;
+               }
+       }
+       return $cache->{$org_id};
+}
+
 my $parser = DateTime::Format::ISO8601->new;
 my $log = 'OpenSRF::Utils::Logger';
 
@@ -1108,6 +1126,9 @@ sub new_hold_copy_targeter {
        my @successes;
        my $actor = OpenSRF::AppSession->create('open-ils.actor');
 
+       my $target_when_closed = {};
+       my $target_when_closed_if_at_pickup_lib = {};
+
        for my $hold (@$holds) {
                try {
                        #start a transaction if needed
@@ -1274,8 +1295,38 @@ sub new_hold_copy_targeter {
                                # current target
                                next if ($c->id eq $hold->current_copy);
 
-                               # circ lib is closed
-                               next if ( grep { ''.$_->org_unit eq ''.$c->circ_lib } @closed );
+                               # skip on circ lib is closed IFF we care
+                               my $ignore_closing;
+
+                               if (''.$hold->pickup_lib eq ''.$c->circ_lib) {
+                                       $ignore_closing = ou_ancestor_setting_value_or_cache(
+                        $actor,
+                                               ''.$c->circ_lib,
+                                               'circ.holds.target_when_closed_if_at_pickup_lib',
+                                               $target_when_closed_if_at_pickup_lib
+                                       ) || 0;
+                               }
+                               if (not $ignore_closing) {  # one more chance to find a reason
+                                                                                       # to ignore OU closedness.
+                                       $ignore_closing = ou_ancestor_setting_value_or_cache(
+                        $actor,
+                                               ''.$c->circ_lib,
+                                               'circ.holds.target_when_closed',
+                                               $target_when_closed
+                                       ) || 0;
+                               }
+
+#                              $logger->info(
+#                                      "For hold " . $hold->id . " and copy with circ_lib " .
+#                                      $c->circ_lib . " we " .
+#                                      ($ignore_closing ? "ignore" : "respect")
+#                                      . " closed dates"
+#                              );
+
+                               next if (
+                                       (not $ignore_closing) and
+                                       (grep { ''.$_->org_unit eq ''.$c->circ_lib } @closed)
+                               );
 
                                # target of another hold
                                next if (action::hold_request
index 9ea1baa..686471e 100644 (file)
@@ -4456,6 +4456,23 @@ INSERT into config.org_unit_setting_type
         'If unset, the OPAC (only when wrapped in the staff client!) will default to showing you your ten most recent searches on the left side of the results and record details pages.  If you actually don''t want to see this feature at all, set this value to zero at the top of your organizational tree.',
         'coust', 'description'),
     'integer', null)
+,( 'circ.holds.target_when_closed', 'circ',
+    oils_i18n_gettext('circ.holds.target_when_closed',
+        'Target copies for a hold even if copy''s circ lib is closed',
+        'coust', 'label'),
+    oils_i18n_gettext('circ.holds.target_when_closed',
+        'If this setting is true at a given org unit or one of its ancestors, the hold targeter will target copies from this org unit even if the org unit is closed (according to the actor.org_unit.closed_date table).',
+        'coust', 'description'),
+    'bool', null)
+,( 'circ.holds.target_when_closed_if_at_pickup_lib', 'circ',
+    oils_i18n_gettext('circ.holds.target_when_closed_if_at_pickup_lib',
+        'Target copies for a hold even if copy''s circ lib is closed IF the circ lib is the hold''s pickup lib',
+        'coust', 'label'),
+    oils_i18n_gettext('circ.holds.target_when_closed_if_at_pickup_lib',
+        'If this setting is true at a given org unit or one of its ancestors, the hold targeter will target copies from this org unit even if the org unit is closed (according to the actor.org_unit.closed_date table) IF AND ONLY IF the copy''s circ lib is the same as the hold''s pickup lib.',
+        'coust', 'description'),
+    'bool', null)
+
 
 ,( 'opac.staff.jump_to_details_on_single_hit', 'opac',
     oils_i18n_gettext('opac.staff.jump_to_details_on_single_hit',
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.YAOUS-target-when-closed.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.YAOUS-target-when-closed.sql
new file mode 100644 (file)
index 0000000..0ab7a08
--- /dev/null
@@ -0,0 +1,24 @@
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+INSERT into config.org_unit_setting_type (name, grp, label, description, datatype) VALUES
+( 'circ.holds.target_when_closed', 'circ',
+    oils_i18n_gettext('circ.holds.target_when_closed',
+        'Target copies for a hold even if copy''s circ lib is closed',
+        'coust', 'label'),
+    oils_i18n_gettext('circ.holds.target_when_closed',
+        'If this setting is true at a given org unit or one of its ancestors, the hold targeter will target copies from this org unit even if the org unit is closed (according to the actor.org_unit.closed_date table).',
+        'coust', 'description'),
+    'bool'),
+( 'circ.holds.target_when_closed_if_at_pickup_lib', 'circ',
+    oils_i18n_gettext('circ.holds.target_when_closed_if_at_pickup_lib',
+        'Target copies for a hold even if copy''s circ lib is closed IF the circ lib is the hold''s pickup lib',
+        'coust', 'label'),
+    oils_i18n_gettext('circ.holds.target_when_closed_if_at_pickup_lib',
+        'If this setting is true at a given org unit or one of its ancestors, the hold targeter will target copies from this org unit even if the org unit is closed (according to the actor.org_unit.closed_date table) IF AND ONLY IF the copy''s circ lib is the same as the hold''s pickup lib.',
+        'coust', 'description'),
+    'bool')
+;
+
+COMMIT;