fix 'Can't call method "setup" on an undefined value' error when using into rates...
[freeside.git] / FS / FS / cust_pkg_discount.pm
index 3770a2b..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;
@@ -165,10 +166,16 @@ sub check {
     || $self->ut_float('months_used') #actually decimal, but this will do
     || $self->ut_numbern('end_date')
     || $self->ut_alphan('otaker')
+    || $self->ut_numbern('usernum')
     || $self->ut_enum('disabled', [ '', 'Y' ] )
   ;
   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;
 }