use of com.axelor.apps.base.db.Street in project axelor-open-suite by axelor.
the class AddressServiceImpl method autocompleteAddress.
@Override
public void autocompleteAddress(Address address) {
String zip = address.getZip();
if (zip == null) {
return;
}
Country country = address.getAddressL7Country();
List<City> cities = cityRepository.findByZipAndCountry(zip, country).fetch();
City city = cities.size() == 1 ? cities.get(0) : null;
address.setCity(city);
address.setAddressL6(city != null ? zip + " " + city.getName() : null);
if (appBaseService.getAppBase().getStoreStreets()) {
List<Street> streets = streetRepository.all().filter("self.city = :city").bind("city", city).fetch();
if (streets.size() == 1) {
Street street = streets.get(0);
address.setStreet(street);
String name = street.getName();
String num = address.getStreetNumber();
address.setAddressL4(num != null ? num + " " + name : name);
} else {
address.setStreet(null);
address.setAddressL4(null);
}
}
}