diff options
author | Mark Wells <mark@freeside.biz> | 2014-10-22 11:57:32 -0700 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2014-10-22 11:57:32 -0700 |
commit | 70322c9412a97ab97582d76baeae00b9117c8a12 (patch) | |
tree | 4280215f6384d9364577dfca4ad50840820aa32f /FS/FS/cust_svc.pm | |
parent | e47e15d130dc68ce1bcf6caa2a60b6788b115049 (diff) |
ensure relocate export always runs exactly once, #14049
Diffstat (limited to 'FS/FS/cust_svc.pm')
-rw-r--r-- | FS/FS/cust_svc.pm | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/FS/FS/cust_svc.pm b/FS/FS/cust_svc.pm index f499bef..96409c3 100644 --- a/FS/FS/cust_svc.pm +++ b/FS/FS/cust_svc.pm @@ -334,15 +334,34 @@ sub replace { #trigger a relocate export on location changes if ( $new->cust_pkg->locationnum != $old->cust_pkg->locationnum ) { - $error ||= $new->svc_x->export('relocate', - $new->cust_pkg->cust_location, - $old->cust_pkg->cust_location, + my $svc_x = $new->svc_x; + if ( $svc_x->locationnum ) { + if ( $svc_x->locationnum == $old->cust_pkg->locationnum ) { + # in this case, set the service location to be the same as the new + # package location + $svc_x->set('locationnum', $new->cust_pkg->locationnum); + # and replace it, which triggers a relocate export so we don't + # need to + $error ||= $svc_x->replace; + } else { + # the service already has a different location from its package + # so don't change it + } + } else { + # the service doesn't have a locationnum (either isn't of a type + # that has the locationnum field, or the locationnum is null and + # defaults to cust_pkg->locationnum) + # so just trigger the export here + $error ||= $new->svc_x->export('relocate', + $new->cust_pkg->cust_location, + $old->cust_pkg->cust_location, ); - } + } # if ($svc_x->locationnum) + } # if this is a location change if ( $error ) { $dbh->rollback if $oldAutoCommit; - return $error if $error; + return $error if $error } $dbh->commit or die $dbh->errstr if $oldAutoCommit; |