svc_cable unique serialnum and mac_addr, RT#
[freeside.git] / FS / FS / svc_cable.pm
index 0c0d684..944f781 100644 (file)
@@ -56,7 +56,7 @@ points to.  You can ask the object for a copy with the I<hash> method.
 
 sub table { 'svc_cable'; }
 
-sub table_dupcheck_fields { ( 'mac_addr' ); }
+sub table_dupcheck_fields { ( 'serialnum', 'mac_addr' ); }
 
 sub search_sql {
   my( $class, $string ) = @_;
@@ -171,6 +171,27 @@ sub check {
   $self->SUPER::check;
 }
 
+sub _check_duplicate {
+  my $self = shift;
+
+  # Not reliable checks because the table isn't locked, but that's why we have
+  # unique indices.  These are just to give friendlier error messages.
+
+  my @dup_mac;
+  @dup_mac = $self->find_duplicates('global', 'mac_addr');
+  if ( @dup_mac ) {
+    return "MAC address in use (svcnum ".$dup_mac[0]->svcnum.")";
+  }
+
+  my @dup_serial;
+  @dup_serial = $self->find_duplicates('global', 'serialnum');
+  if ( @dup_serial ) {
+    return "Serial number in use (svcnum ".$dup_serial[0]->svcnum.")";
+  }
+
+  '';
+}
+
 =item cable_provider
 
 Returns the cable_provider object for this record.