summaryrefslogtreecommitdiff
path: root/FS/FS/tax_class.pm
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2014-08-30 18:20:52 -0700
committerMark Wells <mark@freeside.biz>2014-08-30 18:20:52 -0700
commit60dc4fe638eb9abc5a3ea92d43031dcbfeb71454 (patch)
tree7afb7557490089633abb2b26ac0301bf2b352c49 /FS/FS/tax_class.pm
parent5ef5203cb6da8e0a8e1f60228b9a9250605f404e (diff)
enable CCH update to remove tax classes, #30670
Diffstat (limited to 'FS/FS/tax_class.pm')
-rw-r--r--FS/FS/tax_class.pm70
1 files changed, 28 insertions, 42 deletions
diff --git a/FS/FS/tax_class.pm b/FS/FS/tax_class.pm
index d68e7e3..04e9d37 100644
--- a/FS/FS/tax_class.pm
+++ b/FS/FS/tax_class.pm
@@ -85,52 +85,38 @@ Delete this record from the database.
sub delete {
my $self = shift;
- return "Can't delete a tax class which has package tax rates!"
- if qsearch( 'part_pkg_taxrate', { 'taxclassnumtaxed' => $self->taxclassnum } );
-
- return "Can't delete a tax class which has package tax overrides!"
- if qsearch( 'part_pkg_taxoverride', { 'taxclassnum' => $self->taxclassnum } );
-
- 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;
-
- foreach my $tax_rate (
- qsearch( 'tax_rate', { taxclassnum=>$self->taxclassnum } )
- ) {
- my $error = $tax_rate->delete;
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return $error;
- }
+ #return "Can't delete a tax class which has package tax rates!"
+ #if qsearch( 'part_pkg_taxrate', { 'taxclassnumtaxed' => $self->taxclassnum
+ # If this tax class is manually assigned to a package,
+ # then return a useful error message instead of just having a conniption.
+ my @overrides = qsearch( 'part_pkg_taxoverride', {
+ 'taxclassnum' => $self->taxclassnum
+ } );
+ if (@overrides) {
+ return "Tried to delete tax class " . $self->taxclass .
+ ", which is assigned to package definition " .
+ join(', ', map { '#'.$_->pkgpart} @overrides) .
+ ".";
}
- foreach my $part_pkg_taxrate (
- qsearch( 'part_pkg_taxrate', { taxclassnum=>$self->taxclassnum } )
- ) {
- my $error = $part_pkg_taxrate->delete;
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return $error;
- }
+ # part_pkg_taxrate.taxclass identifies taxes belonging to this taxclass.
+ # part_pkg_taxrate.taxclassnumtaxed identifies taxes applying to this
+ # taxclass.
+ # If this taxclass goes away, remove all of them. (CCH upgrade CAN'T
+ # remove them, because it removes the tax_class first and then doesn't
+ # know what the taxclassnum was. Yeah, I know. So it will just skip
+ # over them at the TXMATRIX stage.)
+ my @part_pkg_taxrate = (
+ qsearch('part_pkg_taxrate', { 'taxclassnum' => $self->taxclassnum }),
+ qsearch('part_pkg_taxrate', { 'taxclassnumtaxed' => $self->taxclassnum })
+ );
+ foreach (@part_pkg_taxrate) {
+ my $error = $_->delete;
+ return "when deleting taxclass ".$self->taxclass.": $error"
+ if $error;
}
- my $error = $self->SUPER::delete(@_);
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return $error;
- }
-
- $dbh->commit or die $dbh->errstr if $oldAutoCommit;
-
- '';
+ $self->SUPER::delete(@_);
}