adding follow-tax-rename tool (well, quick hack), RT#4878
authorivan <ivan>
Sat, 21 Feb 2009 17:56:07 +0000 (17:56 +0000)
committerivan <ivan>
Sat, 21 Feb 2009 17:56:07 +0000 (17:56 +0000)
FS/FS/cust_bill_pkg.pm
bin/follow-tax-rename [new file with mode: 0644]

index d0c51cf..6c0589a 100644 (file)
@@ -30,10 +30,6 @@ FS::cust_bill_pkg - Object methods for cust_bill_pkg records
 
   $error = $record->insert;
 
-  $error = $new_record->replace($old_record);
-
-  $error = $record->delete;
-
   $error = $record->check;
 
 =head1 DESCRIPTION
@@ -182,16 +178,18 @@ sub delete {
   return "Can't delete cust_bill_pkg records!";
 }
 
-=item replace OLD_RECORD
-
-Currently unimplemented.  This would be even more of an accounting nightmare
-than deleteing the items.  Just don't do it.
-
-=cut
-
-sub replace {
-  return "Can't modify cust_bill_pkg records!";
-}
+#alas, bin/follow-tax-rename
+#
+#=item replace OLD_RECORD
+#
+#Currently unimplemented.  This would be even more of an accounting nightmare
+#than deleteing the items.  Just don't do it.
+#
+#=cut
+#
+#sub replace {
+#  return "Can't modify cust_bill_pkg records!";
+#}
 
 =item check
 
diff --git a/bin/follow-tax-rename b/bin/follow-tax-rename
new file mode 100644 (file)
index 0000000..b7536e8
--- /dev/null
@@ -0,0 +1,52 @@
+#!/usr/bin/perl
+
+use FS::UID qw( adminsuidsetup );
+use FS::Record qw( qsearch qsearchs );
+use FS::cust_bill_pkg;
+
+$FS::Record::nowarn_classload = 1;
+$FS::Record::nowarn_classload = 1;
+
+adminsuidsetup shift;
+
+my $begin = 1231876106;
+
+my @old = qsearch('h_cust_main_county', {
+  'history_action' => 'replace_old',
+  'history_date'   => { op=>'>=', value=>$begin, },
+} );
+
+foreach my $old (@old) {
+
+  my $new = qsearchs('h_cust_main_county', {
+    'history_action' => 'replace_new',
+    'history_date'   => $old->history_date,
+  });
+
+  unless ( $new ) {
+    warn "huh?  no corresponding new record found?";
+    next;
+  }
+
+  my $old_taxname = $old->taxname;
+  my $new_taxname = $new->taxname;
+
+  my @cust_bill_pkg = qsearch('cust_bill_pkg', {
+   'pkgnum'   => 0,
+   'itemdesc' => $old->taxname,
+  });
+
+  next unless @cust_bill_pkg;
+
+  warn 'fixing '. scalar(@cust_bill_pkg).
+       " dangling line items for rename $old_taxname -> $new_taxname\n";
+
+  foreach my $cust_bill_pkg ( @cust_bill_pkg ) {
+
+    $cust_bill_pkg->itemdesc( $new->taxname );
+    my $error = $cust_bill_pkg->replace;
+    die $error if $error;
+
+  }
+
+}