[freeside-commits] branch FREESIDE_3_BRANCH updated. 6b285a7d0b37bb1dfd1972eead37a45bff977651

Jonathan Prykop jonathan at 420.am
Wed Mar 16 23:12:25 PDT 2016


The branch, FREESIDE_3_BRANCH has been updated
       via  6b285a7d0b37bb1dfd1972eead37a45bff977651 (commit)
       via  6b7eaf2053e63569f1d8475fc16d603fa3995646 (commit)
       via  004f098a9b193a7ef7ff055aee97d3071a8cbbc0 (commit)
      from  8e1ae165bfb1fba2e3cca8081acadefc81aac95a (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 6b285a7d0b37bb1dfd1972eead37a45bff977651
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 fcd2c0b..645971c 100644
--- a/FS/FS/cust_main_Mixin.pm
+++ b/FS/FS/cust_main_Mixin.pm
@@ -673,8 +673,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 6b7eaf2053e63569f1d8475fc16d603fa3995646
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 [v3 merge]

diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm
index 05881b9..e6fa757 100644
--- a/FS/FS/Upgrade.pm
+++ b/FS/FS/Upgrade.pm
@@ -156,6 +156,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');
+  }
+
 }
 
 sub upgrade_overlimit_groups {
diff --git a/FS/FS/cust_main/Packages.pm b/FS/FS/cust_main/Packages.pm
index bea4c02..7b71eb2 100644
--- a/FS/FS/cust_main/Packages.pm
+++ b/FS/FS/cust_main/Packages.pm
@@ -532,12 +532,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 93906df..587454e 100644
--- a/FS/FS/cust_pay.pm
+++ b/FS/FS/cust_pay.pm
@@ -1242,15 +1242,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 b137384..a4c5447 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 004f098a9b193a7ef7ff055aee97d3071a8cbbc0
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 [v3 merge]

diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 9ff75de..10bb59c 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -2101,10 +2101,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 bf205aa..7cb79df 100644
--- a/FS/FS/cust_credit.pm
+++ b/FS/FS/cust_credit.pm
@@ -4,7 +4,7 @@ use strict;
 use base qw( FS::otaker_Mixin FS::cust_main_Mixin FS::reason_Mixin
              FS::Record );
 
-use vars qw( $conf $unsuspendauto $me $DEBUG
+use vars qw( $conf $me $DEBUG
              $otaker_upgrade_kludge $ignore_empty_reasonnum
            );
 use List::Util qw( min );
@@ -37,7 +37,6 @@ $ignore_empty_reasonnum = 0;
 $FS::UID::callback{'FS::cust_credit'} = sub { 
 
   $conf = new FS::Conf;
-  $unsuspendauto = $conf->exists('unsuspendauto');
 
 };
 
@@ -186,16 +185,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 40c0ae9..fcd2c0b 100644
--- a/FS/FS/cust_main_Mixin.pm
+++ b/FS/FS/cust_main_Mixin.pm
@@ -645,6 +645,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 d0966ca..93906df 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::Record );
 use vars qw( $DEBUG $me $conf @encrypted_fields
-             $unsuspendauto $ignore_noapply 
+             $ignore_noapply
            );
 use Date::Format;
 use Business::CreditCard;
@@ -35,7 +35,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');
@@ -341,16 +340,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
@@ -1251,6 +1242,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