Search in sources :

Example 1 with ProdProduct

use of com.axelor.apps.production.db.ProdProduct in project axelor-open-suite by axelor.

the class ManufOrderStockMoveService method createNewConsumedStockMoveLineList.

/**
 * Clear the consumed list and create a new one with the right quantity.
 *
 * @param manufOrder
 * @param qtyToUpdate
 */
public void createNewConsumedStockMoveLineList(ManufOrder manufOrder, BigDecimal qtyToUpdate) throws AxelorException {
    // find planned stock move
    Optional<StockMove> stockMoveOpt = getPlannedStockMove(manufOrder.getInStockMoveList());
    if (!stockMoveOpt.isPresent()) {
        return;
    }
    StockMove stockMove = stockMoveOpt.get();
    stockMoveService.cancel(stockMove);
    // clear all lists from planned lines
    manufOrder.getConsumedStockMoveLineList().removeIf(stockMoveLine -> stockMoveLine.getStockMove().getStatusSelect() == StockMoveRepository.STATUS_CANCELED);
    stockMove.clearStockMoveLineList();
    // create a new list
    for (ProdProduct prodProduct : manufOrder.getToConsumeProdProductList()) {
        BigDecimal qty = getFractionQty(manufOrder, prodProduct, qtyToUpdate);
        _createStockMoveLine(prodProduct, stockMove, StockMoveLineService.TYPE_IN_PRODUCTIONS, qty);
        // Update consumed StockMoveLineList with created stock move lines
        stockMove.getStockMoveLineList().stream().filter(stockMoveLine1 -> !manufOrder.getConsumedStockMoveLineList().contains(stockMoveLine1)).forEach(manufOrder::addConsumedStockMoveLineListItem);
    }
    stockMoveService.plan(stockMove);
}
Also used : Company(com.axelor.apps.base.db.Company) IExceptionMessage(com.axelor.apps.production.exceptions.IExceptionMessage) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) ReservedQtyService(com.axelor.apps.supplychain.service.ReservedQtyService) Inject(com.google.inject.Inject) LocalDateTime(java.time.LocalDateTime) LoggerFactory(org.slf4j.LoggerFactory) StockMoveService(com.axelor.apps.stock.service.StockMoveService) ProductCompanyService(com.axelor.apps.base.service.ProductCompanyService) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) StockLocation(com.axelor.apps.stock.db.StockLocation) CollectionUtils(org.apache.commons.collections.CollectionUtils) I18n(com.axelor.i18n.I18n) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) ProdProcess(com.axelor.apps.production.db.ProdProcess) ProdProduct(com.axelor.apps.production.db.ProdProduct) RoundingMode(java.math.RoundingMode) Logger(org.slf4j.Logger) 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) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) OperationOrder(com.axelor.apps.production.db.OperationOrder) OperationOrderRepository(com.axelor.apps.production.db.repo.OperationOrderRepository) StockConfigProductionService(com.axelor.apps.production.service.config.StockConfigProductionService) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) List(java.util.List) Beans(com.axelor.inject.Beans) ManufOrder(com.axelor.apps.production.db.ManufOrder) LocalDate(java.time.LocalDate) Optional(java.util.Optional) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) OperationOrderStockMoveService(com.axelor.apps.production.service.operationorder.OperationOrderStockMoveService) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) StockMove(com.axelor.apps.stock.db.StockMove) ProdProduct(com.axelor.apps.production.db.ProdProduct) BigDecimal(java.math.BigDecimal)

Example 2 with ProdProduct

use of com.axelor.apps.production.db.ProdProduct in project axelor-open-suite by axelor.

the class OperationOrderStockMoveService method createToConsumeStockMove.

public void createToConsumeStockMove(OperationOrder operationOrder) throws AxelorException {
    Company company = operationOrder.getManufOrder().getCompany();
    if (operationOrder.getToConsumeProdProductList() != null && company != null) {
        StockMove stockMove = this._createToConsumeStockMove(operationOrder, company);
        stockMove.setOriginId(operationOrder.getId());
        stockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_OPERATION_ORDER);
        stockMove.setOrigin(operationOrder.getOperationName());
        for (ProdProduct prodProduct : operationOrder.getToConsumeProdProductList()) {
            StockMoveLine stockMoveLine = this._createStockMoveLine(prodProduct, stockMove);
        }
        if (stockMove.getStockMoveLineList() != null && !stockMove.getStockMoveLineList().isEmpty()) {
            stockMoveService.plan(stockMove);
            operationOrder.addInStockMoveListItem(stockMove);
        }
        // case where we had to split tracked stock move lines
        if (stockMove.getStockMoveLineList() != null) {
            for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
                operationOrder.addConsumedStockMoveLineListItem(stockMoveLine);
            }
        }
    }
}
Also used : Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) ProdProduct(com.axelor.apps.production.db.ProdProduct)

Example 3 with ProdProduct

use of com.axelor.apps.production.db.ProdProduct 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 4 with ProdProduct

use of com.axelor.apps.production.db.ProdProduct 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 5 with ProdProduct

use of com.axelor.apps.production.db.ProdProduct in project axelor-open-suite by axelor.

the class ManufOrderServiceImpl method createToConsumeProdProductList.

@Override
public void createToConsumeProdProductList(ManufOrder manufOrder) {
    BigDecimal manufOrderQty = manufOrder.getQty();
    BillOfMaterial billOfMaterial = manufOrder.getBillOfMaterial();
    BigDecimal bomQty = billOfMaterial.getQty();
    if (billOfMaterial.getBillOfMaterialSet() != null) {
        for (BillOfMaterial billOfMaterialLine : getSortedBillsOfMaterials(billOfMaterial.getBillOfMaterialSet())) {
            if (!billOfMaterialLine.getHasNoManageStock()) {
                Product product = productVariantService.getProductVariant(manufOrder.getProduct(), billOfMaterialLine.getProduct());
                BigDecimal qty = computeToConsumeProdProductLineQuantity(bomQty, manufOrderQty, billOfMaterialLine.getQty());
                ProdProduct prodProduct = new ProdProduct(product, qty, billOfMaterialLine.getUnit());
                manufOrder.addToConsumeProdProductListItem(prodProduct);
                // id by order of creation
                prodProductRepo.persist(prodProduct);
            }
        }
    }
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) 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)

Aggregations

ProdProduct (com.axelor.apps.production.db.ProdProduct)17 BigDecimal (java.math.BigDecimal)13 Company (com.axelor.apps.base.db.Company)9 Product (com.axelor.apps.base.db.Product)9 StockMove (com.axelor.apps.stock.db.StockMove)8 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)8 AxelorException (com.axelor.exception.AxelorException)8 ArrayList (java.util.ArrayList)8 List (java.util.List)8 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)7 ManufOrder (com.axelor.apps.production.db.ManufOrder)7 StockLocation (com.axelor.apps.stock.db.StockLocation)7 Beans (com.axelor.inject.Beans)7 Transactional (com.google.inject.persist.Transactional)7 LocalDate (java.time.LocalDate)7 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)6 OperationOrder (com.axelor.apps.production.db.OperationOrder)6 ManufOrderRepository (com.axelor.apps.production.db.repo.ManufOrderRepository)6 IExceptionMessage (com.axelor.apps.production.exceptions.IExceptionMessage)6 I18n (com.axelor.i18n.I18n)6