+sub insert {
+ my $self = shift;
+ my %options = @_;
+
+ local $SIG{HUP} = 'IGNORE';
+ local $SIG{INT} = 'IGNORE';
+ local $SIG{QUIT} = 'IGNORE';
+ local $SIG{TERM} = 'IGNORE';
+ local $SIG{TSTP} = 'IGNORE';
+ local $SIG{PIPE} = 'IGNORE';
+
+ my $oldAutoCommit = $FS::UID::AutoCommit;
+ local $FS::UID::AutoCommit = 0;
+ my $dbh = dbh;
+
+ if ( $options{'cust_location'} ) {
+ my $cust_location = $options{'cust_location'};
+ my $method = $cust_location->locationnum ? 'replace' : 'insert';
+ my $error = $cust_location->$method();
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ $self->locationnum( $cust_location->locationnum );
+ }
+
+ my @qual_option = ();
+ if ( $self->exportnum ) {
+ my $export = $self->part_export
+ or die 'Invalid exportnum';
+
+ my $qres = $export->qual($self);
+ unless ( ref($qres) ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "Qualification error: $qres";
+ }
+
+ $self->$_($qres->{$_}) foreach grep $qres->{$_}, qw(status vendor_qual_id);
+ @qual_option = ( $qres->{'options'} ) if ref($qres->{'options'});
+ }
+
+ my $error = $self->SUPER::insert(@qual_option);
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+
+ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+ '';
+}