1606 correct bug in overlimit groups handling
[freeside.git] / FS / FS / svc_acct.pm
index d94673b..1e0389d 100644 (file)
@@ -1636,7 +1636,10 @@ sub _op_usage {
 
   my $action = $op2action{$op};
 
-  if ( &{$op2condition{$op}}($self, $column, $amount) ) {
+  if ( &{$op2condition{$op}}($self, $column, $amount) &&
+        ( $action eq 'suspend'   && !$self->overlimit 
+       || $action eq 'unsuspend' &&  $self->overlimit ) 
+     ) {
     foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
       if ($part_export->option('overlimit_groups')) {
         my ($new,$old);
@@ -1663,7 +1666,7 @@ sub _op_usage {
        && &{$op2condition{$op}}($self, $column, $amount)    ) {
     #my $error = $self->$action();
     my $error = $self->cust_svc->cust_pkg->$action();
-    $error ||= $self->overlimit($action);
+    $error ||= $self->overlimit($action);
     if ( $error ) {
       $dbh->rollback if $oldAutoCommit;
       return "Error ${action}ing: $error";
@@ -1758,15 +1761,18 @@ sub set_usage {
   }
 
   if ( $reset ) {
-    my $error = $self->overlimit('unsuspend');
-
-    foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
-      if ($part_export->option('overlimit_groups')) {
-        my $old = new FS::svc_acct $self->hashref;
-        my $groups = &{ $self->_fieldhandlers->{'usergroup'} }
-                       ($self, $part_export->option('overlimit_groups'));
-        $old->usergroup( $groups );
-        $error ||= $part_export->export_replace($self, $old);
+    my $error;
+
+    if ($self->overlimit) {
+      $error = $self->overlimit('unsuspend');
+      foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
+        if ($part_export->option('overlimit_groups')) {
+          my $old = new FS::svc_acct $self->hashref;
+          my $groups = &{ $self->_fieldhandlers->{'usergroup'} }
+                         ($self, $part_export->option('overlimit_groups'));
+          $old->usergroup( $groups );
+          $error ||= $part_export->export_replace($self, $old);
+        }
       }
     }