time/data/etc. unit pricing add-ons, RT#24392
authorIvan Kohler <ivan@freeside.biz>
Thu, 9 Jan 2014 01:53:05 +0000 (17:53 -0800)
committerIvan Kohler <ivan@freeside.biz>
Thu, 9 Jan 2014 01:53:05 +0000 (17:53 -0800)
FS/FS/cust_pkg.pm

index a2173d9..f530947 100644 (file)
@@ -30,6 +30,7 @@ use FS::reg_code;
 use FS::part_svc;
 use FS::cust_pkg_reason;
 use FS::reason;
+use FS::cust_pkg_usageprice;
 use FS::cust_pkg_discount;
 use FS::discount;
 use FS::UI::Web;
@@ -1973,6 +1974,22 @@ sub change {
     }
   }
 
+  # transfer usage pricing add-ons, if we're not changing pkgpart
+  if ( $same_pkgpart ) {
+    foreach my $old_cust_pkg_usageprice ($self->cust_pkg_usageprice) {
+      my $new_cust_pkg_usageprice = new FS::cust_pkg_usageprice {
+        'pkgnum'         => $cust_pkg->pkgnum,
+        'usagepricepart' => $old_cust_pkg_usageprice->usagepricepart,
+        'quantity'       => $old_cust_pkg_usageprice->quantity,
+      };
+      $error = $new_cust_pkg_usageprice->insert;
+      if ( $error ) {
+        $dbh->rollback if $oldAutoCommit;
+        return "Error transferring usage pricing add-on: $error";
+      }
+    }
+  }
+
   # transfer discounts, if we're not changing pkgpart
   if ( $same_pkgpart ) {
     foreach my $old_discount ($self->cust_pkg_discount_active) {