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;
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']},
},
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},
$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);
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) {
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;