From: Mike Rylander Date: Mon, 19 Dec 2022 17:16:04 +0000 (-0500) Subject: LP#2006971: Custom system penalty business logic X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=20a752e24f7fb1efbfc9fb3c1483fcb3e6996291;p=evergreen%2Fpines.git LP#2006971: Custom system penalty business logic 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 Signed-off-by: Elizabeth Davis Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm index da0c9d7fa2..43f3584d73 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm @@ -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; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm index 352168525a..270314a44c 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm @@ -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); diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/Penalty.pm b/Open-ILS/src/perlmods/lib/OpenILS/Utils/Penalty.pm index c91bbc8d8a..03efff88db 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/Penalty.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/Penalty.pm @@ -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;