[freeside-commits] branch master updated. b7f8a7cfd566881a6d89117d17e391ceb58097d4

Jonathan Prykop jonathan at 420.am
Mon Apr 18 19:48:30 PDT 2016


The branch, master has been updated
       via  b7f8a7cfd566881a6d89117d17e391ceb58097d4 (commit)
      from  9e069687732191fedeaed8ade62e4db2886429c0 (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 b7f8a7cfd566881a6d89117d17e391ceb58097d4
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Mon Apr 18 21:47:51 2016 -0500

    RT#29296: API stuff: Add new locations [change_package_location API call]

diff --git a/FS/FS/API.pm b/FS/FS/API.pm
index 32400f7..77ae03b 100644
--- a/FS/FS/API.pm
+++ b/FS/FS/API.pm
@@ -8,6 +8,7 @@ use FS::cust_location;
 use FS::cust_pay;
 use FS::cust_credit;
 use FS::cust_refund;
+use FS::cust_pkg;
 
 =head1 NAME
 
@@ -556,6 +557,57 @@ sub location_info {
   return \%return;
 }
 
+=item change_package_location
+
+Updates package location. Takes a list of keys and values 
+as paramters with the following keys: 
+
+pkgnum
+
+secret
+
+locationnum - pass this, or the following keys (don't pass both)
+
+address1
+
+address2
+
+city
+
+county
+
+state
+
+zip
+
+country
+
+On error, returns a hashref with an 'error' key.
+On success, returns a hashref with 'pkgnum' and 'locationnum' keys,
+containing the new values.
+
+=cut
+
+sub change_package_location {
+  my $self = shift;
+  my %opt  = @_;
+  return _shared_secret_error() unless _check_shared_secret($opt{'secret'});
+
+  my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $opt{'pkgnum'} })
+    or return { 'error' => 'Unknown pkgnum' };
+
+  my %changeopt;
+  $changeopt{'pkgnum'} = $pkgnum;
+
+  my $cust_location = FS::cust_location->new({
+    'custnum' => $cust_pkg->custnum,
+    %location_hash,
+  });
+  $changeopt{'cust_location'} = $cust_location;
+
+  $cust_pkg->API_change(%changeopt);
+}
+
 =item bill_now OPTION => VALUE, ...
 
 Bills a single customer now, in the same fashion as the "Bill now" link in the
diff --git a/FS/FS/cust_location.pm b/FS/FS/cust_location.pm
index 3588cee..f38e8ef 100644
--- a/FS/FS/cust_location.pm
+++ b/FS/FS/cust_location.pm
@@ -728,7 +728,7 @@ sub label_prefix {
   $prefix;
 }
 
-=item county_state_county
+=item county_state_country
 
 Returns a string consisting of just the county, state and country.
 
diff --git a/FS/FS/cust_location/API.pm b/FS/FS/cust_location/API.pm
new file mode 100644
index 0000000..7d9140f
--- /dev/null
+++ b/FS/FS/cust_location/API.pm
@@ -0,0 +1,34 @@
+package FS::cust_location::API;
+
+use strict;
+
+# this gets used by FS::cust_main::API and FS::cust_pkg::API,
+# so don't use FS::cust_main or FS::cust_pkg here
+
+# some of these could probably be included, but in general,
+# probably a bad idea to expose everything in 
+# cust_main::Location::location_fields by default
+#
+#locationname
+#district
+#latitude
+#longitude
+#censustract
+#censusyear
+#geocode
+#coord_auto
+#addr_clean
+
+sub API_editable_fields {
+  return qw(
+    address1
+    address2
+    city
+    county
+    state
+    zip
+    country
+  );
+}
+
+1;
diff --git a/FS/FS/cust_main/API.pm b/FS/FS/cust_main/API.pm
index 2d6da9e..f9ba140 100644
--- a/FS/FS/cust_main/API.pm
+++ b/FS/FS/cust_main/API.pm
@@ -4,6 +4,7 @@ use strict;
 use FS::Conf;
 use FS::part_tag;
 use FS::Record qw( qsearchs );
+use FS::cust_location::API;
 
 =item API_getinfo FIELD => VALUE, ...
 
@@ -22,9 +23,7 @@ use vars qw(
 );
 #  locale
 #  ss stateid stateid_state
- at location_editable_fields = qw(
-  address1 address2 city county state zip country
-);
+ at location_editable_fields = FS::cust_location::API::API_editable_fields();
 
 sub API_getinfo {
   my( $self, %opt ) = @_;
diff --git a/FS/FS/cust_pkg/API.pm b/FS/FS/cust_pkg/API.pm
index f87eed3..6e03b8e 100644
--- a/FS/FS/cust_pkg/API.pm
+++ b/FS/FS/cust_pkg/API.pm
@@ -2,6 +2,8 @@ package FS::cust_pkg::API;
 
 use strict;
 
+use FS::cust_location::API;
+
 sub API_getinfo {
   my $self = shift;
 
@@ -10,4 +12,50 @@ sub API_getinfo {
 
 }
 
+# currently only handles location change...
+# eventually have it handle all sorts of package changes
+sub API_change {
+  my $self = shift;
+  my %opt = @_;
+
+  return { 'error' => 'Cannot change canceled package' }
+    if $self->cancel;
+
+  my %changeopt;
+
+  # update location--accepts raw fields OR location
+  my %location_hash;
+  foreach my $field (FS::cust_location::API::API_editable_fields()) {
+    $location_hash{$field} = $opt{$field} if $opt{$field};
+  }
+  return { 'error' => 'Cannot pass both locationnum and location fields' }
+    if $opt{'locationnum'} && %location_hash;
+
+  if (%location_hash) {
+    my $cust_location = FS::cust_location->new({
+      'custnum' => $self->custnum,
+      %location_hash,
+    });
+    $changeopt{'cust_location'} = $cust_location;
+  } elsif ($opt{'locationnum'}) {
+    $changeopt{'locationnum'} = $opt{'locationnum'};
+  }
+
+  # not quite "nothing changed" because passed changes might be identical to current record,
+  #   we don't currently check for that, don't want to imply that we do...but maybe we should?
+  return { 'error' => 'No changes passed to method' }
+    unless $changeopt{'cust_location'} || $changeopt{'locationnum'};
+
+  $changeopt{'keep_dates'} = 1;
+
+  my $pkg_or_error = $self->change( \%changeopt );
+  my $error = ref($pkg_or_error) ? '' : $pkg_or_error;
+
+  return { 'error' => $error } if $error;
+
+  # return all fields?  we don't yet expose them through FS::API
+  return { map { $_ => $pkg_or_error->get($_) } qw( pkgnum locationnum ) };
+
+}
+
 1;

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/API.pm               |   52 ++++++++++++++++++++++++++++++++++++++++++++
 FS/FS/cust_location.pm     |    2 +-
 FS/FS/cust_location/API.pm |   34 +++++++++++++++++++++++++++++
 FS/FS/cust_main/API.pm     |    5 ++---
 FS/FS/cust_pkg/API.pm      |   48 ++++++++++++++++++++++++++++++++++++++++
 5 files changed, 137 insertions(+), 4 deletions(-)
 create mode 100644 FS/FS/cust_location/API.pm




More information about the freeside-commits mailing list