summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2016-07-07 13:01:09 -0700
committerMark Wells <mark@freeside.biz>2016-07-07 20:21:42 -0700
commit7ba0f3f2442dbb788b3fcd50b8a9f48da80556b1 (patch)
tree26841619595f29f5251c225150ad0d8af3a54701
parent5e76080d6ca453fa4471d21e10da023f8bb03184 (diff)
enable cancel_pkgs to expire packages even if the reason is missing, #71623, from #37177
-rw-r--r--FS/FS/cust_main.pm25
1 files changed, 22 insertions, 3 deletions
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index 1b8e0330a..e4fc3db34 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -75,6 +75,7 @@ use FS::cust_attachment;
use FS::contact;
use FS::Locales;
use FS::upgrade_journal;
+use FS::reason;
# 1 is mostly method/subroutine entry and options
# 2 traces progress of some operations
@@ -2396,7 +2397,11 @@ FS::cust_pkg::cancel() methods.
=item quiet - can be set true to supress email cancellation notices.
-=item reason - can be set to a cancellation reason (see L<FS:reason>), either a reasonnum of an existing reason, or passing a hashref will create a new reason. The hashref should have the following keys: typenum - Reason type (see L<FS::reason_type>, reason - Text of the new reason.
+=item reason - can be set to a cancellation reason (see L<FS:reason>), either a
+reasonnum of an existing reason, or passing a hashref will create a new reason.
+The hashref should have the following keys:
+typenum - Reason type (see L<FS::reason_type>)
+reason - Text of the new reason.
=item cust_pkg_reason - can be an arrayref of L<FS::cust_pkg_reason> objects
for the individual packages, parallel to the C<cust_pkg> argument. The
@@ -2486,12 +2491,26 @@ sub cancel_pkgs {
if ($opt{'cust_pkg_reason'}) {
@cprs = @{ delete $opt{'cust_pkg_reason'} };
}
+ my $null_reason;
foreach (@pkgs) {
my %lopt = %opt;
if (@cprs) {
my $cpr = shift @cprs;
- $lopt{'reason'} = $cpr->reasonnum;
- $lopt{'reason_otaker'} = $cpr->otaker;
+ if ( $cpr ) {
+ $lopt{'reason'} = $cpr->reasonnum;
+ $lopt{'reason_otaker'} = $cpr->otaker;
+ } else {
+ warn "no reason found when canceling package ".$_->pkgnum."\n";
+ # we're not actually required to pass a reason to cust_pkg::cancel,
+ # but if we're getting to this point, something has gone awry.
+ $null_reason ||= FS::reason->new_or_existing(
+ reason => 'unknown reason',
+ type => 'Cancel Reason',
+ class => 'C',
+ );
+ $lopt{'reason'} = $null_reason->reasonnum;
+ $lopt{'reason_otaker'} = $FS::CurrentUser::CurrentUser->username;
+ }
}
my $error = $_->cancel(%lopt);
push @errors, 'pkgnum '.$_->pkgnum.': '.$error if $error;