Search in sources :

Example 1 with Country

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

the class ConvertLeadWizardService method createPrimaryAddress.

@SuppressWarnings("unchecked")
public Address createPrimaryAddress(Map<String, Object> context) {
    Map<String, Object> leadContext = (Map<String, Object>) context.get("_lead");
    Lead lead = Beans.get(LeadRepository.class).find(((Integer) leadContext.get("id")).longValue());
    String addressL4 = lead.getPrimaryAddress();
    if (addressL4 == null) {
        return null;
    }
    String addressL5 = lead.getPrimaryState() != null ? lead.getPrimaryState().getName() : null;
    String addressL6 = lead.getPrimaryPostalCode() + " " + (lead.getPrimaryCity() != null ? lead.getPrimaryCity().getName() : "");
    Country addressL7Country = lead.getPrimaryCountry();
    Address address = addressService.getAddress(null, null, addressL4, addressL5, addressL6, addressL7Country);
    if (address == null) {
        address = addressService.createAddress(null, null, addressL4, addressL5, addressL6, addressL7Country);
    }
    return address;
}
Also used : LeadRepository(com.axelor.apps.crm.db.repo.LeadRepository) EmailAddress(com.axelor.apps.message.db.EmailAddress) Address(com.axelor.apps.base.db.Address) Lead(com.axelor.apps.crm.db.Lead) Country(com.axelor.apps.base.db.Country) Map(java.util.Map)

Example 2 with Country

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

the class SyncContactService method createCountry.

protected Country createCountry(String googleCountry, String googleCountryCode) {
    Country country = new Country();
    country.setAlpha2Code(googleCountryCode);
    country.setName(googleCountry);
    country.setImportOrigin(importOrigin);
    return countryRepo.save(country);
}
Also used : Country(com.axelor.apps.base.db.Country)

Example 3 with Country

use of com.axelor.apps.base.db.Country 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 4 with Country

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

the class ImportBank method setCountry.

@Transactional(rollbackOn = Exception.class)
public Object setCountry(Object bean, Map<String, Object> values) throws AxelorException {
    assert bean instanceof Bank;
    Bank bank = (Bank) bean;
    String code = (String) values.get("code");
    String codeCountry = code.substring(4, 6);
    Country country = countryRepository.all().filter("self.alpha2Code = :codeCountry").bind("codeCountry", codeCountry).fetchOne();
    if (country != null) {
        bank.setCountry(country);
    }
    bankRepository.save(bank);
    return bank;
}
Also used : Bank(com.axelor.apps.base.db.Bank) Country(com.axelor.apps.base.db.Country) Transactional(com.google.inject.persist.Transactional)

Example 5 with Country

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

the class MapRestSale method getGeoMapData.

@Path("/geomap/turnover")
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonNode getGeoMapData() {
    Map<String, BigDecimal> data = new HashMap<String, BigDecimal>();
    List<? extends SaleOrder> orders = saleOrderRepo.all().filter("self.statusSelect=?", 3).fetch();
    JsonNodeFactory factory = JsonNodeFactory.instance;
    ObjectNode mainNode = factory.objectNode();
    ArrayNode arrayNode = factory.arrayNode();
    ArrayNode labelNode = factory.arrayNode();
    labelNode.add("Country");
    labelNode.add("Turnover");
    arrayNode.add(labelNode);
    for (SaleOrder so : orders) {
        Country country = so.getMainInvoicingAddress().getAddressL7Country();
        BigDecimal value = so.getExTaxTotal();
        if (country != null) {
            String key = country.getName();
            if (data.containsKey(key)) {
                BigDecimal oldValue = data.get(key);
                oldValue = oldValue.add(value);
                data.put(key, oldValue);
            } else {
                data.put(key, value);
            }
        }
    }
    Iterator<String> keys = data.keySet().iterator();
    while (keys.hasNext()) {
        String key = keys.next();
        ArrayNode dataNode = factory.arrayNode();
        dataNode.add(key);
        dataNode.add(data.get(key));
        arrayNode.add(dataNode);
    }
    mainNode.put("status", 0);
    mainNode.set("data", arrayNode);
    return mainNode;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) Country(com.axelor.apps.base.db.Country) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) SaleOrder(com.axelor.apps.sale.db.SaleOrder) BigDecimal(java.math.BigDecimal) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Country (com.axelor.apps.base.db.Country)9 Address (com.axelor.apps.base.db.Address)3 City (com.axelor.apps.base.db.City)2 EmailAddress (com.axelor.apps.message.db.EmailAddress)2 BigDecimal (java.math.BigDecimal)2 BankOrderEconomicReason (com.axelor.apps.bankpayment.db.BankOrderEconomicReason)1 BankOrderFileFormatCountry (com.axelor.apps.bankpayment.db.BankOrderFileFormatCountry)1 Bank (com.axelor.apps.base.db.Bank)1 BankDetails (com.axelor.apps.base.db.BankDetails)1 PartnerAddress (com.axelor.apps.base.db.PartnerAddress)1 Street (com.axelor.apps.base.db.Street)1 CountryRepository (com.axelor.apps.base.db.repo.CountryRepository)1 Lead (com.axelor.apps.crm.db.Lead)1 LeadRepository (com.axelor.apps.crm.db.repo.LeadRepository)1 SaleOrder (com.axelor.apps.sale.db.SaleOrder)1 AxelorException (com.axelor.exception.AxelorException)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Transactional (com.google.inject.persist.Transactional)1