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