per-agent disable_previous_balance, #15863
[freeside.git] / FS / FS / type_pkgs.pm
index 07ad2bc..6503755 100644 (file)
@@ -35,6 +35,8 @@ FS::Record.  The following fields are currently supported:
 
 =over 4
 
+=item typepkgnum - primary key
+
 =item typenum - Agent type, see L<FS::agent_type>
 
 =item pkgpart - Billing item definition, see L<FS::part_pkg>
@@ -80,17 +82,12 @@ sub check {
   my $self = shift;
 
   my $error = 
-    $self->ut_number('typenum')
-    || $self->ut_number('pkgpart')
+       $self->ut_numbern('typepkgnum')
+    || $self->ut_foreign_key('typenum', 'agent_type', 'typenum' )
+    || $self->ut_foreign_key('pkgpart', 'part_pkg',   'pkgpart' )
   ;
   return $error if $error;
 
-  return "Unknown typenum"
-    unless qsearchs( 'agent_type', { 'typenum' => $self->typenum } );
-
-  return "Unknown pkgpart"
-    unless qsearchs( 'part_pkg', { 'pkgpart' => $self->pkgpart } );
-
   $self->SUPER::check;
 }
 
@@ -105,6 +102,17 @@ sub part_pkg {
   qsearchs( 'part_pkg', { 'pkgpart' => $self->pkgpart } );
 }
 
+=item agent_type
+
+Returns the FS::agent_type object associated with this record.
+
+=cut
+
+sub agent_type {
+  my $self = shift;
+  qsearchs( 'agent_type', { 'typenum' => $self->typenum } );
+}
+
 =cut
 
 =back