respect part_svc labels in svc_hardware & svc_cable short service labels, RT#73405
[freeside.git] / FS / FS / svc_cable.pm
index 4dd4543..9e818e1 100644 (file)
@@ -53,7 +53,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 ) = @_;
@@ -122,11 +122,16 @@ Returns the MAC address and serial number.
 
 sub label {
   my $self = shift;
+  my $part_svc = $self->cust_svc->part_svc;
   my @label = ();
   push @label, 'MAC:'. $self->mac_addr_pretty
     if $self->mac_addr;
-  push @label, 'Serial#'. $self->serialnum
-    if $self->serialnum;
+  if ( $self->serialnum ) {
+    my $serialnum_label = $part_svc->part_svc_column('serialnum');
+    push @label,
+      ($serialnum_label && $serialnum_label->columnlabel || 'Serial#').
+      $self->serialnum;
+  }
   return join(', ', @label);
 }
 
@@ -160,14 +165,39 @@ sub check {
     || $self->ut_foreign_keyn('providernum', 'cable_provider', 'providernum')
     || $self->ut_alphan('ordernum')
     || $self->ut_foreign_key('modelnum', 'cable_model', 'modelnum')
-    || $self->ut_alpha('serialnum')
-    || $self->ut_mac_addr('mac_addr')
+    || $self->ut_alphan('serialnum')
+    || $self->ut_mac_addrn('mac_addr')
   ;
   return $error if $error;
 
   $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.
+
+  if ( $self->mac_addr ) {
+    my @dup_mac;
+    @dup_mac = $self->find_duplicates('global', 'mac_addr');
+    if ( @dup_mac ) {
+      return "MAC address in use (svcnum ".$dup_mac[0]->svcnum.")";
+    }
+  }
+
+  if ( $self->serialnum ) {
+    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.