Search in sources :

Example 6 with Address

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

the class PartnerServiceImpl method updatePartnerAddress.

/**
 * Updates M2O and O2M fields of partner that manage partner addresses. This method ensures
 * consistency between these two fields.
 *
 * @param partner
 * @throws AxelorException
 */
protected void updatePartnerAddress(Partner partner) throws AxelorException {
    Address address = partner.getMainAddress();
    if (!partner.getIsContact() && !partner.getIsEmployee()) {
        if (partner.getPartnerAddressList() != null) {
            partner.setMainAddress(checkDefaultAddress(partner));
        }
    } else if (address == null) {
        partner.removePartnerAddressListItem(JPA.all(PartnerAddress.class).filter("self.partner = :partnerId AND self.isDefaultAddr = 't'").bind("partnerId", partner.getId()).fetchOne());
    } else if (partner.getPartnerAddressList() != null && partner.getPartnerAddressList().stream().map(PartnerAddress::getAddress).noneMatch(address::equals)) {
        PartnerAddress mainAddress = new PartnerAddress();
        mainAddress.setAddress(address);
        mainAddress.setIsDefaultAddr(true);
        mainAddress.setIsDeliveryAddr(true);
        mainAddress.setIsInvoicingAddr(true);
        partner.addPartnerAddressListItem(mainAddress);
    }
}
Also used : EmailAddress(com.axelor.apps.message.db.EmailAddress) PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Address(com.axelor.apps.base.db.Address) PartnerAddress(com.axelor.apps.base.db.PartnerAddress)

Example 7 with Address

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

the class MapRestServiceImpl method setData.

@Override
public void setData(ObjectNode mainNode, ArrayNode arrayNode) throws AxelorException, JSONException {
    mainNode.put("status", 0);
    mainNode.set("data", arrayNode);
    Optional<Address> optionalAddress = Beans.get(UserService.class).getUserActiveCompanyAddress();
    if (optionalAddress.isPresent()) {
        Optional<Pair<BigDecimal, BigDecimal>> latLong = Beans.get(AddressService.class).getOrUpdateLatLong(optionalAddress.get());
        if (latLong.isPresent()) {
            JsonNodeFactory factory = JsonNodeFactory.instance;
            ObjectNode objectNode = factory.objectNode();
            objectNode.put("lat", latLong.get().getLeft());
            objectNode.put("lng", latLong.get().getRight());
            mainNode.set("company", objectNode);
        }
    }
}
Also used : Address(com.axelor.apps.base.db.Address) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) UserService(com.axelor.apps.base.service.user.UserService) Pair(org.apache.commons.lang3.tuple.Pair) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 8 with Address

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

the class AddressServiceImpl method createAddress.

@Override
public Address createAddress(String addressL2, String addressL3, String addressL4, String addressL5, String addressL6, Country addressL7Country) {
    Address address = new Address();
    address.setAddressL2(addressL2);
    address.setAddressL3(addressL3);
    address.setAddressL4(addressL4);
    address.setAddressL5(addressL5);
    address.setAddressL6(addressL6);
    address.setAddressL7Country(addressL7Country);
    return address;
}
Also used : PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Address(com.axelor.apps.base.db.Address)

Example 9 with Address

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

the class AddressServiceImpl method export.

@Override
public int export(String path) throws IOException {
    List<Address> addresses = addressRepo.all().filter("self.certifiedOk IS FALSE").fetch();
    CSVWriter csv = new CSVWriter(new java.io.FileWriter(path), "|".charAt(0), CSVWriter.NO_QUOTE_CHARACTER);
    List<String> header = new ArrayList<>();
    header.add("Id");
    header.add("AddressL1");
    header.add("AddressL2");
    header.add("AddressL3");
    header.add("AddressL4");
    header.add("AddressL5");
    header.add("AddressL6");
    header.add("CodeINSEE");
    csv.writeNext(header.toArray(new String[header.size()]));
    List<String> items = new ArrayList<>();
    for (Address a : addresses) {
        items.add(a.getId() != null ? a.getId().toString() : "");
        items.add(a.getAddressL2() != null ? a.getAddressL2() : "");
        items.add(a.getAddressL3() != null ? a.getAddressL3() : "");
        items.add(a.getAddressL4() != null ? a.getAddressL4() : "");
        items.add(a.getAddressL5() != null ? a.getAddressL5() : "");
        items.add(a.getAddressL6() != null ? a.getAddressL6() : "");
        items.add(a.getInseeCode() != null ? a.getInseeCode() : "");
        csv.writeNext(items.toArray(new String[items.size()]));
        items.clear();
    }
    csv.close();
    LOG.info("{} exported", path);
    return addresses.size();
}
Also used : PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Address(com.axelor.apps.base.db.Address) ArrayList(java.util.ArrayList) CSVWriter(com.opencsv.CSVWriter)

Example 10 with Address

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

the class AddressController method createPartnerAddress.

public void createPartnerAddress(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    Context parentContext = context.getParent();
    if (parentContext.isEmpty()) {
        return;
    }
    String parentModel = (String) parentContext.get("_model");
    LOG.debug("Create partner address : Parent model = {}", parentModel);
    String partnerField = PartnerAddressRepository.modelPartnerFieldMap.get(parentModel);
    LOG.debug("Create partner address : Parent field = {}", partnerField);
    Partner partner = null;
    if (parentContext.get(partnerField) instanceof Partner) {
        partner = (Partner) parentContext.get(partnerField);
    } else if (parentContext.get(partnerField) instanceof Map) {
        partner = Mapper.toBean(Partner.class, (Map<String, Object>) parentContext.get(partnerField));
    }
    LOG.debug("Create partner address : Partner = {}", partner);
    if (partner == null || partner.getId() == null) {
        return;
    }
    Address address = context.asType(Address.class);
    PartnerAddress partnerAddress = Beans.get(PartnerAddressRepository.class).all().filter("self.partner.id = ? AND self.address.id = ?", partner.getId(), address.getId()).fetchOne();
    LOG.debug("Create partner address : Partner Address = {}", partnerAddress);
    if (partnerAddress == null) {
        partner = Beans.get(PartnerRepository.class).find(partner.getId());
        address = Beans.get(AddressRepository.class).find(address.getId());
        Boolean invoicing = (Boolean) context.get("isInvoicingAddr");
        if (invoicing == null) {
            invoicing = false;
        }
        Boolean delivery = (Boolean) context.get("isDeliveryAddr");
        if (delivery == null) {
            delivery = false;
        }
        Boolean isDefault = (Boolean) context.get("isDefault");
        if (isDefault == null) {
            isDefault = false;
        }
        PartnerService partnerService = Beans.get(PartnerService.class);
        partnerService.addPartnerAddress(partner, address, isDefault, invoicing, delivery);
        partnerService.savePartner(partner);
    }
}
Also used : Context(com.axelor.rpc.Context) PartnerAddressRepository(com.axelor.apps.base.db.repo.PartnerAddressRepository) PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Address(com.axelor.apps.base.db.Address) PartnerAddress(com.axelor.apps.base.db.PartnerAddress) PartnerService(com.axelor.apps.base.service.PartnerService) Partner(com.axelor.apps.base.db.Partner) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Address (com.axelor.apps.base.db.Address)32 PartnerAddress (com.axelor.apps.base.db.PartnerAddress)18 AxelorException (com.axelor.exception.AxelorException)15 Partner (com.axelor.apps.base.db.Partner)13 AddressService (com.axelor.apps.base.service.AddressService)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)7 EmailAddress (com.axelor.apps.message.db.EmailAddress)6 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)6 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 PartnerService (com.axelor.apps.base.service.PartnerService)5 Map (java.util.Map)4 Invoice (com.axelor.apps.account.db.Invoice)3 Company (com.axelor.apps.base.db.Company)3 Country (com.axelor.apps.base.db.Country)3 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)3 StockMove (com.axelor.apps.stock.db.StockMove)3 BigDecimal (java.math.BigDecimal)3 ArrayList (java.util.ArrayList)3