Search in sources :

Example 1 with City

use of com.axelor.apps.base.db.City in project axelor-open-suite by axelor.

the class SyncContactService method createAddress.

protected Address createAddress(com.google.api.services.people.v1.model.Address googleAddr) {
    Address partnerAddr = new Address();
    Country partnerCountry = countryRepo.findByName(googleAddr.getCountry());
    if (partnerCountry == null) {
        partnerCountry = createCountry(googleAddr.getCountry(), googleAddr.getCountryCode());
    }
    partnerAddr.setAddressL7Country(partnerCountry);
    if (!Strings.isNullOrEmpty(googleAddr.getCity())) {
        City partnerCity = cityRepo.findByName(googleAddr.getCity());
        if (partnerCity == null) {
            partnerCity = createCity(googleAddr.getCity(), partnerCountry);
        }
        partnerAddr.setCity(partnerCity);
    }
    StringBuilder addrL4 = new StringBuilder();
    if (!Strings.isNullOrEmpty(googleAddr.getPoBox())) {
        addrL4.append(googleAddr.getPoBox()).append(" - ");
    }
    partnerAddr.setZip(googleAddr.getPostalCode());
    addrL4.append(googleAddr.getStreetAddress());
    partnerAddr.setAddressL4(addrL4.toString());
    partnerAddr.setAddressL5(googleAddr.getCity());
    partnerAddr.setAddressL2(googleAddr.getExtendedAddress());
    partnerAddr.setAddressL6(googleAddr.getPostalCode() + " " + googleAddr.getCity());
    partnerAddr.setFullName(Beans.get(AddressService.class).computeFullName(partnerAddr));
    partnerAddr.setImportOrigin(importOrigin);
    return partnerAddr;
}
Also used : EmailAddress(com.axelor.apps.message.db.EmailAddress) PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Address(com.axelor.apps.base.db.Address) Country(com.axelor.apps.base.db.Country) City(com.axelor.apps.base.db.City)

Example 2 with City

use of com.axelor.apps.base.db.City in project axelor-open-suite by axelor.

the class ImportCity method importCity.

public Object importCity(Object bean, Map<String, Object> values) {
    assert bean instanceof City;
    City city = (City) bean;
    LOG.debug(city.getName());
    if (city.getCountry() == null || city.getName() == null) {
        return null;
    } else {
        try {
            if (city.getCanton() != null) {
                city.getCanton().setDepartment(city.getDepartment());
            }
        } catch (Exception e) {
            LOG.error("Error when importing city : {}", city.getName(), e);
        }
    }
    return city;
}
Also used : City(com.axelor.apps.base.db.City)

Example 3 with City

use of com.axelor.apps.base.db.City in project axelor-open-suite by axelor.

the class SyncContactService method createCity.

protected City createCity(String googleCity, Country country) {
    City city = new City();
    city.setName(googleCity);
    city.setCountry(country);
    city.setImportOrigin(importOrigin);
    return cityRepo.save(city);
}
Also used : City(com.axelor.apps.base.db.City)

Example 4 with City

use of com.axelor.apps.base.db.City 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);
        }
    }
}
Also used : Country(com.axelor.apps.base.db.Country) Street(com.axelor.apps.base.db.Street) City(com.axelor.apps.base.db.City)

Aggregations

City (com.axelor.apps.base.db.City)4 Country (com.axelor.apps.base.db.Country)2 Address (com.axelor.apps.base.db.Address)1 PartnerAddress (com.axelor.apps.base.db.PartnerAddress)1 Street (com.axelor.apps.base.db.Street)1 EmailAddress (com.axelor.apps.message.db.EmailAddress)1