Search in sources :

Example 21 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class ProductCategoryServiceImpl method fetchParentCategoryList.

public List<ProductCategory> fetchParentCategoryList(ProductCategory productCategory) throws AxelorException {
    // security in case of code error to avoid infinite loop
    int i = 0;
    List<ProductCategory> parentProductCategoryList = new ArrayList<>();
    if (productCategory.getId() != null) {
        productCategory = productCategoryRepository.find(productCategory.getId());
    }
    ProductCategory parentProductCategory = productCategory.getParentProductCategory();
    while (parentProductCategory != null && i < MAX_ITERATION) {
        if (parentProductCategoryList.contains(parentProductCategory) || parentProductCategory.equals(productCategory)) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PRODUCT_CATEGORY_PARENTS_CIRCULAR_DEPENDENCY), parentProductCategory.getCode());
        }
        parentProductCategoryList.add(parentProductCategory);
        parentProductCategory = parentProductCategory.getParentProductCategory();
        i++;
    }
    return parentProductCategoryList;
}
Also used : AxelorException(com.axelor.exception.AxelorException) ProductCategory(com.axelor.apps.base.db.ProductCategory) ArrayList(java.util.ArrayList)

Example 22 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class ProductCategoryServiceImpl method fetchChildrenCategoryList.

public List<ProductCategory> fetchChildrenCategoryList(ProductCategory productCategory) throws AxelorException {
    // security in case of code error to avoid infinite loop
    int i = 0;
    List<ProductCategory> descendantsProductCategoryList = new ArrayList<>();
    if (productCategory.getId() == null) {
        // if product category is not saved, then it cannot have children
        return descendantsProductCategoryList;
    }
    List<ProductCategory> childrenProductCategoryList = fetchChildren(productCategory);
    while (!childrenProductCategoryList.isEmpty() && i < MAX_ITERATION) {
        List<ProductCategory> nextChildrenProductCategoryList = new ArrayList<>();
        for (ProductCategory childProductCategory : childrenProductCategoryList) {
            if (descendantsProductCategoryList.contains(childProductCategory) || childProductCategory.equals(productCategory)) {
                throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PRODUCT_CATEGORY_CHILDREN_CIRCULAR_DEPENDENCY), childProductCategory.getCode());
            }
            descendantsProductCategoryList.add(childProductCategory);
            nextChildrenProductCategoryList.addAll(fetchChildren(childProductCategory));
        }
        childrenProductCategoryList.clear();
        childrenProductCategoryList.addAll(nextChildrenProductCategoryList);
        nextChildrenProductCategoryList.clear();
        i++;
    }
    return descendantsProductCategoryList;
}
Also used : AxelorException(com.axelor.exception.AxelorException) ProductCategory(com.axelor.apps.base.db.ProductCategory) ArrayList(java.util.ArrayList)

Example 23 with AxelorException

use of com.axelor.exception.AxelorException 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 24 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class ConvertLeadWizardController method convertLead.

@SuppressWarnings("unchecked")
public void convertLead(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        Map<String, Object> leadContext = (Map<String, Object>) context.get("_lead");
        Lead lead = Beans.get(LeadRepository.class).find(((Integer) leadContext.get("id")).longValue());
        Partner partner = createPartnerData(context);
        Partner contactPartner = null;
        if (partner != null) {
            contactPartner = createContactData(context, partner);
        }
        try {
            lead = Beans.get(LeadService.class).convertLead(lead, partner, contactPartner);
        } catch (Exception e) {
            TraceBackService.trace(e);
        }
        if (lead.getPartner() == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.CONVERT_LEAD_ERROR));
        }
        openPartner(response, lead);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) LeadRepository(com.axelor.apps.crm.db.repo.LeadRepository) AxelorException(com.axelor.exception.AxelorException) Lead(com.axelor.apps.crm.db.Lead) Map(java.util.Map) Partner(com.axelor.apps.base.db.Partner) AxelorException(com.axelor.exception.AxelorException)

Example 25 with AxelorException

use of com.axelor.exception.AxelorException 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

AxelorException (com.axelor.exception.AxelorException)546 Transactional (com.google.inject.persist.Transactional)126 BigDecimal (java.math.BigDecimal)118 ArrayList (java.util.ArrayList)84 IOException (java.io.IOException)73 Product (com.axelor.apps.base.db.Product)64 Company (com.axelor.apps.base.db.Company)63 LocalDate (java.time.LocalDate)58 Partner (com.axelor.apps.base.db.Partner)48 List (java.util.List)45 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)40 HashMap (java.util.HashMap)38 Invoice (com.axelor.apps.account.db.Invoice)33 StockMove (com.axelor.apps.stock.db.StockMove)32 Map (java.util.Map)31 Beans (com.axelor.inject.Beans)30 I18n (com.axelor.i18n.I18n)28 Inject (com.google.inject.Inject)28 MoveLine (com.axelor.apps.account.db.MoveLine)27 Context (com.axelor.rpc.Context)27