Search in sources :

Example 1 with Opportunity

use of com.axelor.apps.crm.db.Opportunity in project axelor-open-suite by axelor.

the class LeadServiceImpl method convertLead.

/**
 * Convert lead into a partner
 *
 * @param lead
 * @return
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
public Lead convertLead(Lead lead, Partner partner, Partner contactPartner) throws AxelorException {
    if (partner != null && contactPartner != null) {
        contactPartner = partnerRepo.save(contactPartner);
        if (partner.getContactPartnerSet() == null) {
            partner.setContactPartnerSet(new HashSet<>());
        }
        partner.getContactPartnerSet().add(contactPartner);
        contactPartner.setMainPartner(partner);
    }
    if (partner != null) {
        partner = partnerRepo.save(partner);
        lead.setPartner(partner);
    }
    for (Event event : lead.getEventList()) {
        event.setPartner(partner);
        event.setContactPartner(contactPartner);
        eventRepo.save(event);
    }
    for (Opportunity opportunity : lead.getOpportunitiesList()) {
        opportunity.setPartner(partner);
        opportunityRepo.save(opportunity);
    }
    lead.setStatusSelect(LeadRepository.LEAD_STATUS_CONVERTED);
    return leadRepo.save(lead);
}
Also used : Opportunity(com.axelor.apps.crm.db.Opportunity) Event(com.axelor.apps.crm.db.Event) Transactional(com.google.inject.persist.Transactional)

Example 2 with Opportunity

use of com.axelor.apps.crm.db.Opportunity 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 3 with Opportunity

use of com.axelor.apps.crm.db.Opportunity in project axelor-open-suite by axelor.

the class OpportunitySaleOrderController method cancelSaleOrders.

public void cancelSaleOrders(ActionRequest request, ActionResponse response) {
    Opportunity opportunity = request.getContext().asType(Opportunity.class);
    SaleOrderWorkflowService saleOrderWorkflowService = Beans.get(SaleOrderWorkflowService.class);
    if (opportunity.getSalesStageSelect() == OpportunityRepository.SALES_STAGE_CLOSED_LOST) {
        List<SaleOrder> saleOrderList = opportunity.getSaleOrderList();
        if (saleOrderList != null && !saleOrderList.isEmpty()) {
            for (SaleOrder saleOrder : saleOrderList) {
                if (saleOrder.getStatusSelect() == SaleOrderRepository.STATUS_DRAFT_QUOTATION || saleOrder.getStatusSelect() == SaleOrderRepository.STATUS_FINALIZED_QUOTATION) {
                    saleOrderWorkflowService.cancelSaleOrder(saleOrder, null, opportunity.getName());
                }
            }
        }
    }
}
Also used : SaleOrderWorkflowService(com.axelor.apps.sale.service.saleorder.SaleOrderWorkflowService) Opportunity(com.axelor.apps.crm.db.Opportunity) SaleOrder(com.axelor.apps.sale.db.SaleOrder)

Example 4 with Opportunity

use of com.axelor.apps.crm.db.Opportunity in project axelor-open-suite by axelor.

the class OpportunitySaleRepository method copy.

public Opportunity copy(Opportunity entity, boolean deep) {
    Opportunity copy = super.copy(entity, deep);
    copy.clearSaleOrderList();
    return copy;
}
Also used : Opportunity(com.axelor.apps.crm.db.Opportunity)

Example 5 with Opportunity

use of com.axelor.apps.crm.db.Opportunity in project axelor-open-suite by axelor.

the class OpportunityController method assignToMe.

public void assignToMe(ActionRequest request, ActionResponse response) {
    OpportunityService opportunityService = Beans.get(OpportunityService.class);
    OpportunityRepository opportunityRepository = Beans.get(OpportunityRepository.class);
    if (request.getContext().get("id") != null) {
        Opportunity opportunity = opportunityRepository.find((Long) request.getContext().get("id"));
        opportunity.setUser(AuthUtils.getUser());
        opportunityService.saveOpportunity(opportunity);
    } else if (ObjectUtils.notEmpty(request.getContext().get("_ids"))) {
        for (Opportunity opportunity : opportunityRepository.all().filter("id in ?1", request.getContext().get("_ids")).fetch()) {
            opportunity.setUser(AuthUtils.getUser());
            opportunityService.saveOpportunity(opportunity);
        }
    } else {
        response.setNotify(com.axelor.apps.base.exceptions.IExceptionMessage.RECORD_NONE_SELECTED);
        return;
    }
    response.setReload(true);
}
Also used : OpportunityRepository(com.axelor.apps.crm.db.repo.OpportunityRepository) Opportunity(com.axelor.apps.crm.db.Opportunity) OpportunityService(com.axelor.apps.crm.service.OpportunityService)

Aggregations

Opportunity (com.axelor.apps.crm.db.Opportunity)9 OpportunityService (com.axelor.apps.crm.service.OpportunityService)2 SaleOrder (com.axelor.apps.sale.db.SaleOrder)2 Transactional (com.google.inject.persist.Transactional)2 Address (com.axelor.apps.base.db.Address)1 Partner (com.axelor.apps.base.db.Partner)1 PartnerService (com.axelor.apps.base.service.PartnerService)1 Event (com.axelor.apps.crm.db.Event)1 OpportunityRepository (com.axelor.apps.crm.db.repo.OpportunityRepository)1 OpportunitySaleOrderService (com.axelor.apps.sale.service.saleorder.OpportunitySaleOrderService)1 SaleOrderWorkflowService (com.axelor.apps.sale.service.saleorder.SaleOrderWorkflowService)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1