svc_hardware: better error messages for bad hw_addr when not validating as a MAC...
[freeside.git] / FS / FS / part_pkg_link.pm
index aee0131..5fe6f2f 100644 (file)
@@ -130,6 +130,7 @@ sub insert {
     return $error if $error;
   }
 
+  $dbh->commit if $oldAutoCommit;
   return;
 }
 
@@ -166,10 +167,18 @@ sub delete {
     $dbh->rollback if $oldAutoCommit;
     return $error;
   }
-  $dbh->commit;
+  $dbh->commit if $oldAutoCommit;
   return;
 }
 
+=item remove_linked
+
+Removes any supplemental packages that were created by this link, by canceling
+them and setting their pkglinknum to null. This should be done in preparation
+for removing the link itself.
+
+=cut
+
 sub remove_linked {
   my $self = shift;
   my $pkglinknum = $self->pkglinknum;
@@ -180,23 +189,11 @@ sub remove_linked {
   warn "expiring ".scalar(@pkgs).
        " linked packages from part_pkg_link #$pkglinknum\n";
 
-  my $reason = qsearchs('reason', { reason => $cancel_reason_text });
-  if (!$reason) {
-    # upgrade/FS::Setup created this one automatically
-    my $reason_type = qsearchs('reason_type',
-                               { type => $cancel_reason_type }
-      ) or die "default cancel reason type does not exist";
-
-    $reason = FS::reason->new({
-        reason_type => $reason_type->typenum,
-        reason      => $cancel_reason_text,
-        disabled    => 'Y',
-    });
-    $error = $reason->insert;
-    if ( $error ) {
-      return "$error (creating package cancel reason)";
-    }
-  }
+  my $reason = FS::reason->new_or_existing(
+    class => 'C',
+    type => $cancel_reason_type,
+    reason => $cancel_reason_text
+  );
 
   foreach my $pkg (@pkgs) {
     $pkg->set('pkglinknum' => '');
@@ -253,12 +250,10 @@ sub check {
     my $dst_pkg = $self->dst_pkg;
     if ( $src_pkg->freq eq '0' and $dst_pkg->freq ne '0' ) {
       return "One-time charges can't have supplemental packages."
-    } elsif ( $dst_pkg->freq ne '0' ) {
-      my $ratio = $dst_pkg->freq / $src_pkg->freq;
-      if ($ratio != int($ratio)) {
-        return "Supplemental package period (pkgpart ".$dst_pkg->pkgpart.
-               ") must be an integer multiple of main package period.";
-      }
+    } elsif ( $dst_pkg->freq == 0 ) {
+      return "The billing period of a supplemental package must be a whole number of months.";
+    } elsif ( $src_pkg->freq == 0 ) {
+      return "To have supplemental packages, the billing period of a package must be a whole number of months.";
     }
   }