[freeside-commits] branch FREESIDE_4_BRANCH updated. 680aba630fa70add3218eabaebe2c3da86116c7e
Mark Wells
mark at 420.am
Tue Jun 7 01:21:26 PDT 2016
The branch, FREESIDE_4_BRANCH has been updated
via 680aba630fa70add3218eabaebe2c3da86116c7e (commit)
from e797703f8c893db9da8c003e41986a31cb576bcc (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 680aba630fa70add3218eabaebe2c3da86116c7e
Author: Mark Wells <mark at freeside.biz>
Date: Tue Jun 7 01:20:40 2016 -0700
when canceling all packages for a customer, remove all services in cancel weight order, #37177
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index 335ecbf..1a2255a 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -2382,6 +2382,9 @@ Always returns a list: an empty list on success or a list of errors.
sub cancel {
my( $self, %opt ) = @_;
+ my $oldAutoCommit = $FS::UID::AutoCommit;
+ local $FS::UID::AutoCommit = 0;
+
warn "$me cancel called on customer ". $self->custnum. " with options ".
join(', ', map { "$_: $opt{$_}" } keys %opt ). "\n"
if $DEBUG;
@@ -2401,7 +2404,10 @@ sub cancel {
my $ban = new FS::banned_pay $cust_payby->_new_banned_pay_hashref;
my $error = $ban->insert;
- return ( $error ) if $error;
+ if ($error) {
+ dbh->rollback if $oldAutoCommit;
+ return ( $error );
+ }
}
@@ -2409,18 +2415,54 @@ sub cancel {
my @pkgs = $self->ncancelled_pkgs;
+ # bill all packages first, so we don't lose usage, service counts for
+ # bulk billing, etc.
if ( !$opt{nobill} && $conf->exists('bill_usage_on_cancel') ) {
$opt{nobill} = 1;
my $error = $self->bill( pkg_list => [ @pkgs ], cancel => 1 );
- warn "Error billing during cancel, custnum ". $self->custnum. ": $error"
- if $error;
+ if ($error) {
+ # we should return an error and exit in this case, yes?
+ warn "Error billing during cancel, custnum ". $self->custnum. ": $error";
+ dbh->rollback if $oldAutoCommit;
+ return ( "Error billing during cancellation: $error" );
+ }
}
- warn "$me cancelling ". scalar($self->ncancelled_pkgs). "/".
- scalar(@pkgs). " packages for customer ". $self->custnum. "\n"
+ my @errors;
+ # now cancel all services, the same way we would for individual packages
+ my @cust_svc = map { $_->cust_svc } @pkgs;
+ my @sorted_cust_svc =
+ map { $_->[0] }
+ sort { $a->[1] <=> $b->[1] }
+ map { [ $_, $_->svc_x ? $_->svc_x->table_info->{'cancel_weight'} : -1 ]; }
+ @cust_svc
+ ;
+ warn "$me removing ".scalar(@sorted_cust_svc)." service(s) for customer ".
+ $self->custnum."\n"
if $DEBUG;
+ foreach my $cust_svc (@sorted_cust_svc) {
+ my $part_svc = $cust_svc->part_svc;
+ next if ( defined($part_svc) and $part_svc->preserve );
+ my $error = $cust_svc->cancel; # immediate cancel, no date option
+ push @errors, $error if $error;
+ }
+ if (@errors) {
+ # then we won't get to the point of canceling packages
+ dbh->rollback if $oldAutoCommit;
+ return @errors;
+ }
+
+ warn "$me cancelling ". scalar(@pkgs) ." package(s) for customer ".
+ $self->custnum. "\n"
+ if $DEBUG;
+
+ @errors = grep { $_ } map { $_->cancel(%opt) } @pkgs;
+ if (@errors) {
+ dbh->rollback if $oldAutoCommit;
+ return @errors;
+ }
- grep { $_ } map { $_->cancel(%opt) } $self->ncancelled_pkgs;
+ return;
}
sub _banned_pay_hashref {
-----------------------------------------------------------------------
Summary of changes:
FS/FS/cust_main.pm | 54 ++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 48 insertions(+), 6 deletions(-)
More information about the freeside-commits
mailing list