1606 correct bug in overlimit groups handling
authorjeff <jeff>
Mon, 7 May 2007 02:13:54 +0000 (02:13 +0000)
committerjeff <jeff>
Mon, 7 May 2007 02:13:54 +0000 (02:13 +0000)
FS/FS/cust_pkg.pm
FS/FS/svc_acct.pm
httemplate/misc/process/link.cgi

index 616a480..9b5066f 100644 (file)
@@ -1267,11 +1267,8 @@ sub transfer {
   foreach my $cust_svc ($self->cust_svc) {
     if($target{$cust_svc->svcpart} > 0) {
       $target{$cust_svc->svcpart}--;
-      my $new = new FS::cust_svc {
-        svcnum  => $cust_svc->svcnum,
-        svcpart => $cust_svc->svcpart,
-        pkgnum  => $dest_pkgnum,
-      };
+      my $new = new FS::cust_svc { $cust_svc->hash };
+      $new->pkgnum($dest_pkgnum);
       my $error = $new->replace($cust_svc);
       return $error if $error;
     } elsif ( exists $opt{'change_svcpart'} && $opt{'change_svcpart'} ) {
@@ -1290,11 +1287,9 @@ sub transfer {
         warn "alternate(s) found\n" if $DEBUG;
         my $change_svcpart = $alternate[0];
         $target{$change_svcpart}--;
-        my $new = new FS::cust_svc {
-          svcnum  => $cust_svc->svcnum,
-          svcpart => $change_svcpart,
-          pkgnum  => $dest_pkgnum,
-        };
+        my $new = new FS::cust_svc { $cust_svc->hash };
+        $new->svcpart($change_svcpart);
+        $new->pkgnum($dest_pkgnum);
         my $error = $new->replace($cust_svc);
         return $error if $error;
       } else {
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);
+        }
       }
     }
 
index fd3d8bb..7c71371 100755 (executable)
 %if ( $old->pkgnum && ! $conf->exists('legacy_link-steal') ) {
 %  $error = "svcnum $svcnum already linked to package ". $old->pkgnum;
 %} else {
-%  $new = new FS::cust_svc ({
-%    'svcnum' => $svcnum,
-%    'pkgnum' => $pkgnum,
-%    'svcpart' => $svcpart,
-%  });
+%  $new = new FS::cust_svc { $old->hash };
+%  $new->pkgnum($pkgnum);
+%  $new->svcpart($svcpart);
 %
 %  $error = $new->replace($old);
 %}