fix 'Can't call method "setup" on an undefined value' error when using into rates...
[freeside.git] / FS / FS / cust_pkg_discount.pm
index 7b6b203..a207940 100644 (file)
@@ -106,6 +106,7 @@ sub insert {
       'amount'   => $self->amount,
       'percent'  => $self->percent,
       'months'   => $self->months,
+      'setup'   => $self->setup,
       'disabled' => 'Y',
     };
     my $error = $discount->insert;
@@ -170,6 +171,9 @@ sub check {
   ;
   return $error if $error;
 
+  return "Discount does not apply to setup fees, and package has no recurring"
+    if ! $self->discount->setup && $self->cust_pkg->part_pkg->freq =~ /^0/;
+
   $self->usernum($FS::CurrentUser::CurrentUser->usernum) unless $self->usernum;
 
   $self->SUPER::check;