[freeside-commits] branch FREESIDE_4_BRANCH updated. 9dd24df729dd13819019b87d25c1669346c49dd4

Jonathan Prykop jonathan at 420.am
Wed Mar 16 22:45:14 PDT 2016


The branch, FREESIDE_4_BRANCH has been updated
       via  9dd24df729dd13819019b87d25c1669346c49dd4 (commit)
       via  f40a061c3d2bfc3d988d4fd4e8e15211e8d9a291 (commit)
       via  fdff077d075af80c623bf03ce65cca4af0ebdde5 (commit)
      from  216272ed8a5ccfc8dc72268b9b02cc8fcd4479cf (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 9dd24df729dd13819019b87d25c1669346c49dd4
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Thu Mar 17 00:21:01 2016 -0500

    RT#28648: Unsuspend when past due balance is paid [more cleanup for backport]

diff --git a/FS/FS/cust_main_Mixin.pm b/FS/FS/cust_main_Mixin.pm
index 9b4ae3a..9a2a9d7 100644
--- a/FS/FS/cust_main_Mixin.pm
+++ b/FS/FS/cust_main_Mixin.pm
@@ -682,8 +682,6 @@ sub unsuspend_balance {
   }
   my $balance = $cust_main->balance || 0;
   if ($balance <= $maxbalance) {
-    # or should this be 
-    # my @errors = grep { ($_->get('setup')) && $_->unsuspend } $cust_main->unflagged_suspended_pkgs;
     my @errors = $cust_main->unsuspend;
     # side-fx with nested transactions?  upstack rolls back?
     warn "WARNING:Errors unsuspending customer ". $cust_main->custnum. ": ".

commit f40a061c3d2bfc3d988d4fd4e8e15211e8d9a291
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Thu Mar 17 00:16:35 2016 -0500

    RT#28648: Unsuspend when past due balance is paid [cleanup for backport]

diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm
index b7768a6..82fb800 100644
--- a/FS/FS/Upgrade.pm
+++ b/FS/FS/Upgrade.pm
@@ -171,6 +171,11 @@ If you need to continue using the old Form 477 report, turn on the
     $conf->set('password-generated-characters', $pw_set);
   }
 
+  if ($conf->exists('unsuspendauto') && !$conf->config('unsuspend_balance')) {
+    $conf->set('unsuspend_balance','Zero');
+    $conf->delete('unsuspendauto');
+  }
+
   enable_banned_pay_pad() unless length($conf->config('banned_pay-pad'));
 
 }
diff --git a/FS/FS/cust_main/Packages.pm b/FS/FS/cust_main/Packages.pm
index ef8d1a4..4356c59 100644
--- a/FS/FS/cust_main/Packages.pm
+++ b/FS/FS/cust_main/Packages.pm
@@ -557,12 +557,14 @@ sub suspended_pkgs {
   grep { $_->susp } $self->ncancelled_pkgs;
 }
 
-=item unflagged_suspended_pkgs
-
-Returns all unflagged suspended packages (see L<FS::cust_pkg>) for this
-customer (thouse packages without the `manual_flag' set).
-
-=cut
+### This appears to be unused, will be going away
+#
+#=item unflagged_suspended_pkgs
+#
+#Returns all unflagged suspended packages (see L<FS::cust_pkg>) for this
+#customer (thouse packages without the `manual_flag' set).
+#
+#=cut
 
 sub unflagged_suspended_pkgs {
   my $self = shift;
diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm
index 86e7968..331a156 100644
--- a/FS/FS/cust_pay.pm
+++ b/FS/FS/cust_pay.pm
@@ -1205,15 +1205,6 @@ sub _upgrade_data {  #class method
       process_upgrade_paybatch();
     }
   }
-
-  # unsuspendauto upgrade
-  # could just as easily go in cust_credit, or even cust_bill or cust_main
-  # but here works
-  if ($conf->exists('unsuspendauto') && !$conf->config('unsuspend_balance')) {
-    $conf->set('unsuspend_balance','Zero');
-    $conf->delete('unsuspendauto');
-  }
-
 }
 
 sub process_upgrade_paybatch {
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index 02e0e1e..6a10b71 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -189,11 +189,6 @@ date
 
 order taker (see L<FS::access_user>)
 
-=item manual_flag
-
-If this field is set to 1, disables the automatic
-unsuspension of this package when using the B<unsuspendauto> config option.
-
 =item quantity
 
 If not set, defaults to 1

commit fdff077d075af80c623bf03ce65cca4af0ebdde5
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Mon Mar 14 23:39:18 2016 -0500

    RT#28648: Unsuspend when past due balance is paid

diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 1ca9edb..1a8769d 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -1967,10 +1967,13 @@ and customer address. Include units.',
   },
 
   {
-    'key'         => 'unsuspendauto',
+    'key'         => 'unsuspend_balance',
     'section'     => 'billing',
-    'description' => 'Enables the automatic unsuspension of suspended packages when a customer\'s balance due changes from positive to zero or negative as the result of a payment or credit',
-    'type'        => 'checkbox',
+    'description' => 'Enables the automatic unsuspension of suspended packages when a customer\'s balance due is at or below the specified amount after a payment or credit',
+    'type'        => 'select',
+    'select_enum' => [ 
+      '', 'Zero', 'Latest invoice charges'
+    ],
   },
 
   {
diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm
index 4be4b17..094437e 100644
--- a/FS/FS/cust_credit.pm
+++ b/FS/FS/cust_credit.pm
@@ -3,7 +3,7 @@ use base qw( FS::otaker_Mixin FS::cust_main_Mixin FS::reason_Mixin
              FS::Record );
 
 use strict;
-use vars qw( $conf $unsuspendauto $me $DEBUG
+use vars qw( $conf $me $DEBUG
              $otaker_upgrade_kludge $ignore_empty_reasonnum
            );
 use List::Util qw( min );
@@ -34,7 +34,6 @@ $ignore_empty_reasonnum = 0;
 $FS::UID::callback{'FS::cust_credit'} = sub { 
 
   $conf = new FS::Conf;
-  $unsuspendauto = $conf->exists('unsuspendauto');
 
 };
 
@@ -210,16 +209,8 @@ sub insert {
 
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
 
-  #false laziness w/ cust_pay::insert
-  if ( $unsuspendauto && $old_balance && $cust_main->balance <= 0 ) {
-    my @errors = $cust_main->unsuspend;
-    #return 
-    # side-fx with nested transactions?  upstack rolls back?
-    warn "WARNING:Errors unsuspending customer ". $cust_main->custnum. ": ".
-         join(' / ', @errors)
-      if @errors;
-  }
-  #eslaf
+  # possibly trigger package unsuspend, doesn't abort transaction on failure
+  $self->unsuspend_balance if $old_balance;
 
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
 
diff --git a/FS/FS/cust_main_Mixin.pm b/FS/FS/cust_main_Mixin.pm
index de13847..9b4ae3a 100644
--- a/FS/FS/cust_main_Mixin.pm
+++ b/FS/FS/cust_main_Mixin.pm
@@ -654,6 +654,45 @@ sub time2str_local {
   $string;
 }
 
+=item unsuspend_balance
+
+If conf I<unsuspend_balance> is set and customer's current balance is
+beneath the set threshold, unsuspends customer packages.
+
+=cut
+
+sub unsuspend_balance {
+  my $self = shift;
+  my $cust_main = $self->cust_main;
+  my $conf = $self->conf;
+  my $setting = $conf->config('unsuspend_balance');
+  my $maxbalance;
+  if ($setting eq 'Zero') {
+    $maxbalance = 0;
+  } elsif ($setting eq 'Latest invoice charges') {
+    my @cust_bill = $cust_main->cust_bill();
+    my $cust_bill = $cust_bill[-1]; #always want the most recent one
+    return unless $cust_bill;
+    $maxbalance = $cust_bill->charged || 0;
+  } elsif (length($setting)) {
+    warn "Unrecognized unsuspend_balance setting $setting";
+    return;
+  } else {
+    return;
+  }
+  my $balance = $cust_main->balance || 0;
+  if ($balance <= $maxbalance) {
+    # or should this be 
+    # my @errors = grep { ($_->get('setup')) && $_->unsuspend } $cust_main->unflagged_suspended_pkgs;
+    my @errors = $cust_main->unsuspend;
+    # side-fx with nested transactions?  upstack rolls back?
+    warn "WARNING:Errors unsuspending customer ". $cust_main->custnum. ": ".
+         join(' / ', @errors)
+      if @errors;
+  }
+  return;
+}
+
 =back
 
 =head1 BUGS
diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm
index 620f6c6..86e7968 100644
--- a/FS/FS/cust_pay.pm
+++ b/FS/FS/cust_pay.pm
@@ -4,7 +4,7 @@ use strict;
 use base qw( FS::otaker_Mixin FS::payinfo_transaction_Mixin FS::cust_main_Mixin
              FS::reason_Mixin FS::Record);
 use vars qw( $DEBUG $me $conf @encrypted_fields
-             $unsuspendauto $ignore_noapply
+             $ignore_noapply
            );
 use Date::Format;
 use Business::CreditCard;
@@ -36,7 +36,6 @@ $ignore_noapply = 0;
 #ask FS::UID to run this stuff for us later
 FS::UID->install_callback( sub { 
   $conf = new FS::Conf;
-  $unsuspendauto = $conf->exists('unsuspendauto');
 } );
 
 @encrypted_fields = ('payinfo');
@@ -355,16 +354,8 @@ sub insert {
 
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
 
-  #false laziness w/ cust_credit::insert
-  if ( $unsuspendauto && $old_balance && $cust_main->balance <= 0 ) {
-    my @errors = $cust_main->unsuspend;
-    #return 
-    # side-fx with nested transactions?  upstack rolls back?
-    warn "WARNING:Errors unsuspending customer ". $cust_main->custnum. ": ".
-         join(' / ', @errors)
-      if @errors;
-  }
-  #eslaf
+  # possibly trigger package unsuspend, doesn't abort transaction on failure
+  $self->unsuspend_balance if $old_balance;
 
   #bill setup fees for voip_cdr bill_every_call packages
   #some false laziness w/search in freeside-cdrd
@@ -1214,6 +1205,15 @@ sub _upgrade_data {  #class method
       process_upgrade_paybatch();
     }
   }
+
+  # unsuspendauto upgrade
+  # could just as easily go in cust_credit, or even cust_bill or cust_main
+  # but here works
+  if ($conf->exists('unsuspendauto') && !$conf->config('unsuspend_balance')) {
+    $conf->set('unsuspend_balance','Zero');
+    $conf->delete('unsuspendauto');
+  }
+
 }
 
 sub process_upgrade_paybatch {

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

Summary of changes:
 FS/FS/Conf.pm               |    9 ++++++---
 FS/FS/Upgrade.pm            |    5 +++++
 FS/FS/cust_credit.pm        |   15 +++------------
 FS/FS/cust_main/Packages.pm |   14 ++++++++------
 FS/FS/cust_main_Mixin.pm    |   37 +++++++++++++++++++++++++++++++++++++
 FS/FS/cust_pay.pm           |   15 +++------------
 FS/FS/cust_pkg.pm           |    5 -----
 7 files changed, 62 insertions(+), 38 deletions(-)




More information about the freeside-commits mailing list