svc_hardware: better error messages for bad hw_addr when not validating as a MAC...
[freeside.git] / FS / FS / part_device.pm
1 package FS::part_device;
2
3 use strict;
4 use base qw( FS::Record FS::m2m_Common );
5 use FS::Record qw( qsearch qsearchs );
6 use FS::part_export;
7 use FS::export_device;
8
9 =head1 NAME
10
11 FS::part_device - Object methods for part_device records
12
13 =head1 SYNOPSIS
14
15   use FS::part_device;
16
17   $record = new FS::part_device \%hash;
18   $record = new FS::part_device { 'column' => 'value' };
19
20   $error = $record->insert;
21
22   $error = $new_record->replace($old_record);
23
24   $error = $record->delete;
25
26   $error = $record->check;
27
28 =head1 DESCRIPTION
29
30 An FS::part_device object represents a phone device definition. FS::part_device
31 inherits from FS::Record.  The following fields are currently supported:
32
33 =over 4
34
35 =item devicepart
36
37 primary key
38
39 =item devicename
40
41 device name (used in Freeside)
42
43 =item inventory_classnum
44
45 L<FS::inventory_class> used to track inventory of these devices.
46
47 =item title
48
49 external device name (for export)
50
51 =back
52
53 =head1 METHODS
54
55 =over 4
56
57 =item new HASHREF
58
59 Creates a new record.  To add the record to the database, see L<"insert">.
60
61 Note that this stores the hash reference, not a distinct copy of the hash it
62 points to.  You can ask the object for a copy with the I<hash> method.
63
64 =cut
65
66 # the new method can be inherited from FS::Record, if a table method is defined
67
68 sub table { 'part_device'; }
69
70 =item insert
71
72 Adds this record to the database.  If there is an error, returns the error,
73 otherwise returns false.
74
75 =cut
76
77 # the insert method can be inherited from FS::Record
78
79 =item delete
80
81 Delete this record from the database.
82
83 =cut
84
85 # the delete method can be inherited from FS::Record
86
87 =item replace OLD_RECORD
88
89 Replaces the OLD_RECORD with this one in the database.  If there is an error,
90 returns the error, otherwise returns false.
91
92 =cut
93
94 # the replace method can be inherited from FS::Record
95
96 =item check
97
98 Checks all fields to make sure this is a valid record.  If there is
99 an error, returns the error, otherwise returns false.  Called by the insert
100 and replace methods.
101
102 =cut
103
104 # the check method should currently be supplied - FS::Record contains some
105 # data checking routines
106
107 sub check {
108   my $self = shift;
109
110   my $error = 
111     $self->ut_numbern('devicepart')
112     || $self->ut_text('devicename')
113     || $self->ut_foreign_keyn('inventory_classnum', 'inventory_class', 'classnum')
114     || $self->ut_textn('title')
115   ;
116   return $error if $error;
117
118   $self->SUPER::check;
119 }
120
121 =item part_export
122
123 Returns a list of all exports (see L<FS::part_export>) for this device.
124
125 =cut
126
127 sub part_export {
128   my $self = shift;
129   map { qsearchs( 'part_export', { 'exportnum' => $_->exportnum } ) }
130     qsearch( 'export_device', { 'devicepart' => $self->devicepart } );
131 }
132
133 =item inventory_class
134
135 Returns the inventory class (see L<FS::inventory_class>) for this device, 
136 if any.
137
138 =cut
139
140 sub inventory_class {
141   my $self = shift;
142   return '' unless $self->inventory_classnum;
143   qsearchs('inventory_class', { 'classnum' => $self->inventory_classnum });
144 }
145
146 sub process_batch_import {
147   my $job = shift;
148
149   my $opt = { 'table'   => 'part_device',
150               'params'  => [],
151               'formats' => { 'default' => [ 'devicename' ] },
152               'default_csv' => 1,
153             };
154
155   FS::Record::process_batch_import( $job, $opt, @_ );
156
157 }
158
159 =back
160
161 =head1 BUGS
162
163 =head1 SEE ALSO
164
165 L<FS::Record>, schema.html from the base documentation.
166
167 =cut
168
169 1;
170