move sql_external to use recur_Common, RT#7212
[freeside.git] / FS / FS / prepay_credit.pm
index 38e87ad..302ba37 100644 (file)
@@ -110,6 +110,9 @@ sub check {
   || $self->ut_alpha('identifier')
   || $self->ut_money('amount')
   || $self->ut_numbern('seconds')
+  || $self->ut_numbern('upbytes')
+  || $self->ut_numbern('downbytes')
+  || $self->ut_numbern('totalbytes')
   || $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum')
   || $self->SUPER::check
   ;
@@ -159,10 +162,18 @@ sub generate {
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
 
+  my $condup = 0; #don't retry forever
+
   my @cards = ();
   for ( 1 ... $num ) {
+
+    my $identifier = join('', map($codeset[int(rand $#codeset)], (0..7) ) );
+
+    redo if qsearchs('prepay_credit',{identifier=>$identifier}) && $condup++<23;
+    $condup = 0;
+
     my $prepay_credit = new FS::prepay_credit {
-      'identifier' => join('', map($codeset[int(rand $#codeset)], (0..7) ) ),
+      'identifier' => $identifier,
       %$hashref,
     };
     my $error = $prepay_credit->check || $prepay_credit->insert;