Search in sources :

Example 11 with ProdProduct

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

the class ManufOrderStockMoveService method createToProduceStockMove.

public void createToProduceStockMove(ManufOrder manufOrder) throws AxelorException {
    Company company = manufOrder.getCompany();
    if (manufOrder.getToProduceProdProductList() != null && company != null) {
        StockMove stockMove = this._createToProduceStockMove(manufOrder, company);
        for (ProdProduct prodProduct : manufOrder.getToProduceProdProductList()) {
            BigDecimal productCostPrice = prodProduct.getProduct() != null ? (BigDecimal) productCompanyService.get(prodProduct.getProduct(), "costPrice", manufOrder.getCompany()) : BigDecimal.ZERO;
            this._createStockMoveLine(prodProduct, stockMove, StockMoveLineService.TYPE_OUT_PRODUCTIONS, prodProduct.getQty(), productCostPrice);
        }
        if (stockMove.getStockMoveLineList() != null && !stockMove.getStockMoveLineList().isEmpty()) {
            stockMoveService.plan(stockMove);
            manufOrder.addOutStockMoveListItem(stockMove);
        }
        if (stockMove.getStockMoveLineList() != null) {
            for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
                manufOrder.addProducedStockMoveLineListItem(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) BigDecimal(java.math.BigDecimal)

Example 12 with ProdProduct

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

the class ManufOrderStockMoveService method createToConsumeStockMove.

public void createToConsumeStockMove(ManufOrder manufOrder) throws AxelorException {
    Company company = manufOrder.getCompany();
    SupplyChainConfig supplyChainConfig = supplyChainConfigService.getSupplyChainConfig(company);
    if (manufOrder.getToConsumeProdProductList() != null && company != null) {
        StockMove stockMove = this._createToConsumeStockMove(manufOrder, company);
        for (ProdProduct prodProduct : manufOrder.getToConsumeProdProductList()) {
            this._createStockMoveLine(prodProduct, stockMove, StockMoveLineService.TYPE_IN_PRODUCTIONS);
        }
        if (stockMove.getStockMoveLineList() != null && !stockMove.getStockMoveLineList().isEmpty()) {
            stockMoveService.plan(stockMove);
            if (supplyChainConfig.getAutoRequestReservedQtyOnManufOrder()) {
                requestStockReservation(stockMove);
            }
            manufOrder.addInStockMoveListItem(stockMove);
        }
        // case where we had to split tracked stock move lines
        if (stockMove.getStockMoveLineList() != null) {
            for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
                manufOrder.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) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) ProdProduct(com.axelor.apps.production.db.ProdProduct)

Example 13 with ProdProduct

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

the class OperationOrderServiceImpl method createToConsumeProdProductList.

@Override
public void createToConsumeProdProductList(OperationOrder operationOrder) {
    BigDecimal manufOrderQty = operationOrder.getManufOrder().getQty();
    BigDecimal bomQty = operationOrder.getManufOrder().getBillOfMaterial().getQty();
    ProdProcessLine prodProcessLine = operationOrder.getProdProcessLine();
    if (prodProcessLine.getToConsumeProdProductList() != null) {
        for (ProdProduct prodProduct : prodProcessLine.getToConsumeProdProductList()) {
            BigDecimal qty = Beans.get(ManufOrderService.class).computeToConsumeProdProductLineQuantity(bomQty, manufOrderQty, prodProduct.getQty());
            operationOrder.addToConsumeProdProductListItem(new ProdProduct(prodProduct.getProduct(), qty, prodProduct.getUnit()));
        }
    }
}
Also used : ManufOrderService(com.axelor.apps.production.service.manuforder.ManufOrderService) ProdProduct(com.axelor.apps.production.db.ProdProduct) ProdProcessLine(com.axelor.apps.production.db.ProdProcessLine) BigDecimal(java.math.BigDecimal)

Example 14 with ProdProduct

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

the class OperationOrderStockMoveService method createNewConsumedStockMoveLineList.

/**
 * Clear the consumed list and create a new one with the right quantity.
 *
 * @param operationOrder
 * @param qtyToUpdate
 */
public void createNewConsumedStockMoveLineList(OperationOrder operationOrder, BigDecimal qtyToUpdate) throws AxelorException {
    ManufOrderStockMoveService manufOrderStockMoveService = Beans.get(ManufOrderStockMoveService.class);
    // find planned stock move
    Optional<StockMove> stockMoveOpt = manufOrderStockMoveService.getPlannedStockMove(operationOrder.getInStockMoveList());
    if (!stockMoveOpt.isPresent()) {
        return;
    }
    StockMove stockMove = stockMoveOpt.get();
    stockMoveService.cancel(stockMove);
    // clear all lists from planned lines
    operationOrder.getConsumedStockMoveLineList().removeIf(stockMoveLine -> stockMoveLine.getStockMove().getStatusSelect() == StockMoveRepository.STATUS_CANCELED);
    stockMove.clearStockMoveLineList();
    // create a new list
    for (ProdProduct prodProduct : operationOrder.getToConsumeProdProductList()) {
        BigDecimal qty = manufOrderStockMoveService.getFractionQty(operationOrder.getManufOrder(), prodProduct, qtyToUpdate);
        manufOrderStockMoveService._createStockMoveLine(prodProduct, stockMove, StockMoveLineService.TYPE_IN_PRODUCTIONS, qty);
        // Update consumed StockMoveLineList with created stock move lines
        stockMove.getStockMoveLineList().stream().filter(stockMoveLine1 -> !operationOrder.getConsumedStockMoveLineList().contains(stockMoveLine1)).forEach(operationOrder::addConsumedStockMoveLineListItem);
    }
    stockMoveService.plan(stockMove);
}
Also used : Company(com.axelor.apps.base.db.Company) StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) Inject(com.google.inject.Inject) 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) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) ProdProduct(com.axelor.apps.production.db.ProdProduct) 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) OperationOrder(com.axelor.apps.production.db.OperationOrder) StockConfigProductionService(com.axelor.apps.production.service.config.StockConfigProductionService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) List(java.util.List) Beans(com.axelor.inject.Beans) ManufOrder(com.axelor.apps.production.db.ManufOrder) Optional(java.util.Optional) ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) StockMove(com.axelor.apps.stock.db.StockMove) ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) ProdProduct(com.axelor.apps.production.db.ProdProduct) BigDecimal(java.math.BigDecimal)

Example 15 with ProdProduct

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

the class ManufOrderController method multiLevelManufOrderOnLoad.

/**
 * Called from manuf order form, on clicking "Multi-level planning" button.
 *
 * @param request
 * @param response
 */
public void multiLevelManufOrderOnLoad(ActionRequest request, ActionResponse response) {
    try {
        Long moId = Long.valueOf(request.getContext().get("id").toString());
        ManufOrder mo = Beans.get(ManufOrderRepository.class).find(moId);
        boolean showOnlyMissingQty = request.getContext().get("_showOnlyMissingQty") != null && Boolean.parseBoolean(request.getContext().get("_showOnlyMissingQty").toString());
        ProdProductProductionRepository prodProductProductionRepository = Beans.get(ProdProductProductionRepository.class);
        List<ProdProduct> prodProducts = mo.getToConsumeProdProductList().stream().filter(prodProduct -> prodProduct.getProduct().getProductSubTypeSelect() == ProductRepository.PRODUCT_SUB_TYPE_FINISHED_PRODUCT || prodProduct.getProduct().getProductSubTypeSelect() == ProductRepository.PRODUCT_SUB_TYPE_SEMI_FINISHED_PRODUCT).filter(prodProduct -> !showOnlyMissingQty || prodProductProductionRepository.computeMissingQty(prodProduct.getProduct().getId(), prodProduct.getQty(), moId).compareTo(BigDecimal.ZERO) > 0).collect(Collectors.toList());
        response.setValue("$components", prodProducts);
    } 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) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) ProdProductProductionRepository(com.axelor.apps.production.service.ProdProductProductionRepository) ProdProduct(com.axelor.apps.production.db.ProdProduct) BirtException(org.eclipse.birt.core.exception.BirtException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) ManufOrder(com.axelor.apps.production.db.ManufOrder)

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