Search in sources :

Example 21 with Address

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

the class SyncContactService method importAddress.

protected void importAddress(Person googlePerson, Partner partner, Boolean updateContactField) {
    if (googlePerson.getAddresses() == null) {
        return;
    }
    com.google.api.services.people.v1.model.Address googleAddr = Mapper.toBean(com.google.api.services.people.v1.model.Address.class, googlePerson.getAddresses().get(0));
    // Google contact has empty address or not enough fields to create an address
    if (Strings.isNullOrEmpty(googleAddr.getCountryCode()) || Strings.isNullOrEmpty(googleAddr.getCountry()) || Strings.isNullOrEmpty(googleAddr.getStreetAddress()) || Strings.isNullOrEmpty(googleAddr.getPostalCode())) {
        return;
    }
    String query = "self.zip = '" + googleAddr.getPostalCode() + "' AND self.addressL7Country.alpha2Code = '" + googleAddr.getCountryCode() + "' AND self.addressL4 = '" + googleAddr.getStreetAddress() + "'";
    if (!Strings.isNullOrEmpty(googleAddr.getCity())) {
        query += " AND self.city.name = '" + googleAddr.getCity() + "'";
    }
    Address partnerAddr = addressRepo.all().filter(query).fetchOne();
    if (partnerAddr == null) {
        partnerAddr = createAddress(googleAddr);
    }
    if (partner.getMainAddress() == null) {
        partner.setMainAddress(partnerAddr);
        createPartnerAddress(partner, partnerAddr);
    } else {
        if (!partner.getMainAddress().equals(partnerAddr)) {
            if (updateContactField) {
                updateDescription(partner, I18n.get(SYNC_CONTACT_OLD_ADDR), partner.getMainAddress().getFullName());
                partner.setMainAddress(partnerAddr);
                createPartnerAddress(partner, partnerAddr);
            } else if (Strings.isNullOrEmpty(partner.getDescription()) || (partner.getDescription() != null && !partner.getDescription().contains(googleAddr.getStreetAddress()))) {
                updateDescription(partner, I18n.get(SYNC_CONTACT_GOOGLE_ADDR), googleAddr.getFormattedValue());
            }
        }
    }
}
Also used : EmailAddress(com.axelor.apps.message.db.EmailAddress) PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Address(com.axelor.apps.base.db.Address)

Example 22 with Address

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

the class AddressController method viewMap.

public void viewMap(ActionRequest request, ActionResponse response) {
    try {
        Address address = request.getContext().asType(Address.class);
        address = Beans.get(AddressRepository.class).find(address.getId());
        Optional<Pair<BigDecimal, BigDecimal>> latLong = Beans.get(AddressService.class).getOrUpdateLatLong(address);
        if (latLong.isPresent()) {
            MapService mapService = Beans.get(MapService.class);
            Map<String, Object> mapView = new HashMap<>();
            mapView.put("title", "Map");
            mapView.put("resource", mapService.getMapUrl(latLong.get(), address.getFullName()));
            mapView.put("viewType", "html");
            response.setView(mapView);
        } else {
            response.setFlash(String.format(I18n.get(IExceptionMessage.ADDRESS_5), address.getFullName()));
        }
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Address(com.axelor.apps.base.db.Address) AddressService(com.axelor.apps.base.service.AddressService) HashMap(java.util.HashMap) MapService(com.axelor.apps.base.service.MapService) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) Pair(org.apache.commons.lang3.tuple.Pair)

Example 23 with Address

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

the class AddressController method validate.

public void validate(ActionRequest request, ActionResponse response) {
    Address a = request.getContext().asType(Address.class);
    LOG.debug("validate a = {}", a);
    String search = a.getAddressL4() + " " + a.getAddressL6();
    Map<String, Object> retDict = Beans.get(AddressService.class).validate(Beans.get(AppBaseService.class).getAppBase().getQasWsdlUrl(), search);
    LOG.debug("validate retDict = {}", retDict);
    VerifyLevelType verifyLevel = (VerifyLevelType) retDict.get("verifyLevel");
    if (verifyLevel != null && verifyLevel.value().equals("Verified")) {
        QAAddressType address = (QAAddressType) retDict.get("qaAddress");
        String addL1;
        List<AddressLineType> addressLineType = address.getAddressLine();
        addL1 = addressLineType.get(0).getLine();
        response.setValue("addressL2", addressLineType.get(1).getLine());
        response.setValue("addressL3", addressLineType.get(2).getLine());
        response.setValue("addressL4", addressLineType.get(3).getLine());
        response.setValue("addressL5", addressLineType.get(4).getLine());
        response.setValue("addressL6", addressLineType.get(5).getLine());
        response.setValue("inseeCode", addressLineType.get(6).getLine());
        response.setValue("certifiedOk", true);
        response.setValue("pickList", new ArrayList<QAPicklistType>());
        if (addL1 != null) {
            response.setFlash("Ligne 1: " + addL1);
        }
    } else if (verifyLevel != null && (verifyLevel.value().equals("Multiple") || verifyLevel.value().equals("StreetPartial") || verifyLevel.value().equals("InteractionRequired") || verifyLevel.value().equals("PremisesPartial"))) {
        LOG.debug("retDict.verifyLevel = {}", retDict.get("verifyLevel"));
        QAPicklistType qaPicklist = (QAPicklistType) retDict.get("qaPicklist");
        List<PickListEntry> pickList = new ArrayList<>();
        if (qaPicklist != null) {
            for (PicklistEntryType p : qaPicklist.getPicklistEntry()) {
                PickListEntry e = new PickListEntry();
                e.setAddress(a);
                e.setMoniker(p.getMoniker());
                e.setScore(p.getScore().toString());
                e.setPostcode(p.getPostcode());
                e.setPartialAddress(p.getPartialAddress());
                e.setPicklist(p.getPicklist());
                pickList.add(e);
            }
        } else if (retDict.get("qaAddress") != null) {
            QAAddressType address = (QAAddressType) retDict.get("qaAddress");
            PickListEntry e = new PickListEntry();
            List<AddressLineType> addressLineType = address.getAddressLine();
            e.setAddress(a);
            e.setL2(addressLineType.get(1).getLine());
            e.setL3(addressLineType.get(2).getLine());
            e.setPartialAddress(addressLineType.get(3).getLine());
            e.setL5(addressLineType.get(4).getLine());
            e.setPostcode(addressLineType.get(5).getLine());
            e.setInseeCode(addressLineType.get(6).getLine());
            pickList.add(e);
        }
        response.setValue("certifiedOk", false);
        response.setValue("pickList", pickList);
    } else if (verifyLevel != null && verifyLevel.value().equals("None")) {
        LOG.debug("address None");
        response.setFlash(I18n.get(IExceptionMessage.ADDRESS_3));
    }
}
Also used : PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Address(com.axelor.apps.base.db.Address) PickListEntry(com.axelor.apps.base.db.PickListEntry) AddressLineType(com.qas.web_2005_02.AddressLineType) PicklistEntryType(com.qas.web_2005_02.PicklistEntryType) QAPicklistType(com.qas.web_2005_02.QAPicklistType) AddressService(com.axelor.apps.base.service.AddressService) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) VerifyLevelType(com.qas.web_2005_02.VerifyLevelType) ArrayList(java.util.ArrayList) List(java.util.List) QAAddressType(com.qas.web_2005_02.QAAddressType)

Example 24 with Address

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

the class AddressController method select.

public void select(ActionRequest request, ActionResponse response) {
    Address a = request.getContext().asType(Address.class);
    PickListEntry pickedEntry = null;
    if (!a.getPickList().isEmpty()) {
        // if (a.pickList*.selected.count { it == true} > 0)
        // pickedEntry = a.pickList.find {it.selected == true}
        pickedEntry = a.getPickList().get(0);
        LOG.debug("select pickedEntry = {}", pickedEntry);
        String moniker = pickedEntry.getMoniker();
        if (moniker != null) {
            com.qas.web_2005_02.Address address = Beans.get(AddressService.class).select(Beans.get(AppBaseService.class).getAppBase().getQasWsdlUrl(), moniker);
            LOG.debug("select address = {}", address);
            // addressL4: title="N° et Libellé de la voie"
            // addressL6: title="Code Postal - Commune"/>
            response.setValue("addressL2", address.getQAAddress().getAddressLine().get(1));
            response.setValue("addressL3", address.getQAAddress().getAddressLine().get(2));
            response.setValue("addressL4", address.getQAAddress().getAddressLine().get(3));
            response.setValue("addressL5", address.getQAAddress().getAddressLine().get(4));
            response.setValue("addressL6", address.getQAAddress().getAddressLine().get(5));
            response.setValue("inseeCode", address.getQAAddress().getAddressLine().get(6));
            response.setValue("certifiedOk", true);
            response.setValue("pickList", new ArrayList<QAPicklistType>());
        } else {
            LOG.debug("missing fields for pickedEntry: {}", pickedEntry);
            response.setValue("addressL2", pickedEntry.getL2());
            response.setValue("addressL3", pickedEntry.getL3());
            response.setValue("addressL4", pickedEntry.getPartialAddress());
            response.setValue("addressL5", pickedEntry.getL5());
            response.setValue("addressL6", pickedEntry.getPostcode());
            response.setValue("inseeCode", pickedEntry.getInseeCode());
            response.setValue("pickList", new ArrayList<QAPicklistType>());
            response.setValue("certifiedOk", true);
        }
    } else
        response.setFlash(I18n.get(IExceptionMessage.ADDRESS_4));
}
Also used : QAPicklistType(com.qas.web_2005_02.QAPicklistType) PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Address(com.axelor.apps.base.db.Address) AddressService(com.axelor.apps.base.service.AddressService) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) PickListEntry(com.axelor.apps.base.db.PickListEntry)

Example 25 with Address

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

the class IntercoServiceImpl method generateIntercoInvoice.

@Override
public Invoice generateIntercoInvoice(Invoice invoice) throws AxelorException {
    PartnerService partnerService = Beans.get(PartnerService.class);
    InvoiceRepository invoiceRepository = Beans.get(InvoiceRepository.class);
    InvoiceService invoiceService = Beans.get(InvoiceService.class);
    boolean isPurchase;
    // set the status
    int generatedOperationTypeSelect;
    int priceListRepositoryType;
    switch(invoice.getOperationTypeSelect()) {
        case InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE:
            generatedOperationTypeSelect = InvoiceRepository.OPERATION_TYPE_CLIENT_SALE;
            priceListRepositoryType = PriceListRepository.TYPE_SALE;
            isPurchase = false;
            break;
        case InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND:
            generatedOperationTypeSelect = InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND;
            priceListRepositoryType = PriceListRepository.TYPE_SALE;
            isPurchase = false;
            break;
        case InvoiceRepository.OPERATION_TYPE_CLIENT_SALE:
            generatedOperationTypeSelect = InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE;
            priceListRepositoryType = PriceListRepository.TYPE_PURCHASE;
            isPurchase = true;
            break;
        case InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND:
            generatedOperationTypeSelect = InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND;
            priceListRepositoryType = PriceListRepository.TYPE_PURCHASE;
            isPurchase = true;
            break;
        default:
            throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_MISSING_TYPE), invoice);
    }
    Company intercoCompany = findIntercoCompany(invoice.getPartner());
    Partner intercoPartner = invoice.getCompany().getPartner();
    PaymentMode intercoPaymentMode = Beans.get(PaymentModeService.class).reverseInOut(invoice.getPaymentMode());
    Address intercoAddress = partnerService.getInvoicingAddress(intercoPartner);
    BankDetails intercoBankDetails = partnerService.getDefaultBankDetails(intercoPartner);
    AccountingSituation accountingSituation = Beans.get(AccountingSituationService.class).getAccountingSituation(intercoPartner, intercoCompany);
    PriceList intercoPriceList = Beans.get(PartnerPriceListService.class).getDefaultPriceList(intercoPartner, priceListRepositoryType);
    Invoice intercoInvoice = invoiceRepository.copy(invoice, true);
    intercoInvoice.setOperationTypeSelect(generatedOperationTypeSelect);
    intercoInvoice.setCompany(intercoCompany);
    intercoInvoice.setPartner(intercoPartner);
    intercoInvoice.setAddress(intercoAddress);
    intercoInvoice.setAddressStr(Beans.get(AddressService.class).computeAddressStr(intercoAddress));
    intercoInvoice.setPaymentMode(intercoPaymentMode);
    intercoInvoice.setBankDetails(intercoBankDetails);
    Set<Invoice> invoices = invoiceService.getDefaultAdvancePaymentInvoice(intercoInvoice);
    intercoInvoice.setAdvancePaymentInvoiceSet(invoices);
    if (accountingSituation != null) {
        intercoInvoice.setInvoiceAutomaticMail(accountingSituation.getInvoiceAutomaticMail());
        intercoInvoice.setInvoiceMessageTemplate(accountingSituation.getInvoiceMessageTemplate());
        intercoInvoice.setPfpValidatorUser(accountingSituation.getPfpValidatorUser());
    }
    intercoInvoice.setPriceList(intercoPriceList);
    intercoInvoice.setInvoicesCopySelect((intercoPartner.getInvoicesCopySelect() == 0) ? DEFAULT_INVOICE_COPY : intercoPartner.getInvoicesCopySelect());
    intercoInvoice.setCreatedByInterco(true);
    intercoInvoice.setInterco(false);
    intercoInvoice.setPrintingSettings(intercoCompany.getPrintingSettings());
    if (intercoInvoice.getInvoiceLineList() != null) {
        for (InvoiceLine invoiceLine : intercoInvoice.getInvoiceLineList()) {
            invoiceLine.setInvoice(intercoInvoice);
            createIntercoInvoiceLine(invoiceLine, isPurchase);
        }
    }
    invoiceService.compute(intercoInvoice);
    intercoInvoice.setExternalReference(invoice.getInvoiceId());
    intercoInvoice = invoiceRepository.save(intercoInvoice);
    if (Beans.get(AppSupplychainService.class).getAppSupplychain().getIntercoInvoiceCreateValidated()) {
        Beans.get(InvoiceService.class).validate(intercoInvoice);
    }
    invoice.setExternalReference(intercoInvoice.getInvoiceId());
    return intercoInvoice;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) PaymentModeService(com.axelor.apps.account.service.payment.PaymentModeService) Invoice(com.axelor.apps.account.db.Invoice) Address(com.axelor.apps.base.db.Address) PartnerPriceListService(com.axelor.apps.base.service.PartnerPriceListService) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) BankDetails(com.axelor.apps.base.db.BankDetails) InvoiceService(com.axelor.apps.account.service.invoice.InvoiceService) PartnerService(com.axelor.apps.base.service.PartnerService) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) Partner(com.axelor.apps.base.db.Partner) PriceList(com.axelor.apps.base.db.PriceList) AccountingSituationService(com.axelor.apps.account.service.AccountingSituationService) PaymentMode(com.axelor.apps.account.db.PaymentMode)

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