- return "Can't delete a tax class which has package tax overrides!"
- if qsearch( 'part_pkg_taxoverride', { 'taxclassnum' => $self->taxclassnum } );
+ # 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;
+ }