Search in sources :

Example 21 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class StockMoveServiceImpl method computeMasses.

private void computeMasses(StockMove stockMove) throws AxelorException {
    StockConfig stockConfig = stockMove.getCompany().getStockConfig();
    Unit endUnit = stockConfig != null ? stockConfig.getCustomsMassUnit() : null;
    boolean massesRequiredForStockMove = false;
    List<StockMoveLine> stockMoveLineList = stockMove.getStockMoveLineList();
    if (stockMoveLineList == null) {
        return;
    }
    UnitConversionService unitConversionService = Beans.get(UnitConversionService.class);
    for (StockMoveLine stockMoveLine : stockMoveLineList) {
        Product product = stockMoveLine.getProduct();
        boolean massesRequiredForStockMoveLine = stockMoveLineService.checkMassesRequired(stockMove, stockMoveLine);
        if (product == null || !ProductRepository.PRODUCT_TYPE_STORABLE.equals(product.getProductTypeSelect())) {
            continue;
        }
        BigDecimal netMass = stockMoveLine.getNetMass();
        if (netMass.signum() == 0) {
            Unit startUnit = product.getMassUnit();
            if (startUnit != null && endUnit != null) {
                netMass = unitConversionService.convert(startUnit, endUnit, product.getNetMass(), product.getNetMass().scale(), null);
                stockMoveLine.setNetMass(netMass);
            }
        }
        if (netMass.signum() != 0) {
            BigDecimal totalNetMass = netMass.multiply(stockMoveLine.getRealQty());
            stockMoveLine.setTotalNetMass(totalNetMass);
        } else if (massesRequiredForStockMoveLine) {
            throw new AxelorException(stockMove, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.STOCK_MOVE_18));
        }
        if (!massesRequiredForStockMove && massesRequiredForStockMoveLine) {
            massesRequiredForStockMove = true;
        }
    }
    if (massesRequiredForStockMove && endUnit == null) {
        throw new AxelorException(stockMove, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.STOCK_MOVE_17));
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) StockConfig(com.axelor.apps.stock.db.StockConfig) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Example 22 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class StockMoveServiceImpl method updateProductNetMass.

@Override
@Transactional
public void updateProductNetMass(StockMove stockMove) throws AxelorException {
    if (stockMove.getStockMoveLineList() != null) {
        for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
            if (stockMoveLine.getProduct() != null) {
                Product product = productRepository.find(stockMoveLine.getProduct().getId());
                stockMoveLine.setNetMass(product.getNetMass());
                stockMoveLineRepo.save(stockMoveLine);
            }
        }
    }
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product) Transactional(com.google.inject.persist.Transactional)

Example 23 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class ManufOrderServiceImpl method createToProduceProdProductList.

@Override
public void createToProduceProdProductList(ManufOrder manufOrder) {
    BigDecimal manufOrderQty = manufOrder.getQty();
    BillOfMaterial billOfMaterial = manufOrder.getBillOfMaterial();
    BigDecimal bomQty = billOfMaterial.getQty();
    // add the produced product
    manufOrder.addToProduceProdProductListItem(new ProdProduct(manufOrder.getProduct(), manufOrderQty, billOfMaterial.getUnit()));
    // Add the residual products
    if (appProductionService.getAppProduction().getManageResidualProductOnBom() && billOfMaterial.getProdResidualProductList() != null) {
        for (ProdResidualProduct prodResidualProduct : billOfMaterial.getProdResidualProductList()) {
            Product product = productVariantService.getProductVariant(manufOrder.getProduct(), prodResidualProduct.getProduct());
            BigDecimal qty = bomQty.signum() != 0 ? prodResidualProduct.getQty().multiply(manufOrderQty).divide(bomQty, appBaseService.getNbDecimalDigitForQty(), RoundingMode.HALF_UP) : BigDecimal.ZERO;
            manufOrder.addToProduceProdProductListItem(new ProdProduct(product, qty, prodResidualProduct.getUnit()));
        }
    }
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) ProdResidualProduct(com.axelor.apps.production.db.ProdResidualProduct) Product(com.axelor.apps.base.db.Product) ProdResidualProduct(com.axelor.apps.production.db.ProdResidualProduct) ProdProduct(com.axelor.apps.production.db.ProdProduct) ProdProduct(com.axelor.apps.production.db.ProdProduct) BigDecimal(java.math.BigDecimal)

Example 24 with Product

use of com.axelor.apps.base.db.Product 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 25 with Product

use of com.axelor.apps.base.db.Product 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)

Aggregations

Product (com.axelor.apps.base.db.Product)189 BigDecimal (java.math.BigDecimal)91 AxelorException (com.axelor.exception.AxelorException)70 Transactional (com.google.inject.persist.Transactional)45 ArrayList (java.util.ArrayList)38 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)33 Company (com.axelor.apps.base.db.Company)24 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)24 Unit (com.axelor.apps.base.db.Unit)23 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)23 HashMap (java.util.HashMap)20 BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)19 StockLocation (com.axelor.apps.stock.db.StockLocation)19 List (java.util.List)19 ProdProduct (com.axelor.apps.production.db.ProdProduct)18 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)18 LocalDate (java.time.LocalDate)18 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)16 StockMove (com.axelor.apps.stock.db.StockMove)16 Map (java.util.Map)16