X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fsvc_hardware.pm;h=7159f6dda8b6545d371e6ca8b85a28a1f06ece2a;hp=dc9ac59dfc07ea37b7dff3a125d6bbad77b9bc07;hb=8d0e8149e7b19ad8543ac6c8c663be63dbc34762;hpb=32072dbf59a054529f5304574c0f56f9567d14d0 diff --git a/FS/FS/svc_hardware.pm b/FS/FS/svc_hardware.pm index dc9ac59df..7159f6dda 100644 --- a/FS/FS/svc_hardware.pm +++ b/FS/FS/svc_hardware.pm @@ -75,6 +75,7 @@ sub table_info { 'name_plural' => 'Hardware', 'display_weight' => 59, 'cancel_weight' => 86, + 'manual_require' => 1, 'fields' => { 'svcnum' => { label => 'Service' }, 'typenum' => { label => 'Device type', @@ -83,6 +84,7 @@ sub table_info { disable_fixed => 1, disable_default => 1, disable_inventory => 1, + required => 1, }, 'serial' => { label => 'Serial number', %opts }, 'hw_addr' => { label => 'Hardware address', %opts }, @@ -132,7 +134,24 @@ sub search_sql { sub label { my $self = shift; - $self->serial || $self->display_hw_addr; + my $part_svc = $self->cust_svc->part_svc; + my @label = (); + if (my $type = $self->hardware_type) { + my $typenum_label = $part_svc->part_svc_column('typenum'); + push @label, ( $typenum_label && $typenum_label->columnlabel || 'Type' ). + ':'. $type->description; + } + if (my $ser = $self->serial) { + my $serial_label = $part_svc->part_svc_column('serial'); + push @label, ( $serial_label && $serial_label->columnlabel || 'Serial' ). + '#'. $ser; + } + if (my $mac = $self->display_hw_addr) { + my $hw_addr_label = $part_svc->part_svc_column('hw_addr'); + push @label, ( $hw_addr_label && $hw_addr_label->columnlabel || 'MAC'). + ':'. $mac; + } + return join(', ', @label); } =item insert @@ -172,6 +191,10 @@ sub check { $hw_addr = uc($hw_addr); $hw_addr =~ /^[0-9A-F]{12}$/ or return "Illegal (MAC address) '".$self->getfield('hw_addr')."'"; + } else { + return "Illegal (hardware address) '".$self->getfield('hw_addr')."': ". + "12 alphanumeric characters maximum" + if length($hw_addr) > 12; } $self->setfield('hw_addr', $hw_addr); @@ -195,6 +218,40 @@ sub check { $self->SUPER::check; } +#false laziness w/svc_cable +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->hw_addr ) { + my @dup_mac; + @dup_mac = $self->find_duplicates('global', 'hw_addr'); + if ( @dup_mac ) { + return "Hardware address in use (svcnum ".$dup_mac[0]->svcnum.")"; + } + } + + if ( $self->ip_addr ) { + my @dup_ip; + @dup_ip = $self->find_duplicates('global', 'ip_addr'); + if ( @dup_ip ) { + return "IP address in use (svcnum ".$dup_ip[0]->svcnum.")"; + } + } + + if ( $self->serial ) { + my @dup_serial; + @dup_serial = $self->find_duplicates('global', 'typenum', 'serial'); + if ( @dup_serial ) { + return "Serial number in use (svcnum ".$dup_serial[0]->svcnum.")"; + } + } + + ''; +} + =item hardware_type Returns the L object associated with this installation. @@ -226,6 +283,17 @@ sub display_hw_addr { join(':', $self->hw_addr =~ /../g) : $self->hw_addr) } +sub _upgrade_data { + + require FS::Misc::FixIPFormat; + FS::Misc::FixIPFormat::fix_bad_addresses_in_table( + 'svc_hardware', 'svcnum', 'ip_addr', + ); + + ''; + +} + =back =head1 SEE ALSO @@ -235,4 +303,3 @@ L, L, schema.html from the base documentation. =cut 1; -