fix 'Can't call method "setup" on an undefined value' error when using into rates...
[freeside.git] / FS / FS / part_pkg_taxproduct.pm
index 000d0d4..56e63b6 100644 (file)
@@ -1,10 +1,11 @@
 package FS::part_pkg_taxproduct;
 
 use strict;
-use vars qw( @ISA );
-use FS::Record;
+use vars qw( @ISA $delete_kludge );
+use FS::Record qw( qsearch );
 
 @ISA = qw(FS::Record);
+$delete_kludge = 0;
 
 =head1 NAME
 
@@ -79,6 +80,20 @@ 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 } );
+
+  unless ( $delete_kludge ) {
+    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,