From: Ivan Kohler Date: Tue, 30 Oct 2018 19:17:19 +0000 (-0700) Subject: add option to limit automatic unsuspensions to a specific suspension reason type... X-Git-Url: http://git.freeside.biz/gitweb/?a=commitdiff_plain;h=fe3d7a23f0ebda93058085b9d439a18a36247f42;p=freeside.git add option to limit automatic unsuspensions to a specific suspension reason type, RT#74448, RT#81634 --- diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 5c0fdffa4..b36f5f585 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -2204,6 +2204,13 @@ and customer address. Include units.', ], }, + { + 'key' => 'unsuspend_reason_type', + 'section' => 'suspension', + 'description' => 'If set, limits automatic unsuspension to packages which were suspended for this reason type.', + reason_type_options('S'), + }, + { 'key' => 'unsuspend-always_adjust_next_bill_date', 'section' => 'billing', diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index b103996a4..1de1db5b1 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -2303,7 +2303,7 @@ Returns a list: an empty list on success or a list of errors. sub unsuspend { my $self = shift; - grep { ($_->get('setup')) && $_->unsuspend } $self->suspended_pkgs; + grep { ($_->get('setup')) && $_->unsuspend } $self->suspended_pkgs(@_); } =item release_hold diff --git a/FS/FS/cust_main/Packages.pm b/FS/FS/cust_main/Packages.pm index fec9fd348..50da8b219 100644 --- a/FS/FS/cust_main/Packages.pm +++ b/FS/FS/cust_main/Packages.pm @@ -545,16 +545,32 @@ sub sort_packages { } -=item suspended_pkgs +=item suspended_pkgs OPTION => VALUE ... Returns all suspended packages (see L) for this customer. +Currently supports one option, I, which if set to a typenum, +limits the results to packages which were suspended for reasons of this type. +(Does not currently work in scalar context; i.e. when just asking for a count.) + =cut sub suspended_pkgs { my $self = shift; - return $self->num_suspended_pkgs unless wantarray; - grep { $_->susp } $self->ncancelled_pkgs; + my %opt = @_; + + return $self->num_suspended_pkgs unless wantarray; #XXX opt in scalar context + + my @pkgs = grep { $_->susp } $self->ncancelled_pkgs; + + if ( $opt{reason_type} ) { + @pkgs = grep { my $r = $_->last_reason('susp'); + $r && $r->reason_type == $opt{reason_type}; + } + @pkgs; + } + + @pkgs; } ### This appears to be unused, will be going away diff --git a/FS/FS/cust_main_Mixin.pm b/FS/FS/cust_main_Mixin.pm index 296a9e469..473bdd299 100644 --- a/FS/FS/cust_main_Mixin.pm +++ b/FS/FS/cust_main_Mixin.pm @@ -715,7 +715,9 @@ sub unsuspend_balance { } my $balance = $cust_main->balance || 0; if ($balance <= $maxbalance) { - my @errors = $cust_main->unsuspend; + my @errors = $cust_main->unsuspend( + 'reason_type' => $conf->config('unsuspend_reason_type') + ); # side-fx with nested transactions? upstack rolls back? warn "WARNING:Errors unsuspending customer ". $cust_main->custnum. ": ". join(' / ', @errors)