LP#2006971: Custom system penalty business logic
authorMike Rylander <mrylander@gmail.com>
Mon, 19 Dec 2022 17:16:04 +0000 (12:16 -0500)
committerBill Erickson <berickxx@gmail.com>
Wed, 3 May 2023 19:38:58 +0000 (15:38 -0400)
Allow processing of penalty subsets, and the option of patron home
context rather than staff workstation location context.

Adjust Collections API to make use of the custom penalty versions
where applicable.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Elizabeth Davis <elizabeth.davis@sparkpa.org>
Signed-off-by: Bill Erickson <berickxx@gmail.com>

Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm
Open-ILS/src/perlmods/lib/OpenILS/Utils/Penalty.pm

index da0c9d7..43f3584 100644 (file)
@@ -3028,13 +3028,19 @@ __PACKAGE__->register_method(
     api_name => "open-ils.actor.user.penalties.update"
 );
 
+__PACKAGE__->register_method(
+    method   => "update_penalties",
+    api_name => "open-ils.actor.user.penalties.update_at_home"
+);
+
 sub update_penalties {
-    my($self, $conn, $auth, $user_id) = @_;
+    my($self, $conn, $auth, $user_id, @penalties) = @_;
     my $e = new_editor(authtoken=>$auth, xact => 1);
     return $e->die_event unless $e->checkauth;
     my $user = $e->retrieve_actor_user($user_id) or return $e->die_event;
     return $e->die_event unless $e->allowed('UPDATE_USER', $user->home_ou);
-    my $evt = OpenILS::Utils::Penalty->calculate_penalties($e, $user_id, $e->requestor->ws_ou);
+    my $context_org = ($self->api_name =~ /_at_home$/) ? $user->home_ou : $e->requestor->ws_ou;
+    my $evt = OpenILS::Utils::Penalty->calculate_penalties($e, $user_id, $context_org, @penalties);
     return $evt if $evt;
     $e->commit;
     return 1;
index 3521685..270314a 100644 (file)
@@ -211,6 +211,8 @@ sub users_of_interest_warning_penalty {
     my $min_set_date = DateTime->now->subtract(seconds =>
         interval_to_seconds($min_age))->strftime( '%F %T%z' ) if $min_age;
 
+    my $sp_id = $U->ou_ancestor_setting_value($org->id, 'circ.custom_penalty_override.PATRON_EXCEEDS_COLLECTIONS_WARNING') || 4;
+
     my $start = time;
     my $query = {
         select => {ausp => ['usr']},
@@ -234,7 +236,7 @@ sub users_of_interest_warning_penalty {
         },
         where => {
             '+ausp' => {
-                standing_penalty => 4, # PATRON_EXCEEDS_COLLECTIONS_WARNING
+                standing_penalty => [4,$sp_id], # PATRON_EXCEEDS_COLLECTIONS_WARNING
                 org_unit => [ map {$_->{id}} @$org_ids ],
                 '-or' => [
                     {stop_date => undef},
@@ -482,10 +484,12 @@ sub put_into_collections {
 
     $e->commit;
 
+    my $sp_id = $U->ou_ancestor_setting_value($org->id, 'circ.custom_penalty_override.PATRON_IN_COLLECTIONS') || 30;
+
     my $pen = Fieldmapper::actor::user_standing_penalty->new;
     $pen->org_unit($org->id);
     $pen->usr($user_id);
-    $pen->standing_penalty(30); # PATRON_IN_COLLECTIONS
+    $pen->standing_penalty($sp_id); # PATRON_IN_COLLECTIONS
     $pen->staff($e->requestor->id);
     my $msg = { 'pub' => 0, 'title' => 'PATRON_IN_COLLECTIONS', 'message' => $fee_note };
     $U->simplereq('open-ils.actor', 'open-ils.actor.user.penalty.apply', $auth, $pen, $msg);
index c91bbc8..03efff8 100644 (file)
@@ -12,10 +12,9 @@ use OpenILS::Utils::Fieldmapper;
 use OpenILS::Const qw/:const/;
 my $U = "OpenILS::Application::AppUtils";
 
-
-# calculate and update the well-known penalties
+# calculate and update the well-known penalties, limited to the list supplied
 sub calculate_penalties {
-    my($class, $e, $user_id, $context_org) = @_;
+    my($class, $e, $user_id, $context_org, @only_penalties) = @_;
 
     my $commit = 0;
     unless($e) {
@@ -25,6 +24,30 @@ sub calculate_penalties {
 
     my $penalties = $e->json_query({from => ['actor.calculate_system_penalties',$user_id, $context_org]});
 
+    if (@only_penalties) {
+        my $all_penalties = $penalties;
+        $penalties = [];
+
+        my @only_penalties_id_list = grep {/^\d+$/} @only_penalties;
+
+        if (my @name_penalties = grep {/\D/} @only_penalties) { # has at least one non-numeric character
+            my $only_these_penalties = $e->search_config_standing_penalty({name => \@name_penalties});
+            my %penalty_override_map = $U->ou_ancestor_setting_batch_insecure(
+                $context_org,
+                [ map { 'circ.custom_penalty_override.'. $_ } @name_penalties ]
+            );
+
+            push @only_penalties_id_list, map { $_->id } @$only_these_penalties;
+            push @only_penalties_id_list, map { $_->{value} } values %penalty_override_map;
+        }
+
+        for my $p (@$all_penalties) {
+            if (grep {$p->{standing_penalty} eq $_} @only_penalties_id_list) {
+                push @$penalties, $p;
+            }
+        }
+    }
+
     my $user = $e->retrieve_actor_user( $user_id );
     my @existing_penalties = grep { defined $_->{id} } @$penalties;
     my @wanted_penalties = grep { !defined $_->{id} } @$penalties;