does this fix Bug#590??
[freeside.git] / FS / FS / svc_Common.pm
index 524e550..7bc155d 100644 (file)
@@ -49,8 +49,8 @@ sub virtual_fields {
 
   if ($self->svcpart) { # Case 1
     $svcpart = $self->svcpart;
-  } elsif (my $cust_svc = $self->cust_svc) { # Case 2
-    $svcpart = $cust_svc->svcpart;
+  } elsif ( $self->svcnum ) { #Case 2
+    $svcpart = $self->cust_svc->svcpart;
   } else { # Case 3
     $svcpart = '';
   }
@@ -80,7 +80,7 @@ sub check {
   $self->SUPER::check;
 }
 
-=item insert [ JOBNUM_ARRAYREF ]
+=item insert [ JOBNUM_ARRAYREF [ OBJECTS_ARRAYREF ] ]
 
 Adds this record to the database.  If there is an error, returns the error,
 otherwise returns false.
@@ -91,11 +91,16 @@ defined.  An FS::cust_svc record will be created and inserted.
 If an arrayref is passed as parameter, the B<jobnum>s of any export jobs will
 be added to the array.
 
+If an arrayref of FS::tablename objects (for example, FS::acct_snarf objects)
+is passed as the optional second parameter, they will have their svcnum fields
+set and will be inserted after this record, but before any exports are run.
+
 =cut
 
 sub insert {
   my $self = shift;
   local $FS::queue::jobnums = shift if @_;
+  my $objects = scalar(@_) ? shift : [];
   my $error;
 
   local $SIG{HUP} = 'IGNORE';
@@ -142,6 +147,15 @@ sub insert {
     return $error;
   }
 
+  foreach my $object ( @$objects ) {
+    $object->svcnum($self->svcnum);
+    $error = $object->insert;
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $error;
+    }
+  }
+
   #new-style exports!
   unless ( $noexport_hack ) {
     foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
@@ -414,10 +428,6 @@ sub cancel { ''; }
 
 =back
 
-=head1 VERSION
-
-$Id: svc_Common.pm,v 1.13 2003-08-05 00:20:47 khoff Exp $
-
 =head1 BUGS
 
 The setfixed method return value.