(finally) wrap up new tax rate engine (for now)
[freeside.git] / FS / FS / part_pkg_taxproduct.pm
index 000d0d4..c66fb8c 100644 (file)
@@ -2,7 +2,7 @@ package FS::part_pkg_taxproduct;
 
 use strict;
 use vars qw( @ISA );
-use FS::Record;
+use FS::Record qw( qsearch );
 
 @ISA = qw(FS::Record);
 
@@ -79,6 +79,18 @@ Delete this record from the database.
 
 =cut
 
+sub delete {
+  my $self = shift;
+
+  return "Can't delete a tax product which has attached package tax rates!"
+    if qsearch( 'part_pkg_taxrate', { 'taxproductnum' => $self->taxproductnum } );
+
+  return "Can't delete a tax product which has attached packages!"
+    if qsearch( 'part_pkg', { 'taxproductnum' => $self->taxproductnum } );
+
+  $self->SUPER::delete(@_);
+}
+
 =item replace OLD_RECORD
 
 Replaces the OLD_RECORD with this one in the database.  If there is an error,