+=item new_or_existing HASHREF
+
+Returns an existing location matching the customer and address fields in
+HASHREF, if one exists; otherwise returns a new location containing those
+fields. The following fields must match: address1, address2, city, county,
+state, zip, country, geocode, disabled. Other fields are only required
+to match if they're specified in HASHREF.
+
+The new location will not be inserted; the calling code must call C<insert>
+(or a method such as C<move_to>) to insert it, and check for errors at that
+point.
+
+=cut
+
+sub new_or_existing {
+ my $class = shift;
+ my %hash = ref($_[0]) ? %{$_[0]} : @_;
+ # if coords are empty, then it doesn't matter if they're auto or not
+ if ( !$hash{'latitude'} and !$hash{'longitude'} ) {
+ delete $hash{'coord_auto'};
+ }
+ foreach ( qw(address1 address2 city county state zip country geocode
+ disabled ) ) {
+ # empty fields match only empty fields
+ $hash{$_} = '' if !defined($hash{$_});
+ }
+ return qsearchs('cust_location', \%hash) || $class->new(\%hash);
+}
+