Search in sources :

Example 1 with ConvertLeadWizardService

use of com.axelor.apps.crm.service.ConvertLeadWizardService 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 ConvertLeadWizardService

use of com.axelor.apps.crm.service.ConvertLeadWizardService 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)

Aggregations

Address (com.axelor.apps.base.db.Address)2 Partner (com.axelor.apps.base.db.Partner)2 PartnerRepository (com.axelor.apps.base.db.repo.PartnerRepository)2 ConvertLeadWizardService (com.axelor.apps.crm.service.ConvertLeadWizardService)2 AxelorException (com.axelor.exception.AxelorException)2 Map (java.util.Map)2