Search in sources :

Example 1 with Address

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

the class ConvertLeadWizardController method createContactData.

@SuppressWarnings("unchecked")
private Partner createContactData(Context context, Partner partner) throws AxelorException {
    Partner contactPartner = null;
    Integer leadToContactSelect = (Integer) context.get("leadToContactSelect");
    ConvertLeadWizardService convertLeadWizardService = Beans.get(ConvertLeadWizardService.class);
    if (leadToContactSelect == null) {
        return null;
    }
    if (leadToContactSelect == LeadRepository.CONVERT_LEAD_CREATE_CONTACT && partner.getPartnerTypeSelect() != PartnerRepository.PARTNER_TYPE_INDIVIDUAL) {
        Address primaryAddress = convertLeadWizardService.createPrimaryAddress(context);
        if (primaryAddress != null && (primaryAddress.getAddressL6() == null || primaryAddress.getAddressL7Country() == null)) {
            throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.LEAD_CONTACT_MISSING_ADDRESS));
        }
        contactPartner = convertLeadWizardService.createPartner((Map<String, Object>) context.get("contactPartner"), primaryAddress);
        contactPartner.setIsContact(true);
    // TODO check all required fields...
    } else if (leadToContactSelect == LeadRepository.CONVERT_LEAD_SELECT_CONTACT && partner.getPartnerTypeSelect() != PartnerRepository.PARTNER_TYPE_INDIVIDUAL) {
        Map<String, Object> selectContactContext = (Map<String, Object>) context.get("selectContact");
        contactPartner = Beans.get(PartnerRepository.class).find(((Integer) selectContactContext.get("id")).longValue());
    }
    return contactPartner;
}
Also used : PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) AxelorException(com.axelor.exception.AxelorException) Address(com.axelor.apps.base.db.Address) Partner(com.axelor.apps.base.db.Partner) Map(java.util.Map) ConvertLeadWizardService(com.axelor.apps.crm.service.ConvertLeadWizardService)

Example 2 with Address

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

the class ConvertLeadWizardController method createPartnerData.

@SuppressWarnings("unchecked")
private Partner createPartnerData(Context context) throws AxelorException {
    Integer leadToPartnerSelect = (Integer) context.get("leadToPartnerSelect");
    ConvertLeadWizardService convertLeadWizardService = Beans.get(ConvertLeadWizardService.class);
    Partner partner = null;
    if (leadToPartnerSelect == LeadRepository.CONVERT_LEAD_CREATE_PARTNER) {
        Address primaryAddress = convertLeadWizardService.createPrimaryAddress(context);
        if (primaryAddress != null && (primaryAddress.getAddressL6() == null || primaryAddress.getAddressL7Country() == null)) {
            throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.LEAD_PARTNER_MISSING_ADDRESS));
        }
        partner = convertLeadWizardService.createPartner((Map<String, Object>) context.get("partner"), primaryAddress);
    // TODO check all required fields...
    } else if (leadToPartnerSelect == LeadRepository.CONVERT_LEAD_SELECT_PARTNER) {
        Map<String, Object> selectPartnerContext = (Map<String, Object>) context.get("selectPartner");
        partner = Beans.get(PartnerRepository.class).find(((Integer) selectPartnerContext.get("id")).longValue());
        if (!partner.getIsCustomer()) {
            partner.setIsProspect(true);
        }
    }
    return partner;
}
Also used : PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) AxelorException(com.axelor.exception.AxelorException) Address(com.axelor.apps.base.db.Address) Partner(com.axelor.apps.base.db.Partner) Map(java.util.Map) ConvertLeadWizardService(com.axelor.apps.crm.service.ConvertLeadWizardService)

Example 3 with Address

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

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

the class MapRestCrm method getOpportunities.

@Path("/opportunity")
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonNode getOpportunities() {
    ObjectNode mainNode = factory.objectNode();
    try {
        List<? extends Opportunity> opportunities = opportunityRepo.all().fetch();
        ArrayNode arrayNode = factory.arrayNode();
        for (Opportunity opportunity : opportunities) {
            Partner partner = opportunity.getPartner();
            if (partner == null) {
                continue;
            }
            ObjectNode objectNode = factory.objectNode();
            String currencyCode = "";
            if (opportunity.getCurrency() != null) {
                currencyCode = opportunity.getCurrency().getCode();
            }
            String amtLabel = "Amount";
            if (!Strings.isNullOrEmpty(I18n.get("amount"))) {
                amtLabel = I18n.get("amount");
            }
            String amount = amtLabel + " : " + opportunity.getAmount() + " " + currencyCode;
            objectNode.put("fullName", opportunity.getName() + "<br/>" + amount);
            objectNode.put("fixedPhone", partner.getFixedPhone() != null ? partner.getFixedPhone() : " ");
            if (partner.getEmailAddress() != null) {
                objectNode.put("emailAddress", partner.getEmailAddress().getAddress());
            }
            Address address = Beans.get(PartnerService.class).getInvoicingAddress(partner);
            if (address != null) {
                String addressString = mapRestService.makeAddressString(address, objectNode);
                objectNode.put("address", addressString);
            }
            objectNode.put("pinColor", "pink");
            objectNode.put("pinChar", I18n.get(ITranslation.PIN_CHAR_OPPORTUNITY));
            arrayNode.add(objectNode);
        }
        mapRestService.setData(mainNode, arrayNode);
    } catch (Exception e) {
        mapRestService.setError(mainNode, e);
    }
    return mainNode;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Address(com.axelor.apps.base.db.Address) Opportunity(com.axelor.apps.crm.db.Opportunity) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PartnerService(com.axelor.apps.base.service.PartnerService) Partner(com.axelor.apps.base.db.Partner) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with Address

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

the class PartnerServiceImpl method checkDefaultAddress.

/**
 * Ensures that there is exactly one default invoicing address and no more than one default
 * delivery address. If the partner address list is valid, returns the default invoicing address.
 *
 * @param partner
 * @throws AxelorException
 */
protected Address checkDefaultAddress(Partner partner) throws AxelorException {
    List<PartnerAddress> partnerAddressList = partner.getPartnerAddressList();
    Address defaultInvoicingAddress = null;
    Address defaultDeliveryAddress = null;
    if (partnerAddressList != null) {
        for (PartnerAddress partnerAddress : partnerAddressList) {
            if (partnerAddress.getIsDefaultAddr() && partnerAddress.getIsInvoicingAddr()) {
                if (defaultInvoicingAddress != null) {
                    throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.ADDRESS_8));
                }
                defaultInvoicingAddress = partnerAddress.getAddress();
            }
            if (partnerAddress.getIsDefaultAddr() && partnerAddress.getIsDeliveryAddr()) {
                if (defaultDeliveryAddress != null) {
                    throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.ADDRESS_9));
                }
                defaultDeliveryAddress = partnerAddress.getAddress();
            }
        }
    }
    return defaultInvoicingAddress;
}
Also used : AxelorException(com.axelor.exception.AxelorException) 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)

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