Search in sources :

Example 96 with AxelorException

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

the class OperationOrderWorkflowService method getMachineSetupDuration.

public long getMachineSetupDuration(OperationOrder operationOrder) throws AxelorException {
    ProdProcessLine prodProcessLine = operationOrder.getProdProcessLine();
    long duration = 0;
    WorkCenter workCenter = prodProcessLine.getWorkCenter();
    if (workCenter == null) {
        return 0;
    }
    int workCenterTypeSelect = workCenter.getWorkCenterTypeSelect();
    if (workCenterTypeSelect == WorkCenterRepository.WORK_CENTER_TYPE_MACHINE || workCenterTypeSelect == WorkCenterRepository.WORK_CENTER_TYPE_BOTH) {
        Machine machine = workCenter.getMachine();
        if (machine == null) {
            throw new AxelorException(workCenter, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.WORKCENTER_NO_MACHINE), workCenter.getName());
        }
        duration += machine.getStartingDuration();
        duration += machine.getEndingDuration();
        duration += machine.getSetupDuration();
    }
    return duration;
}
Also used : AxelorException(com.axelor.exception.AxelorException) WorkCenter(com.axelor.apps.production.db.WorkCenter) ProdProcessLine(com.axelor.apps.production.db.ProdProcessLine) Machine(com.axelor.apps.production.db.Machine)

Example 97 with AxelorException

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

the class ManufOrderServiceImpl method createDiffProdProductList.

@Override
public List<ProdProduct> createDiffProdProductList(List<ProdProduct> prodProductList, List<StockMoveLine> stockMoveLineList) throws AxelorException {
    List<ProdProduct> diffConsumeList = new ArrayList<>();
    for (ProdProduct prodProduct : prodProductList) {
        Product product = prodProduct.getProduct();
        Unit newUnit = prodProduct.getUnit();
        List<StockMoveLine> stockMoveLineProductList = stockMoveLineList.stream().filter(stockMoveLine1 -> stockMoveLine1.getProduct() != null).filter(stockMoveLine1 -> stockMoveLine1.getProduct().equals(product)).collect(Collectors.toList());
        if (stockMoveLineProductList.isEmpty()) {
            StockMoveLine stockMoveLine = new StockMoveLine();
            stockMoveLineProductList.add(stockMoveLine);
        }
        BigDecimal diffQty = computeDiffQty(prodProduct, stockMoveLineProductList, product);
        BigDecimal plannedQty = prodProduct.getQty();
        BigDecimal realQty = diffQty.add(plannedQty);
        if (diffQty.compareTo(BigDecimal.ZERO) != 0) {
            ProdProduct diffProdProduct = new ProdProduct();
            diffProdProduct.setQty(diffQty);
            diffProdProduct.setPlannedQty(plannedQty);
            diffProdProduct.setRealQty(realQty);
            diffProdProduct.setProduct(product);
            diffProdProduct.setUnit(newUnit);
            diffConsumeList.add(diffProdProduct);
        }
    }
    // There are stock move lines with products that are not available in
    // prod product list. It needs to appear in the prod product list
    List<StockMoveLine> stockMoveLineMissingProductList = stockMoveLineList.stream().filter(stockMoveLine1 -> stockMoveLine1.getProduct() != null).filter(stockMoveLine1 -> !prodProductList.stream().map(ProdProduct::getProduct).collect(Collectors.toList()).contains(stockMoveLine1.getProduct())).collect(Collectors.toList());
    for (StockMoveLine stockMoveLine : stockMoveLineMissingProductList) {
        if (stockMoveLine.getQty().compareTo(BigDecimal.ZERO) != 0) {
            ProdProduct diffProdProduct = new ProdProduct();
            diffProdProduct.setQty(stockMoveLine.getQty());
            diffProdProduct.setPlannedQty(BigDecimal.ZERO);
            diffProdProduct.setRealQty(stockMoveLine.getQty());
            diffProdProduct.setProduct(stockMoveLine.getProduct());
            diffProdProduct.setUnit(stockMoveLine.getUnit());
            diffConsumeList.add(diffProdProduct);
        }
    }
    return diffConsumeList;
}
Also used : StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) IExceptionMessage(com.axelor.apps.production.exceptions.IExceptionMessage) ProductionConfig(com.axelor.apps.production.db.ProductionConfig) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) ProductCompanyService(com.axelor.apps.base.service.ProductCompanyService) Transactional(com.google.inject.persist.Transactional) BigDecimal(java.math.BigDecimal) Pair(org.apache.commons.lang3.tuple.Pair) BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) ProductVariantService(com.axelor.apps.base.service.ProductVariantService) SaleOrder(com.axelor.apps.sale.db.SaleOrder) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) ProductionConfigService(com.axelor.apps.production.service.config.ProductionConfigService) StockLocationService(com.axelor.apps.stock.service.StockLocationService) RoundingMode(java.math.RoundingMode) ProdProcessLine(com.axelor.apps.production.db.ProdProcessLine) StockConfig(com.axelor.apps.stock.db.StockConfig) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) Set(java.util.Set) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) StringUtils(com.axelor.common.StringUtils) Collectors(java.util.stream.Collectors) SequenceService(com.axelor.apps.base.service.administration.SequenceService) List(java.util.List) Product(com.axelor.apps.base.db.Product) ManufOrder(com.axelor.apps.production.db.ManufOrder) ProdResidualProduct(com.axelor.apps.production.db.ProdResidualProduct) Optional(java.util.Optional) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) Joiner(com.google.common.base.Joiner) Company(com.axelor.apps.base.db.Company) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) ProdProductRepository(com.axelor.apps.production.db.repo.ProdProductRepository) LocalDateTime(java.time.LocalDateTime) StockMoveService(com.axelor.apps.stock.service.StockMoveService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AxelorException(com.axelor.exception.AxelorException) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) StockLocation(com.axelor.apps.stock.db.StockLocation) I18n(com.axelor.i18n.I18n) ProdProcess(com.axelor.apps.production.db.ProdProcess) ProdProduct(com.axelor.apps.production.db.ProdProduct) ProductionOrder(com.axelor.apps.production.db.ProductionOrder) StringTool(com.axelor.apps.tool.StringTool) Sequence(com.axelor.apps.base.db.Sequence) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) MoreObjects(com.google.common.base.MoreObjects) OperationOrder(com.axelor.apps.production.db.OperationOrder) StockConfigProductionService(com.axelor.apps.production.service.config.StockConfigProductionService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Beans(com.axelor.inject.Beans) Unit(com.axelor.apps.base.db.Unit) OperationOrderService(com.axelor.apps.production.service.operationorder.OperationOrderService) Comparator(java.util.Comparator) OperationOrderStockMoveService(com.axelor.apps.production.service.operationorder.OperationOrderStockMoveService) Collections(java.util.Collections) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) ProdResidualProduct(com.axelor.apps.production.db.ProdResidualProduct) ProdProduct(com.axelor.apps.production.db.ProdProduct) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) ProdProduct(com.axelor.apps.production.db.ProdProduct) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Example 98 with AxelorException

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

the class ManufOrderServiceImpl method generateAllSubManufOrder.

/**
 * Called by generateMultiLevelManufOrder controller to generate all manuf order for a given bill
 * of material list from a given manuf order.
 *
 * @param billOfMaterialList
 * @param manufOrder
 * @throws AxelorException
 * @return
 */
public List<ManufOrder> generateAllSubManufOrder(List<Product> productList, ManufOrder manufOrder) throws AxelorException {
    List<ManufOrder> moList = new ArrayList<>();
    Set<Product> productManufactured = new HashSet<>();
    List<Pair<BillOfMaterial, BigDecimal>> childBomList = getToConsumeSubBomList(manufOrder.getBillOfMaterial(), manufOrder, productList);
    // prevent infinite loop
    int depth = 0;
    while (!childBomList.isEmpty()) {
        if (depth >= 25) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CHILD_BOM_TOO_MANY_ITERATION));
        }
        List<Pair<BillOfMaterial, BigDecimal>> tempChildBomList = new ArrayList<>();
        for (Pair<BillOfMaterial, BigDecimal> childBomPair : childBomList) {
            BillOfMaterial childBom = childBomPair.getLeft();
            BigDecimal qtyRequested = childBomPair.getRight();
            if (productManufactured.contains(childBom.getProduct())) {
                continue;
            }
            manufOrder = generateManufOrder(childBom.getProduct(), qtyRequested.multiply(childBom.getQty()), childBom.getPriority(), IS_TO_INVOICE, childBom, null, manufOrder.getPlannedStartDateT(), ORIGIN_TYPE_OTHER);
            moList.add(manufOrder);
            productManufactured.add(childBom.getProduct());
            tempChildBomList.addAll(getToConsumeSubBomList(childBom, manufOrder, null));
        }
        childBomList.clear();
        childBomList.addAll(tempChildBomList);
        tempChildBomList.clear();
        depth++;
    }
    return moList;
}
Also used : AxelorException(com.axelor.exception.AxelorException) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) ProdResidualProduct(com.axelor.apps.production.db.ProdResidualProduct) ProdProduct(com.axelor.apps.production.db.ProdProduct) BigDecimal(java.math.BigDecimal) BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) ManufOrder(com.axelor.apps.production.db.ManufOrder) HashSet(java.util.HashSet) Pair(org.apache.commons.lang3.tuple.Pair)

Example 99 with AxelorException

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

the class CostSheetLineServiceImpl method getComponentCostPrice.

protected BigDecimal getComponentCostPrice(Product product, int componentsValuationMethod, Company company) throws AxelorException {
    BigDecimal price = null;
    Currency companyCurrency = company.getCurrency();
    if (componentsValuationMethod == ProductRepository.COMPONENTS_VALUATION_METHOD_AVERAGE) {
        price = weightedAveragePriceService.computeAvgPriceForCompany(product, company);
        if (price == null || price.compareTo(BigDecimal.ZERO) == 0) {
            price = (BigDecimal) productCompanyService.get(product, "costPrice", company);
        }
    } else if (componentsValuationMethod == ProductRepository.COMPONENTS_VALUATION_METHOD_COST) {
        price = (BigDecimal) productCompanyService.get(product, "costPrice", company);
        if (price == null || price.compareTo(BigDecimal.ZERO) == 0) {
            price = weightedAveragePriceService.computeAvgPriceForCompany(product, company);
        }
    }
    if (product.getPurchasable() && (price == null || price.compareTo(BigDecimal.ZERO) == 0)) {
        price = (BigDecimal) productCompanyService.get(product, "purchasePrice", company);
        price = unitConversionService.convert(product.getUnit(), product.getPurchasesUnit() != null ? product.getPurchasesUnit() : product.getUnit(), price, appProductionService.getNbDecimalDigitForUnitPrice(), product);
        BigDecimal shippingCoef = shippingCoefService.getShippingCoef(product, (Partner) productCompanyService.get(product, "defaultSupplierPartner", company), company, new BigDecimal(9999999));
        price = price.multiply(shippingCoef);
        if (productCompanyService.get(product, "purchaseCurrency", company) == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MISSING_PRODUCT_PURCHASE_CURRENCY), product.getFullName());
        }
        price = currencyService.getAmountCurrencyConvertedAtDate((Currency) productCompanyService.get(product, "purchaseCurrency", company), companyCurrency, price, appProductionService.getTodayDate(company));
        if (price == null || price.compareTo(BigDecimal.ZERO) == 0) {
            @SuppressWarnings("unchecked") List<SupplierCatalog> supplierCatalogList = (List<SupplierCatalog>) productCompanyService.get(product, "supplierCatalogList", company);
            for (SupplierCatalog supplierCatalog : supplierCatalogList) {
                if (BigDecimal.ZERO.compareTo(supplierCatalog.getPrice()) < 0) {
                    price = unitConversionService.convert(product.getUnit(), product.getPurchasesUnit() != null ? product.getPurchasesUnit() : product.getUnit(), supplierCatalog.getPrice(), appProductionService.getNbDecimalDigitForUnitPrice(), product);
                    Partner supplierPartner = supplierCatalog.getSupplierPartner();
                    if (supplierPartner != null) {
                        shippingCoef = shippingCoefService.getShippingCoef(product, supplierPartner, company, new BigDecimal(9999999));
                        price = price.multiply(shippingCoef);
                        price = currencyService.getAmountCurrencyConvertedAtDate(supplierPartner.getCurrency(), companyCurrency, price, appProductionService.getTodayDate(company));
                    }
                    break;
                }
            }
        }
    }
    return price;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Currency(com.axelor.apps.base.db.Currency) SupplierCatalog(com.axelor.apps.purchase.db.SupplierCatalog) ArrayList(java.util.ArrayList) List(java.util.List) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal)

Example 100 with AxelorException

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

the class ManufOrderController method generateMultiLevelManufOrder.

/**
 * Called from multi-level-planing-wizard-form, on clicking "Generate MO" button.
 *
 * @param request
 * @param response
 */
@SuppressWarnings("unchecked")
public void generateMultiLevelManufOrder(ActionRequest request, ActionResponse response) {
    try {
        Long moId = Long.valueOf(request.getContext().get("id").toString());
        ManufOrder mo = Beans.get(ManufOrderRepository.class).find(moId);
        ProdProductRepository prodProductRepository = Beans.get(ProdProductRepository.class);
        List<ProdProduct> prodProductList = ((List<LinkedHashMap<String, Object>>) request.getContext().get("components")).stream().filter(map -> (boolean) map.get("selected")).map(map -> prodProductRepository.find(Long.valueOf(map.get("id").toString()))).collect(Collectors.toList());
        if (prodProductList.isEmpty()) {
            throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.NO_PRODUCT_SELECTED));
        }
        List<Product> selectedProductList = new ArrayList<>();
        for (ProdProduct prod : prodProductList) {
            if (selectedProductList.contains(prod.getProduct())) {
                throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.DUPLICATE_PRODUCT_SELECTED));
            }
            selectedProductList.add(prod.getProduct());
        }
        List<ManufOrder> moList = Beans.get(ManufOrderService.class).generateAllSubManufOrder(selectedProductList, mo);
        response.setCanClose(true);
        response.setView(ActionView.define(I18n.get("Manufacturing orders")).model(ManufOrder.class.getName()).add("grid", "generated-manuf-order-grid").add("form", "manuf-order-form").param("popup", "true").param("popup-save", "false").param("show-toolbar", "false").param("show-confirm", "false").domain("self.id in (" + StringTool.getIdListString(moList) + ")").map());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : IExceptionMessage(com.axelor.apps.production.exceptions.IExceptionMessage) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) BirtException(org.eclipse.birt.core.exception.BirtException) CostSheetRepository(com.axelor.apps.production.db.repo.CostSheetRepository) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) ActionView(com.axelor.meta.schema.actions.ActionView) ProdProductRepository(com.axelor.apps.production.db.repo.ProdProductRepository) LoggerFactory(org.slf4j.LoggerFactory) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) ActionResponse(com.axelor.rpc.ActionResponse) I18n(com.axelor.i18n.I18n) ManufOrderService(com.axelor.apps.production.service.manuforder.ManufOrderService) ActionRequest(com.axelor.rpc.ActionRequest) ProdProductProductionRepository(com.axelor.apps.production.service.ProdProductProductionRepository) ProdProduct(com.axelor.apps.production.db.ProdProduct) StringTool(com.axelor.apps.tool.StringTool) ManufOrderPrintService(com.axelor.apps.production.service.manuforder.ManufOrderPrintService) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) MethodHandles(java.lang.invoke.MethodHandles) CostSheet(com.axelor.apps.production.db.CostSheet) TraceBackService(com.axelor.exception.service.TraceBackService) IOException(java.io.IOException) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Collectors(java.util.stream.Collectors) ManufOrderWorkflowService(com.axelor.apps.production.service.manuforder.ManufOrderWorkflowService) List(java.util.List) IReport(com.axelor.apps.production.report.IReport) CostSheetService(com.axelor.apps.production.service.costsheet.CostSheetService) ReportSettings(com.axelor.apps.report.engine.ReportSettings) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) ManufOrder(com.axelor.apps.production.db.ManufOrder) ReportFactory(com.axelor.apps.ReportFactory) LocalDate(java.time.LocalDate) ObjectUtils(com.axelor.common.ObjectUtils) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) Context(com.axelor.rpc.Context) ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) Singleton(com.google.inject.Singleton) ManufOrderService(com.axelor.apps.production.service.manuforder.ManufOrderService) AxelorException(com.axelor.exception.AxelorException) ArrayList(java.util.ArrayList) ProdProduct(com.axelor.apps.production.db.ProdProduct) Product(com.axelor.apps.base.db.Product) ProdProduct(com.axelor.apps.production.db.ProdProduct) BirtException(org.eclipse.birt.core.exception.BirtException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) ProdProductRepository(com.axelor.apps.production.db.repo.ProdProductRepository) ManufOrder(com.axelor.apps.production.db.ManufOrder)

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