Search in sources :

Example 41 with OperationOrder

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

the class OperationOrderStockMoveService method partialFinish.

/**
 * Allows to create and realize in stock moves for the given operation order. This method is used
 * during a partial finish.
 *
 * @param operationOrder
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
public void partialFinish(OperationOrder operationOrder) throws AxelorException {
    ManufOrderStockMoveService manufOrderStockMoveService = Beans.get(ManufOrderStockMoveService.class);
    ManufOrder manufOrder = operationOrder.getManufOrder();
    Company company = manufOrder.getCompany();
    StockConfigProductionService stockConfigService = Beans.get(StockConfigProductionService.class);
    StockConfig stockConfig = stockConfigService.getStockConfig(company);
    StockLocation fromStockLocation;
    StockLocation toStockLocation;
    List<StockMove> stockMoveList;
    stockMoveList = operationOrder.getInStockMoveList();
    fromStockLocation = manufOrderStockMoveService.getDefaultStockLocation(manufOrder, company, ManufOrderStockMoveService.STOCK_LOCATION_IN);
    toStockLocation = stockConfigService.getProductionVirtualStockLocation(stockConfig, operationOrder.getManufOrder().getProdProcess().getOutsourcing());
    // realize current stock move
    Optional<StockMove> stockMoveToRealize = stockMoveList.stream().filter(stockMove -> stockMove.getStatusSelect() == StockMoveRepository.STATUS_PLANNED && !CollectionUtils.isEmpty(stockMove.getStockMoveLineList())).findFirst();
    if (stockMoveToRealize.isPresent()) {
        manufOrderStockMoveService.finishStockMove(stockMoveToRealize.get());
    }
    // generate new stock move
    StockMove newStockMove = stockMoveService.createStockMove(null, null, company, fromStockLocation, toStockLocation, null, operationOrder.getPlannedStartDateT().toLocalDate(), null, StockMoveRepository.TYPE_INTERNAL);
    newStockMove.setOrigin(operationOrder.getOperationName());
    newStockMove.setOriginId(operationOrder.getId());
    newStockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_OPERATION_ORDER);
    newStockMove.setStockMoveLineList(new ArrayList<>());
    createNewStockMoveLines(operationOrder, newStockMove);
    if (!newStockMove.getStockMoveLineList().isEmpty()) {
        // plan the stockmove
        stockMoveService.plan(newStockMove);
        operationOrder.addInStockMoveListItem(newStockMove);
        newStockMove.getStockMoveLineList().forEach(operationOrder::addConsumedStockMoveLineListItem);
        operationOrder.clearDiffConsumeProdProductList();
    }
}
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) Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) StockConfig(com.axelor.apps.stock.db.StockConfig) StockLocation(com.axelor.apps.stock.db.StockLocation) StockConfigProductionService(com.axelor.apps.production.service.config.StockConfigProductionService) ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) ManufOrder(com.axelor.apps.production.db.ManufOrder) Transactional(com.google.inject.persist.Transactional)

Example 42 with OperationOrder

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

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

the class CostSheetServiceImpl method computeRealHumanResourceCost.

protected void computeRealHumanResourceCost(OperationOrder operationOrder, int priority, int bomLevel, CostSheetLine parentCostSheetLine, LocalDate previousCostSheetDate) throws AxelorException {
    if (operationOrder.getProdHumanResourceList() != null) {
        Long duration = 0L;
        if (parentCostSheetLine.getCostSheet().getCalculationTypeSelect() == CostSheetRepository.CALCULATION_END_OF_PRODUCTION || parentCostSheetLine.getCostSheet().getCalculationTypeSelect() == CostSheetRepository.CALCULATION_PARTIAL_END_OF_PRODUCTION) {
            Period period = previousCostSheetDate != null ? Period.between(parentCostSheetLine.getCostSheet().getCalculationDate(), previousCostSheetDate) : null;
            duration = period != null ? Long.valueOf(period.getDays() * 24) : operationOrder.getRealDuration();
        } else if (parentCostSheetLine.getCostSheet().getCalculationTypeSelect() == CostSheetRepository.CALCULATION_WORK_IN_PROGRESS) {
            BigDecimal ratio = costSheet.getManufOrderProducedRatio();
            Long plannedDuration = DurationTool.getSecondsDuration(Duration.between(operationOrder.getPlannedStartDateT(), operationOrder.getPlannedEndDateT())) * ratio.longValue();
            Long totalPlannedDuration = 0L;
            for (OperationOrder manufOperationOrder : operationOrder.getManufOrder().getOperationOrderList()) {
                if (manufOperationOrder.equals(operationOrder)) {
                    totalPlannedDuration += manufOperationOrder.getPlannedDuration();
                }
            }
            duration = Math.abs(totalPlannedDuration - plannedDuration);
        }
        for (ProdHumanResource prodHumanResource : operationOrder.getProdHumanResourceList()) {
            this.computeRealHumanResourceCost(prodHumanResource, operationOrder.getWorkCenter(), priority, bomLevel, parentCostSheetLine, duration);
        }
    }
}
Also used : ProdHumanResource(com.axelor.apps.production.db.ProdHumanResource) Period(java.time.Period) OperationOrder(com.axelor.apps.production.db.OperationOrder) BigDecimal(java.math.BigDecimal)

Example 44 with OperationOrder

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

the class MrpServiceProductionImpl method createManufOrderMrpLines.

@Transactional(rollbackOn = { Exception.class })
protected void createManufOrderMrpLines(Mrp mrp, ManufOrder manufOrder, MrpLineType manufOrderMrpLineType, MrpLineType manufOrderNeedMrpLineType) throws AxelorException {
    StockLocation stockLocation = manufOrder.getProdProcess().getStockLocation();
    LocalDate maturityDate = null;
    if (manufOrder.getPlannedEndDateT() != null) {
        maturityDate = manufOrder.getPlannedEndDateT().toLocalDate();
    } else {
        maturityDate = manufOrder.getPlannedStartDateT().toLocalDate();
    }
    maturityDate = this.computeMaturityDate(maturityDate, manufOrderMrpLineType);
    for (ProdProduct prodProduct : manufOrder.getToProduceProdProductList()) {
        Product product = prodProduct.getProduct();
        if ((this.isBeforeEndDate(maturityDate) || manufOrderMrpLineType.getIgnoreEndDate()) && this.isMrpProduct(product)) {
            MrpLine mrpLine = this.createMrpLine(mrp, product, manufOrderMrpLineType, prodProduct.getQty(), maturityDate, BigDecimal.ZERO, stockLocation, manufOrder);
            if (mrpLine != null) {
                mrpLineRepository.save(mrpLine);
            }
        }
    }
    if (manufOrderNeedMrpLineType == null) {
        return;
    }
    if (manufOrder.getIsConsProOnOperation()) {
        for (OperationOrder operationOrder : manufOrder.getOperationOrderList()) {
            for (ProdProduct prodProduct : operationOrder.getToConsumeProdProductList()) {
                Product product = prodProduct.getProduct();
                if (this.isMrpProduct(product)) {
                    maturityDate = null;
                    if (operationOrder.getPlannedEndDateT() != null) {
                        maturityDate = operationOrder.getPlannedEndDateT().toLocalDate();
                    } else {
                        maturityDate = operationOrder.getPlannedStartDateT().toLocalDate();
                    }
                    maturityDate = this.computeMaturityDate(maturityDate, manufOrderNeedMrpLineType);
                    MrpLine mrpLine = this.createMrpLine(mrp, prodProduct.getProduct(), manufOrderNeedMrpLineType, computeQtyLeftToConsume(operationOrder, prodProduct), maturityDate, BigDecimal.ZERO, stockLocation, operationOrder);
                    if (mrpLine != null) {
                        mrpLineRepository.save(mrpLine);
                    }
                }
            }
        }
    } else {
        for (ProdProduct prodProduct : manufOrder.getToConsumeProdProductList()) {
            Product product = prodProduct.getProduct();
            if (this.isMrpProduct(product)) {
                // add it with the level of manuf order product + 1.
                if (!this.productMap.containsKey(product.getId())) {
                    this.assignProductAndLevel(product, manufOrder.getProduct());
                    this.createAvailableStockMrpLine(product, manufOrder.getProdProcess().getStockLocation());
                }
                MrpLine mrpLine = this.createMrpLine(mrp, product, manufOrderNeedMrpLineType, computeQtyLeftToConsume(manufOrder, prodProduct), maturityDate, BigDecimal.ZERO, stockLocation, manufOrder);
                if (mrpLine != null) {
                    mrpLineRepository.save(mrpLine);
                }
            }
        }
    }
}
Also used : StockLocation(com.axelor.apps.stock.db.StockLocation) Product(com.axelor.apps.base.db.Product) ProdProduct(com.axelor.apps.production.db.ProdProduct) MrpLine(com.axelor.apps.supplychain.db.MrpLine) ProdProduct(com.axelor.apps.production.db.ProdProduct) LocalDate(java.time.LocalDate) OperationOrder(com.axelor.apps.production.db.OperationOrder) Transactional(com.google.inject.persist.Transactional)

Aggregations

OperationOrder (com.axelor.apps.production.db.OperationOrder)44 Transactional (com.google.inject.persist.Transactional)24 IOException (java.io.IOException)12 BirtException (org.eclipse.birt.core.exception.BirtException)11 OperationOrderWorkflowService (com.axelor.apps.production.service.operationorder.OperationOrderWorkflowService)10 AxelorException (com.axelor.exception.AxelorException)9 BigDecimal (java.math.BigDecimal)9 OperationOrderRepository (com.axelor.apps.production.db.repo.OperationOrderRepository)8 AppProductionService (com.axelor.apps.production.service.app.AppProductionService)7 LocalDateTime (java.time.LocalDateTime)7 ArrayList (java.util.ArrayList)6 ManufOrder (com.axelor.apps.production.db.ManufOrder)5 Company (com.axelor.apps.base.db.Company)4 ProdProduct (com.axelor.apps.production.db.ProdProduct)4 StockMove (com.axelor.apps.stock.db.StockMove)4 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)4 DayPlanning (com.axelor.apps.base.db.DayPlanning)3 ProdProcessLine (com.axelor.apps.production.db.ProdProcessLine)3 ManufOrderStockMoveService (com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService)3 ProductionOrderService (com.axelor.apps.production.service.productionorder.ProductionOrderService)3