[freeside-commits] freeside/FS/FS Schema.pm, 1.51, 1.52 cust_svc.pm, 1.66, 1.67 svc_acct.pm, 1.224, 1.225 svc_Common.pm, 1.39, 1.40 cust_pkg.pm, 1.74, 1.75

Jeff Finucane,420,, jeff at wavetail.420.am
Tue Apr 10 21:28:24 PDT 2007


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail:/tmp/cvs-serv15148/FS/FS

Modified Files:
	Schema.pm cust_svc.pm svc_acct.pm svc_Common.pm cust_pkg.pm 
Log Message:
usage suspend vs admin suspend -- avoid actual cust_pkg::suspend except legacy cases

Index: svc_Common.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_Common.pm,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- svc_Common.pm	29 Dec 2006 08:51:32 -0000	1.39
+++ svc_Common.pm	11 Apr 2007 04:28:21 -0000	1.40
@@ -735,6 +735,17 @@
 
 }
 
+=item overlimit
+
+Sets or retrieves overlimit date.
+
+=cut
+
+sub overlimit {
+  my $self = shift;
+  $self->cust_svc->overlimit(@_);
+}
+
 =item cancel
 
 Stub - returns false (no error) so derived classes don't need to define this

Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- Schema.pm	6 Apr 2007 19:38:08 -0000	1.51
+++ Schema.pm	11 Apr 2007 04:28:21 -0000	1.52
@@ -725,6 +725,7 @@
         'svcnum',    'serial',    '',   '', '', '', 
         'pkgnum',    'int',    'NULL',   '', '', '', 
         'svcpart',   'int',    '',   '', '', '', 
+        'overlimit', @date_type, '', '', 
       ],
       'primary_key' => 'svcnum',
       'unique' => [],

Index: svc_acct.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_acct.pm,v
retrieving revision 1.224
retrieving revision 1.225
diff -u -d -r1.224 -r1.225
--- svc_acct.pm	8 Apr 2007 01:14:25 -0000	1.224
+++ svc_acct.pm	11 Apr 2007 04:28:21 -0000	1.225
@@ -1590,7 +1590,7 @@
 
   if ( &{$op2condition{$op}}($self, $column, $amount) ) {
     foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
-      if ($part_export->option('overlimit_groups')) {
+      if ($part_export->option('overlimit_groups'), 1) {
         my ($new,$old);
         my $other = new FS::svc_acct $self->hashref;
         my $groups = &{ $self->_fieldhandlers->{'usergroup'} }
@@ -1602,6 +1602,7 @@
           $new = $self; $old = $other;
         }
         my $error = $part_export->export_replace($new, $old);
+        $error ||= $self->overlimit($action);
         if ( $error ) {
           $dbh->rollback if $oldAutoCommit;
           return "Error replacing radius groups in export, ${op}: $error";
@@ -1614,6 +1615,7 @@
        && &{$op2condition{$op}}($self, $column, $amount)    ) {
     #my $error = $self->$action();
     my $error = $self->cust_svc->cust_pkg->$action();
+    $error ||= $self->overlimit($action);
     if ( $error ) {
       $dbh->rollback if $oldAutoCommit;
       return "Error ${action}ing: $error";
@@ -1707,8 +1709,22 @@
       if $rv == 0;
   }
 
-  if ( $conf->exists("svc_acct-usage_unsuspend") && $reset ) {
-    my $error = $self->cust_svc->cust_pkg->unsuspend;
+  if ( $reset ) {
+    my $error = $self->overlimit('unsuspend');
+
+    foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
+      if ($part_export->option('overlimit_groups'), 1) {
+        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);
+      }
+    }
+
+    if ( $conf->exists("svc_acct-usage_unsuspend")) {
+      $error ||= $self->cust_svc->cust_pkg->unsuspend;
+    }
     if ( $error ) {
       $dbh->rollback if $oldAutoCommit;
       return "Error unsuspending: $error";

Index: cust_svc.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_svc.pm,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- cust_svc.pm	29 Dec 2006 08:51:32 -0000	1.66
+++ cust_svc.pm	11 Apr 2007 04:28:21 -0000	1.67
@@ -68,6 +68,8 @@
 
 =item svcpart - Service definition (see L<FS::part_svc>)
 
+=item overlimit - date the service exceeded its usage limit
+
 =back
 
 =head1 METHODS
@@ -154,6 +156,54 @@
 
 }
 
+=item overlimit [ ACTION ]
+
+Retrieves or sets the overlimit date.  If ACTION is absent, return
+the present value of overlimit.  If ACTION is present, it can
+have the value 'suspend' or 'unsuspend'.  In the case of 'suspend' overlimit
+is set to the current time if it is not already set.  The 'unsuspend' value
+causes the time to be cleared.  
+
+If there is an error on setting, returns the error, otherwise returns false.
+
+=cut
+
+sub overlimit {
+  my $self = shift;
+  my $action = shift or return $self->getfield('overlimit');
+
+  local $SIG{HUP} = 'IGNORE';
+  local $SIG{INT} = 'IGNORE';
+  local $SIG{QUIT} = 'IGNORE'; 
+  local $SIG{TERM} = 'IGNORE';
+  local $SIG{TSTP} = 'IGNORE';
+  local $SIG{PIPE} = 'IGNORE';
+
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  my $dbh = dbh;
+
+  if ( $action eq 'suspend' ) {
+    $self->setfield('overlimit', time) unless $self->getfield('overlimit');
+  }elsif ( $action eq 'unsuspend' ) {
+    $self->setfield('overlimit', '');
+  }else{
+    die "unexpected action value: $action";
+  }
+
+  local $ignore_quantity = 1;
+  my $error = $self->replace;
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return "Error setting overlimit: $error";
+  }
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
+  ''; #no errors
+
+}
+
 =item replace OLD_RECORD
 
 Replaces the OLD_RECORD with this one in the database.  If there is an error,
@@ -175,6 +225,8 @@
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
 
+  $old = $new->replace_old unless defined($old);
+  
   if ( $new->svcpart != $old->svcpart ) {
     my $svc_x = $new->svc_x;
     my $new_svc_x = ref($svc_x)->new({$svc_x->hash, svcpart=>$new->svcpart });
@@ -212,6 +264,7 @@
     $self->ut_numbern('svcnum')
     || $self->ut_numbern('pkgnum')
     || $self->ut_number('svcpart')
+    || $self->ut_numbern('overlimit')
   ;
   return $error if $error;
 

Index: cust_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pkg.pm,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- cust_pkg.pm	13 Mar 2007 09:21:35 -0000	1.74
+++ cust_pkg.pm	11 Apr 2007 04:28:21 -0000	1.75
@@ -799,6 +799,19 @@
 
 }
 
+=item overlimit [ SVCPART ]
+
+Returns the services for this package which have exceeded their
+usage limit as FS::cust_svc objects (see L<FS::cust_svc>).  If a svcpart
+is specified, return only the matching services.
+
+=cut
+
+sub overlimit {
+  my $self = shift;
+  grep { $_->overlimit } $self->cust_svc;
+}
+
 =item h_cust_svc END_TIMESTAMP [ START_TIMESTAMP ] 
 
 Returns historical services for this package created before END TIMESTAMP and



More information about the freeside-commits mailing list