fix 'Can't call method "setup" on an undefined value' error when using into rates...
[freeside.git] / FS / FS / part_device.pm
index 4963584..0f840a7 100644 (file)
@@ -40,6 +40,7 @@ primary key
 
 devicename
 
+=item inventory_classnum
 
 =back
 
@@ -103,6 +104,7 @@ sub check {
   my $error = 
     $self->ut_numbern('devicepart')
     || $self->ut_text('devicename')
+    || $self->ut_foreign_keyn('inventory_classnum', 'inventory_class', 'classnum')
   ;
   return $error if $error;
 
@@ -121,6 +123,19 @@ sub part_export {
     qsearch( 'export_device', { 'devicepart' => $self->devicepart } );
 }
 
+=item inventory_class
+
+Returns the inventory class (see L<FS::inventory_class>) for this device, 
+if any.
+
+=cut
+
+sub inventory_class {
+  my $self = shift;
+  return '' unless $self->inventory_classnum;
+  qsearchs('inventory_class', { 'classnum' => $self->inventory_classnum });
+}
+
 sub process_batch_import {
   my $job = shift;