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);
}
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;
}
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());
}
}
}
}
}
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;
}
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);
}
Aggregations