-Deletes this record from the database. If there is an error, returns the
-error, otherwise returns false.
+Deletes this record from the database. If this svcpart is also the default svcpart,
+we set part_pkg.def_svcpart to NULL. If there is an error, returns the error,
+otherwise returns false.
+
+sub delete {
+ my $self = shift;
+ my $part_pkg = qsearchs( 'part_pkg', { pkgpart => $self->pkgpart } );
+
+ # Should this be wrapped in a transaction?
+ if ( $part_pkg->def_svcpart == $self->svcpart ) {
+ my $new = new FS::part_pkg $part_pkg->hash;
+ $new->def_svcpart = 0;
+ my $error = $new->replace($part_pkg);
+ return $error if $error;
+ }
+
+ $self->SUPER::delete;
+}