[freeside-commits] freeside/FS/FS Schema.pm, 1.149, 1.150 part_pkg_taxclass.pm, 1.2, 1.3
Ivan,,,
ivan at wavetail.420.am
Tue Jun 30 12:38:59 PDT 2009
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv2795/FS/FS
Modified Files:
Schema.pm part_pkg_taxclass.pm
Log Message:
disabling a taxclass, RT#5472
Index: part_pkg_taxclass.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg_taxclass.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- part_pkg_taxclass.pm 20 Feb 2008 01:19:45 -0000 1.2
+++ part_pkg_taxclass.pm 30 Jun 2009 19:38:57 -0000 1.3
@@ -2,8 +2,9 @@
use strict;
use vars qw( @ISA );
-use FS::UID qw(dbh);
-use FS::Record qw( qsearch qsearchs );
+use FS::UID qw( dbh );
+use FS::Record; # qw( qsearch qsearchs );
+use FS::cust_main_county;
@ISA = qw(FS::Record);
@@ -41,6 +42,10 @@
Tax class
+=item disabled
+
+Disabled flag, empty or 'Y'
+
=back
=head1 METHODS
@@ -67,7 +72,57 @@
=cut
-# the insert method can be inherited from FS::Record
+sub insert {
+ my $self = shift;
+
+ 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;
+
+ my $error = $self->SUPER::insert;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+
+ my $sth = dbh->prepare("
+ SELECT country, state, county FROM cust_main_county
+ WHERE taxclass IS NOT NULL AND taxclass != ''
+ GROUP BY country, state, county
+ ") or die dbh->errstr;
+ $sth->execute or die $sth->errstr;
+
+ while ( my $row = $sth->fetchrow_hashref ) {
+ #warn "inserting for $row";
+ my $cust_main_county = new FS::cust_main_county {
+ 'country' => $row->{country},
+ 'state' => $row->{state},
+ 'county' => $row->{county},
+ 'tax' => 0,
+ 'taxclass' => $self->taxclass,
+ #exempt_amount
+ #taxname
+ #setuptax
+ #recurtax
+ };
+ $error = $cust_main_county->insert;
+ #last if $error;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ }
+
+ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+ '';
+}
=item delete
@@ -84,7 +139,18 @@
=cut
-# the replace method can be inherited from FS::Record
+sub replace {
+ my $new = shift;
+
+ my $old = ( blessed($_[0]) && $_[0]->isa('FS::Record') )
+ ? shift
+ : $new->replace_old;
+
+ return "Can't change tax class name (disable and create anew)"
+ if $old->taxclass ne $new->taxclass;
+
+ $new->SUPER::replace(@_);
+}
=item check
@@ -103,6 +169,7 @@
my $error =
$self->ut_numbern('taxclassnum')
|| $self->ut_text('taxclass')
+ || $self->ut_enum('disabled', [ '', 'Y' ] )
;
return $error if $error;
Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.149
retrieving revision 1.150
diff -u -d -r1.149 -r1.150
--- Schema.pm 30 Jun 2009 12:28:36 -0000 1.149
+++ Schema.pm 30 Jun 2009 19:38:57 -0000 1.150
@@ -1253,10 +1253,11 @@
'columns' => [
'taxclassnum', 'serial', '', '', '', '',
'taxclass', 'varchar', '', $char_d, '', '',
+ 'disabled', 'char', 'NULL', 1, '', '',
],
'primary_key' => 'taxclassnum',
'unique' => [ [ 'taxclass' ] ],
- 'index' => [],
+ 'index' => [ [ 'disabled' ] ],
},
'part_pkg_taxproduct' => {
More information about the freeside-commits
mailing list