1 package FS::inventory_item;
5 use FS::Record qw( dbh qsearch qsearchs );
6 use FS::cust_main_Mixin;
7 use FS::inventory_class;
10 @ISA = qw( FS::cust_main_Mixin FS::Record );
14 FS::inventory_item - Object methods for inventory_item records
18 use FS::inventory_item;
20 $record = new FS::inventory_item \%hash;
21 $record = new FS::inventory_item { 'column' => 'value' };
23 $error = $record->insert;
25 $error = $new_record->replace($old_record);
27 $error = $record->delete;
29 $error = $record->check;
33 An FS::inventory_item object represents a specific piece of (real or virtual)
34 inventory, such as a specific DID or serial number. FS::inventory_item
35 inherits from FS::Record. The following fields are currently supported:
39 =item itemnum - primary key
41 =item classnum - Inventory class (see L<FS::inventory_class>)
43 =item item - Item identifier (unique within its inventory class)
45 =item svcnum - Customer servcie (see L<FS::cust_svc>)
55 Creates a new item. To add the item to the database, see L<"insert">.
57 Note that this stores the hash reference, not a distinct copy of the hash it
58 points to. You can ask the object for a copy with the I<hash> method.
62 # the new method can be inherited from FS::Record, if a table method is defined
64 sub table { 'inventory_item'; }
68 Adds this record to the database. If there is an error, returns the error,
69 otherwise returns false.
73 # the insert method can be inherited from FS::Record
77 Delete this record from the database.
81 # the delete method can be inherited from FS::Record
83 =item replace OLD_RECORD
85 Replaces the OLD_RECORD with this one in the database. If there is an error,
86 returns the error, otherwise returns false.
90 # the replace method can be inherited from FS::Record
94 Checks all fields to make sure this is a valid item. If there is
95 an error, returns the error, otherwise returns false. Called by the insert
100 # the check method should currently be supplied - FS::Record contains some
101 # data checking routines
107 $self->ut_numbern('itemnum')
108 || $self->ut_foreign_key('classnum', 'inventory_class', 'classnum' )
109 #|| $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum' )
110 || $self->ut_agentnum_acl('agentnum', ['Configuration',
111 'Edit global inventory'] )
112 || $self->ut_text('item')
113 || $self->ut_foreign_keyn('svcnum', 'cust_svc', 'svcnum' )
115 return $error if $error;
122 Returns the customer service associated with this inventory item, if the
123 item has been used (see L<FS::cust_svc>).
129 return '' unless $self->svcnum;
130 qsearchs( 'cust_svc', { 'svcnum' => $self->svcnum } );
135 Returns the associated agent for this event, if any, as an FS::agent object.
141 qsearchs('agent', { 'agentnum' => $self->agentnum } );
150 =item process_batch_import
154 sub process_batch_import {
157 my $opt = { 'table' => 'inventory_item',
158 #'params' => [ 'itembatch', 'classnum', ],
159 'params' => [ 'classnum', 'agentnum', ],
160 'formats' => { 'default' => [ 'item' ] },
164 FS::Record::process_batch_import( $job, $opt, @_ );
172 maybe batch_import should be a regular method in FS::inventory_class
176 L<inventory_class>, L<cust_svc>, L<FS::Record>, schema.html from the base