[freeside-commits] branch master updated. d13dae1c37c36c27f1ac9fd134c5d8b3a4fb9754

Jonathan Prykop jonathan at 420.am
Tue Jun 30 01:26:37 PDT 2015


The branch, master has been updated
       via  d13dae1c37c36c27f1ac9fd134c5d8b3a4fb9754 (commit)
      from  633af1c0e996b16d0e18a7cdff05490ea7d46ca6 (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 d13dae1c37c36c27f1ac9fd134c5d8b3a4fb9754
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Tue Jun 30 03:24:08 2015 -0500

    RT#29285: State field not needed for New Zealand

diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 17030d2..b384d85 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -3383,14 +3383,6 @@ and customer address. Include units.',
   },
 
   {
-    'key'         => 'city_not_required',
-    'section'     => 'required',
-    'description' => 'Turn off requirement for a City to be entered for billing & shipping addresses',
-    'type'        => 'checkbox',
-    'per_agent'   => 1,
-  },
-
-  {
     'key'         => 'echeck-void',
     'section'     => 'deprecated',
     'description' => '<B>DEPRECATED</B>, now controlled by ACLs.  Used to enable local-only voiding of echeck payments in addition to refunds against the payment gateway',
@@ -4525,6 +4517,13 @@ and customer address. Include units.',
   },
 
   {
+    'key'         => 'cust_main-no_city_in_address',
+    'section'     => 'UI',
+    'description' => 'Turn off City for billing & shipping addresses',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'census_year',
     'section'     => 'UI',
     'description' => 'The year to use in census tract lookups.  NOTE: you need to select 2012 or 2013 for Year 2010 Census tract codes.  A selection of 2011 provides Year 2000 Census tract codes.  Use the freeside-censustract-update tool if exisitng customers need to be changed.',
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 0bdc995..24ca858 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -2009,7 +2009,7 @@ sub tables_hashref {
         'locationname',    'varchar', 'NULL', $char_d, '', '',
         'address1',        'varchar',     '', $char_d, '', '', 
         'address2',        'varchar', 'NULL', $char_d, '', '', 
-        'city',            'varchar',     '', $char_d, '', '', 
+        'city',            'varchar', 'NULL', $char_d, '', '', 
         'county',          'varchar', 'NULL', $char_d, '', '', 
         'state',           'varchar', 'NULL', $char_d, '', '', 
         'zip',             'varchar', 'NULL',      10, '', '', 
@@ -2639,7 +2639,7 @@ sub tables_hashref {
         'first',         'varchar',     '', $char_d, '', '', 
         'address1',      'varchar',     '', $char_d, '', '', 
         'address2',      'varchar', 'NULL', $char_d, '', '', 
-        'city',          'varchar',     '', $char_d, '', '', 
+        'city',          'varchar', 'NULL', $char_d, '', '', 
         'state',         'varchar', 'NULL', $char_d, '', '', 
         'zip',           'varchar', 'NULL',      10, '', '', 
         'country',          'char',     '',       2, '', '', 
diff --git a/FS/FS/UI/Web/small_custview.pm b/FS/FS/UI/Web/small_custview.pm
index 72af03e..329e5f7 100644
--- a/FS/FS/UI/Web/small_custview.pm
+++ b/FS/FS/UI/Web/small_custview.pm
@@ -129,7 +129,8 @@ sub small_custview {
     $html .= encode_entities($cust_main->address1). '<BR>';
     $html .= encode_entities($cust_main->address2). '<BR>'
       if $cust_main->address2;
-    $html .= encode_entities($cust_main->city). ', '. $cust_main->state. '  '.
+    $html .= encode_entities($cust_main->city) . ', ' if $cust_main->city;
+    $html .= $cust_main->state. '  '.
              $cust_main->zip. '<BR>';
     $html .= $cust_main->country. '<BR>'
       if $cust_main->country && $cust_main->country ne $countrydefault;
@@ -162,7 +163,7 @@ sub small_custview {
         $cust_main->ship_company,
         $ship->address1,
         $ship->address2,
-        ($ship->city . ', ' . $ship->state . '  ' . $ship->zip),
+        (($ship->city ? $ship->city . ', ' : '') . $ship->state . '  ' . $ship->zip),
         ($ship->country eq $countrydefault ? '' : $ship->country ),
     );
 
diff --git a/FS/FS/cust_location.pm b/FS/FS/cust_location.pm
index a863e5d..9ab94f2 100644
--- a/FS/FS/cust_location.pm
+++ b/FS/FS/cust_location.pm
@@ -68,7 +68,7 @@ Address line two (optional)
 
 =item city
 
-City
+City (optional only if cust_main-no_city_in_address config is set)
 
 =item county
 
@@ -149,9 +149,20 @@ sub find_or_insert {
 
   warn "find_or_insert:\n".Dumper($self) if $DEBUG;
 
-  my @essential = (qw(custnum address1 address2 city county state zip country
+  my @essential = (qw(custnum address1 address2 county state zip country
     location_number location_type location_kind disabled));
 
+  # Just in case this conf was accidentally/temporarily set,
+  # we'll never overwrite existing city; see city method
+  if ($conf->exists('cust_main-no_city_in_address')) {
+    warn "Warning: find_or_insert specified city when cust_main-no_city_in_address was configured"
+      if $self->get('city');
+    $self->set('city',''); # won't end up in %nonempty, hence old value is preserved
+  } else {
+    # otherwise, of course, city is essential
+    push(@essential,'city') 
+  }
+
   # I don't think this is necessary
   #if ( !$self->coord_auto and $self->latitude and $self->longitude ) {
   #  push @essential, qw(latitude longitude);
@@ -207,6 +218,11 @@ otherwise returns false.
 sub insert {
   my $self = shift;
 
+  # Ideally, this should never happen,
+  # but throw a warning and save the value anyway, to avoid data loss
+  warn "Warning: inserting city when cust_main-no_city_in_address is configured"
+    if $conf->exists('cust_main-no_city_in_address') && $self->get('city');
+
   if ( $self->censustract ) {
     $self->set('censusyear' => $conf->config('census_year') || 2012);
   }
@@ -271,6 +287,15 @@ sub replace {
   my $self = shift;
   my $old = shift;
   $old ||= $self->replace_old;
+
+  # Just in case this conf was accidentally/temporarily set,
+  # we'll never overwrite existing city; see city method
+  if ($conf->exists('cust_main-no_city_in_address')) {
+    warn "Warning: replace attempted to change city when cust_main-no_city_in_address was configured"
+      if $self->get('city') && ($old->get('city') != $self->get('city'));
+    $self->set('city',$old->get('city'));
+  }
+
   # the following fields are immutable
   foreach (qw(address1 address2 city state zip country)) {
     if ( $self->$_ ne $old->$_ ) {
@@ -330,7 +355,9 @@ sub check {
     || $self->ut_textn('locationname')
     || $self->ut_text('address1')
     || $self->ut_textn('address2')
-    || $self->ut_text('city')
+    || ($conf->exists('cust_main-no_city_in_address') 
+        ? $self->ut_textn('city') 
+        : $self->ut_text('city'))
     || $self->ut_textn('county')
     || $self->ut_textn('state')
     || $self->ut_country('country')
@@ -392,6 +419,30 @@ sub check {
   $self->SUPER::check;
 }
 
+=item city
+
+When the I<cust_main-no_city_in_address> config is set, the
+city method will return a blank string no matter the previously
+set value of the field.  You can still use the get method to
+access the contents of the field directly.
+
+Just in case this config was accidentally/temporarily set,
+we'll never overwrite existing city while the config is active.
+L</find_or_insert> will throw a warning if passed any true value for city,
+ignore the city field when finding, and preserve the existing value.
+L</replace> will only throw a warning if passed a true value that is 
+different than the existing value of city, and will preserve the existing value.
+L</insert> will throw a warning but still insert a true city value,
+to avoid unnecessary data loss.
+
+=cut
+
+sub city {
+  my $self = shift;
+  return '' if $conf->exists('cust_main-no_city_in_address');
+  return $self->get('city');
+}
+
 =item country_full
 
 Returns this locations's full country name
@@ -731,25 +782,29 @@ names in order.
 
 =cut
 
+### Is this actually used for anything anymore?  Grep doesn't show anything...
 sub in_county_sql {
   # replaces FS::cust_pkg::location_sql
   my ($class, %opt) = @_;
   my $ornull = $opt{ornull} ? ' OR ? IS NULL' : '';
   my $x = $ornull ? 3 : 2;
   my @fields = (('district') x 3,
-                ('city') x 3,
                 ('county') x $x,
                 ('state') x $x,
                 'country');
 
+  unless ($conf->exists('cust_main-no_city_in_address')) {
+    push( @fields, (('city') x 3) );
+  }
+
   my $text = (driver_name =~ /^mysql/i) ? 'char' : 'text';
 
   my @where = (
     "cust_location.district = ? OR ? = '' OR CAST(? AS $text) IS NULL",
-    "cust_location.city     = ? OR ? = '' OR CAST(? AS $text) IS NULL",
     "cust_location.county   = ? OR (? = '' AND cust_location.county IS NULL) $ornull",
     "cust_location.state    = ? OR (? = '' AND cust_location.state IS NULL ) $ornull",
-    "cust_location.country = ?"
+    "cust_location.country = ?",
+    "cust_location.city     = ? OR ? = '' OR CAST(? AS $text) IS NULL"
   );
   my $sql = join(' AND ', map "($_)\n", @where);
   if ( $opt{param} ) {
diff --git a/FS/FS/cust_pay_batch.pm b/FS/FS/cust_pay_batch.pm
index 13b2eef..8f31e4d 100644
--- a/FS/FS/cust_pay_batch.pm
+++ b/FS/FS/cust_pay_batch.pm
@@ -129,6 +129,8 @@ and replace methods.
 sub check {
   my $self = shift;
 
+  my $conf = new FS::Conf;
+
   my $error = 
       $self->ut_numbern('paybatchnum')
     || $self->ut_numbern('trancode') #deprecated
@@ -137,7 +139,9 @@ sub check {
     || $self->ut_number('custnum')
     || $self->ut_text('address1')
     || $self->ut_textn('address2')
-    || $self->ut_text('city')
+    || ($conf->exists('cust_main-no_city_in_address') 
+        ? $self->ut_textn('city') 
+        : $self->ut_text('city'))
     || $self->ut_textn('state')
   ;
 
diff --git a/httemplate/edit/cust_main/basics.html b/httemplate/edit/cust_main/basics.html
index e16aafa..32a03bb 100644
--- a/httemplate/edit/cust_main/basics.html
+++ b/httemplate/edit/cust_main/basics.html
@@ -46,7 +46,7 @@
 
   var ship_locked_agents = <% encode_json(\%ship_locked_agents) %>;
   var ship_fields = [
-    'locationname', 'address1', 'city', 'state', 'zip', 'country', 
+    'locationname', 'address1',<% $conf->exists('cust_main-no_city_in_address') ? '' : q( 'city',) %> 'state', 'zip', 'country', 
     'latitude', 'longitude', 'district'
   ];
 
@@ -307,7 +307,10 @@ foreach (qsearch('agent',{})) {
   my $agent_ship_location = $cust_main->ship_location;
   $ship_locked_agents{$agentnum} = +{
     map { $_ => $agent_ship_location->$_ }
-    qw(locationname address1 city state zip country latitude longitude district)
+    (
+       qw(locationname address1 state zip country latitude longitude district),
+       ($conf->exists('cust_main-no_city_in_address') ? () : 'city')
+    )
   };
 }
 
diff --git a/httemplate/elements/city.html b/httemplate/elements/city.html
index 5f4d4e0..4e9a609 100644
--- a/httemplate/elements/city.html
+++ b/httemplate/elements/city.html
@@ -159,6 +159,11 @@ my $disable_select = 1 if $conf->config('tax_district_method');
 
 $opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'});
 
+if ($conf->exists('cust_main-no_city_in_address')) {
+  $opt{'disable_text'} = 1;
+  $disable_select = 1;
+}
+
 my $text_style   = $opt{'style'} ? [ @{ $opt{'style'} } ] : [];
 my $select_style = $opt{'style'} ? [ @{ $opt{'style'} } ] : [];
 
diff --git a/httemplate/elements/location.html b/httemplate/elements/location.html
index 90f2026..b5f0a96 100644
--- a/httemplate/elements/location.html
+++ b/httemplate/elements/location.html
@@ -169,15 +169,14 @@ Example:
 
 
 <TR>
-% if ($conf->exists('city_not_required')) {
-<input type="hidden" name="<% ($select_hash{'prefix'}) ? $select_hash{'prefix'} : '' %>city" value=" "/>
-%} else {
-  <<%$th%> ALIGN="right"><%$r%><% mt('City') |h %></<%$th%>>
+  <<%$th%> ALIGN="right">
+% unless ($conf->exists('cust_main-no_city_in_address')) {
+  <% $r %><% mt('City') |h %>
+% }
+  </<%$th%>>
   <TD WIDTH="1"><% include('/elements/city.html', %select_hash, 'text_style' => \@style ) %></TD>
-
   <<%$th%> ALIGN="right" WIDTH="1" ID="<%$pre%>countylabel" <%$county_style%>><%$r%>County</<%$th%>>
   <TD WIDTH="1"><% include('/elements/select-county.html', %select_hash ) %></TD>
-% }
   <<%$th%> ALIGN="right" WIDTH="1"><%$r%><% mt('State') |h %></<%$th%>>
   <TD WIDTH="1">
     <% include('/elements/select-state.html', %select_hash ) %>
@@ -291,7 +290,7 @@ Example:
   var clear_coords_on_change = [
     '<%$pre%>address1',
     '<%$pre%>address2',
-    '<%$pre%>city',
+    <% $conf->exists('cust_main-no_city_in_address') ? '' : qq('${pre}city',) %>
     '<%$pre%>state',
     '<%$pre%>zip',
     '<%$pre%>country'
diff --git a/httemplate/elements/standardize_locations.js b/httemplate/elements/standardize_locations.js
index ff7183b..1a01daa 100644
--- a/httemplate/elements/standardize_locations.js
+++ b/httemplate/elements/standardize_locations.js
@@ -13,7 +13,7 @@ function form_address_info() {
 % }
 % for my $pre (@prefixes) {
 %   # normal case
-%   for my $field (qw(address1 address2 city state zip country)) {
+%   for my $field (qw(address1 address2 state zip country), ($conf->exists('cust_main-no_city_in_address') ? () : 'city')) {
     returnobj['<% $pre %><% $field %>'] = cf.elements['<% $pre %><% $field %>'].value;
 %   } #for $field
 %   if ( $withcensus ) {
@@ -145,7 +145,7 @@ function replace_address() {
   var clean = newaddr['<% $pre %>addr_clean'] == 'Y';
   var error = newaddr['<% $pre %>error'];
   if ( clean ) {
-%   foreach my $field (qw(address1 address2 city state zip addr_clean )) {
+%   foreach my $field (qw(address1 address2 state zip addr_clean ),($conf->exists('cust_main-no_city_in_address') ? () : 'city')) {
     cf.elements['<% $pre %><% $field %>'].value = newaddr['<% $pre %><% $field %>'];
 %   } #foreach $field
 
diff --git a/httemplate/view/cust_main/contacts.html b/httemplate/view/cust_main/contacts.html
index 22a7b95..e3d5d63 100644
--- a/httemplate/view/cust_main/contacts.html
+++ b/httemplate/view/cust_main/contacts.html
@@ -100,7 +100,7 @@
 % if ( $location->county ) {
  (<% $location->county |h %> county)\
 % }
-,<% state_label( $location->state, $location->country ) |h %>
+<% ($location->city || $location->county) ? ', ' : ''%><% state_label( $location->state, $location->country ) |h %>
   <% $location->zip %>
 </TD>
 </TR>

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

Summary of changes:
 FS/FS/Conf.pm                                |   15 +++---
 FS/FS/Schema.pm                              |    4 +-
 FS/FS/UI/Web/small_custview.pm               |    5 +-
 FS/FS/cust_location.pm                       |   67 +++++++++++++++++++++++---
 FS/FS/cust_pay_batch.pm                      |    6 ++-
 httemplate/edit/cust_main/basics.html        |    7 ++-
 httemplate/elements/city.html                |    5 ++
 httemplate/elements/location.html            |   13 +++--
 httemplate/elements/standardize_locations.js |    4 +-
 httemplate/view/cust_main/contacts.html      |    2 +-
 10 files changed, 97 insertions(+), 31 deletions(-)




More information about the freeside-commits mailing list