fix 4.x upgrades when an invoice with a discount was deleted instead of voided, RT...
authorIvan Kohler <ivan@freeside.biz>
Sat, 18 Feb 2017 22:21:03 +0000 (14:21 -0800)
committerIvan Kohler <ivan@freeside.biz>
Sat, 18 Feb 2017 22:21:03 +0000 (14:21 -0800)
FS/FS/cust_bill_pkg_discount.pm

index 616657a..2a638a9 100644 (file)
@@ -2,6 +2,7 @@ package FS::cust_bill_pkg_discount;
 use base qw( FS::cust_main_Mixin FS::Record );
 
 use strict;
 use base qw( FS::cust_main_Mixin FS::Record );
 
 use strict;
+use FS::Record qw( dbh );
 
 =head1 NAME
 
 
 =head1 NAME
 
@@ -185,6 +186,19 @@ sub description {
   return $desc;
 }
 
   return $desc;
 }
 
+sub _upgrade_schema {
+  my ($class, %opts) = @_;
+
+  my $sql = '
+    DELETE FROM cust_bill_pkg_discount WHERE NOT EXISTS
+      ( SELECT 1 FROM cust_bill_pkg WHERE cust_bill_pkg.billpkgnum = cust_bill_pkg_discount.billpkgnum )
+  ';
+
+  my $sth = dbh->prepare($sql) or die dbh->errstr;
+  $sth->execute or die $sth->errstr;
+  '';
+}
+
 =back
 
 =head1 BUGS
 =back
 
 =head1 BUGS