[freeside-commits] branch FREESIDE_4_BRANCH updated. d800198db4f59bd5369e0d1acbfeb3c7594c32c0

Ivan Kohler ivan at freeside.biz
Tue Oct 30 12:17:26 PDT 2018


The branch, FREESIDE_4_BRANCH has been updated
       via  d800198db4f59bd5369e0d1acbfeb3c7594c32c0 (commit)
      from  cbb7dce1f2db07e537fad4ccc8d7bf25e9419e1c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit d800198db4f59bd5369e0d1acbfeb3c7594c32c0
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Tue Oct 30 12:17:16 2018 -0700

    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 3ae9a5239..733ed00fe 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -2071,6 +2071,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'     => 'suspension',
     'description' => 'Global override that causes unsuspensions to always adjust the next bill date under any circumstances.  This is now controlled on a per-package bases - probably best not to use this option unless you are a legacy installation that requires this behaviour.',
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index f35ec12f7..ae1c46ad5 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -2293,7 +2293,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 be7de8526..9e529f8dd 100644
--- a/FS/FS/cust_main/Packages.pm
+++ b/FS/FS/cust_main/Packages.pm
@@ -570,16 +570,32 @@ sub sort_packages {
 
 }
 
-=item suspended_pkgs
+=item suspended_pkgs OPTION => VALUE ...
 
 Returns all suspended packages (see L<FS::cust_pkg>) for this customer.
 
+Currently supports one option, I<reason_type>, 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 cceaa4bc7..6a2e9058c 100644
--- a/FS/FS/cust_main_Mixin.pm
+++ b/FS/FS/cust_main_Mixin.pm
@@ -737,7 +737,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)

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Conf.pm               |  7 +++++++
 FS/FS/cust_main.pm          |  2 +-
 FS/FS/cust_main/Packages.pm | 22 +++++++++++++++++++---
 FS/FS/cust_main_Mixin.pm    |  4 +++-
 4 files changed, 30 insertions(+), 5 deletions(-)




More information about the freeside-commits mailing list