Search in sources :

Example 21 with StockMove

use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.

the class OperationOrderServiceImpl method updateConsumedStockMoveFromOperationOrder.

@Override
@Transactional(rollbackOn = { Exception.class })
public void updateConsumedStockMoveFromOperationOrder(OperationOrder operationOrder) throws AxelorException {
    this.updateDiffProdProductList(operationOrder);
    List<StockMoveLine> consumedStockMoveLineList = operationOrder.getConsumedStockMoveLineList();
    if (consumedStockMoveLineList == null) {
        return;
    }
    Optional<StockMove> stockMoveOpt = operationOrder.getInStockMoveList().stream().filter(stockMove -> stockMove.getStatusSelect() == StockMoveRepository.STATUS_PLANNED).findFirst();
    StockMove stockMove;
    if (stockMoveOpt.isPresent()) {
        stockMove = stockMoveOpt.get();
    } else {
        stockMove = Beans.get(ManufOrderStockMoveService.class)._createToConsumeStockMove(operationOrder.getManufOrder(), operationOrder.getManufOrder().getCompany());
        operationOrder.addInStockMoveListItem(stockMove);
        Beans.get(StockMoveService.class).plan(stockMove);
    }
    Beans.get(ManufOrderService.class).updateStockMoveFromManufOrder(consumedStockMoveLineList, stockMove);
}
Also used : ProdHumanResource(com.axelor.apps.production.db.ProdHumanResource) IExceptionMessage(com.axelor.apps.production.exceptions.IExceptionMessage) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) Inject(com.google.inject.Inject) LocalDateTime(java.time.LocalDateTime) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) StockMoveService(com.axelor.apps.stock.service.StockMoveService) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) Machine(com.axelor.apps.production.db.Machine) Duration(java.time.Duration) Map(java.util.Map) I18n(com.axelor.i18n.I18n) MachineTool(com.axelor.apps.production.db.MachineTool) ManufOrderService(com.axelor.apps.production.service.manuforder.ManufOrderService) ProdProduct(com.axelor.apps.production.db.ProdProduct) RoundingMode(java.math.RoundingMode) BarcodeGeneratorService(com.axelor.apps.base.service.BarcodeGeneratorService) ProdProcessLine(com.axelor.apps.production.db.ProdProcessLine) MetaFiles(com.axelor.meta.MetaFiles) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) MethodHandles(java.lang.invoke.MethodHandles) Set(java.util.Set) IOException(java.io.IOException) OperationOrder(com.axelor.apps.production.db.OperationOrder) OperationOrderRepository(com.axelor.apps.production.db.repo.OperationOrderRepository) DayPlanning(com.axelor.apps.base.db.DayPlanning) WorkCenter(com.axelor.apps.production.db.WorkCenter) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) MetaFile(com.axelor.meta.db.MetaFile) List(java.util.List) Beans(com.axelor.inject.Beans) ManufOrder(com.axelor.apps.production.db.ManufOrder) ValidationException(javax.validation.ValidationException) WeeklyPlanningService(com.axelor.apps.base.service.weeklyplanning.WeeklyPlanningService) DateTimeFormatter(java.time.format.DateTimeFormatter) Optional(java.util.Optional) ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) InputStream(java.io.InputStream) ManufOrderService(com.axelor.apps.production.service.manuforder.ManufOrderService) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveService(com.axelor.apps.stock.service.StockMoveService) ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Transactional(com.google.inject.persist.Transactional)

Example 22 with StockMove

use of com.axelor.apps.stock.db.StockMove 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 23 with StockMove

use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.

the class OperationOrderWorkflowService method start.

/**
 * Starts the given {@link OperationOrder} and sets its starting time
 *
 * @param operationOrder An operation order
 */
@Transactional(rollbackOn = { Exception.class })
public void start(OperationOrder operationOrder) throws AxelorException {
    if (operationOrder.getStatusSelect() != OperationOrderRepository.STATUS_IN_PROGRESS) {
        operationOrder.setStatusSelect(OperationOrderRepository.STATUS_IN_PROGRESS);
        operationOrder.setRealStartDateT(appProductionService.getTodayDateTime().toLocalDateTime());
        startOperationOrderDuration(operationOrder);
        if (operationOrder.getManufOrder() != null) {
            int beforeOrAfterConfig = operationOrder.getManufOrder().getProdProcess().getStockMoveRealizeOrderSelect();
            if (beforeOrAfterConfig == ProductionConfigRepository.REALIZE_START) {
                for (StockMove stockMove : operationOrder.getInStockMoveList()) {
                    Beans.get(ManufOrderStockMoveService.class).finishStockMove(stockMove);
                }
                StockMove newStockMove = operationOrderStockMoveService._createToConsumeStockMove(operationOrder, operationOrder.getManufOrder().getCompany());
                newStockMove.setStockMoveLineList(new ArrayList<>());
                Beans.get(StockMoveService.class).plan(newStockMove);
                operationOrder.addInStockMoveListItem(newStockMove);
            }
        }
        operationOrderRepo.save(operationOrder);
    }
    if (operationOrder.getManufOrder().getStatusSelect() != ManufOrderRepository.STATUS_IN_PROGRESS) {
        Beans.get(ManufOrderWorkflowService.class).start(operationOrder.getManufOrder());
    }
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) StockMoveService(com.axelor.apps.stock.service.StockMoveService) ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) ManufOrderWorkflowService(com.axelor.apps.production.service.manuforder.ManufOrderWorkflowService) ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) Transactional(com.google.inject.persist.Transactional)

Example 24 with StockMove

use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.

the class ManufOrderServiceImpl method updateConsumedStockMoveFromManufOrder.

@Override
@Transactional(rollbackOn = { Exception.class })
public void updateConsumedStockMoveFromManufOrder(ManufOrder manufOrder) throws AxelorException {
    this.updateDiffProdProductList(manufOrder);
    List<StockMoveLine> consumedStockMoveLineList = manufOrder.getConsumedStockMoveLineList();
    if (consumedStockMoveLineList == null) {
        return;
    }
    ManufOrderStockMoveService manufOrderStockMoveService = Beans.get(ManufOrderStockMoveService.class);
    Optional<StockMove> stockMoveOpt = manufOrderStockMoveService.getPlannedStockMove(manufOrder.getInStockMoveList());
    StockMove stockMove;
    if (stockMoveOpt.isPresent()) {
        stockMove = stockMoveOpt.get();
    } else {
        stockMove = manufOrderStockMoveService._createToConsumeStockMove(manufOrder, manufOrder.getCompany());
        manufOrder.addInStockMoveListItem(stockMove);
        Beans.get(StockMoveService.class).plan(stockMove);
    }
    updateStockMoveFromManufOrder(consumedStockMoveLineList, stockMove);
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) StockMoveService(com.axelor.apps.stock.service.StockMoveService) OperationOrderStockMoveService(com.axelor.apps.production.service.operationorder.OperationOrderStockMoveService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Transactional(com.google.inject.persist.Transactional)

Example 25 with StockMove

use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.

the class PurchaseOrderStockServiceImpl method createStockMoveFromPurchaseOrder.

/**
 * Méthode permettant de créer un StockMove à partir d'un PurchaseOrder.
 *
 * @param purchaseOrder une commande
 * @throws AxelorException Aucune séquence de StockMove n'a été configurée
 */
public List<Long> createStockMoveFromPurchaseOrder(PurchaseOrder purchaseOrder) throws AxelorException {
    List<Long> stockMoveIdList = new ArrayList<>();
    if (purchaseOrder.getPurchaseOrderLineList() == null || purchaseOrder.getCompany() == null) {
        return stockMoveIdList;
    }
    if (purchaseOrder.getStockLocation() == null) {
        throw new AxelorException(purchaseOrder, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PO_MISSING_STOCK_LOCATION), purchaseOrder.getPurchaseOrderSeq());
    }
    Map<LocalDate, List<PurchaseOrderLine>> purchaseOrderLinePerDateMap = getAllPurchaseOrderLinePerDate(purchaseOrder);
    for (LocalDate estimatedDeliveryDate : purchaseOrderLinePerDateMap.keySet().stream().filter(x -> x != null).sorted((x, y) -> x.compareTo(y)).collect(Collectors.toList())) {
        List<PurchaseOrderLine> purchaseOrderLineList = purchaseOrderLinePerDateMap.get(estimatedDeliveryDate);
        List<Long> stockMoveId = createStockMove(purchaseOrder, estimatedDeliveryDate, purchaseOrderLineList);
        if (stockMoveId != null && !stockMoveId.isEmpty()) {
            stockMoveIdList.addAll(stockMoveId);
        }
    }
    Optional<List<PurchaseOrderLine>> purchaseOrderLineListDeliveryDateNull = Optional.ofNullable(purchaseOrderLinePerDateMap.get(null));
    if (purchaseOrderLineListDeliveryDateNull.isPresent()) {
        List<Long> stockMoveId = createStockMove(purchaseOrder, null, purchaseOrderLineListDeliveryDateNull.get());
        if (stockMoveId != null && !stockMoveId.isEmpty()) {
            stockMoveIdList.addAll(stockMoveId);
        }
    }
    return stockMoveIdList;
}
Also used : StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) IExceptionMessage(com.axelor.apps.supplychain.exception.IExceptionMessage) PartnerService(com.axelor.apps.base.service.PartnerService) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) ShippingCoefService(com.axelor.apps.base.service.ShippingCoefService) PurchaseOrderLineRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderLineRepository) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine) Map(java.util.Map) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) StockLocationService(com.axelor.apps.stock.service.StockLocationService) RoundingMode(java.math.RoundingMode) 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) StringUtils(com.axelor.common.StringUtils) Collectors(java.util.stream.Collectors) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) List(java.util.List) Product(com.axelor.apps.base.db.Product) PartnerStockSettingsService(com.axelor.apps.stock.service.PartnerStockSettingsService) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Address(com.axelor.apps.base.db.Address) Partner(com.axelor.apps.base.db.Partner) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) Company(com.axelor.apps.base.db.Company) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) StockMoveLineRepository(com.axelor.apps.stock.db.repo.StockMoveLineRepository) PurchaseOrderRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderRepository) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) HashMap(java.util.HashMap) StockMoveService(com.axelor.apps.stock.service.StockMoveService) ArrayList(java.util.ArrayList) AxelorException(com.axelor.exception.AxelorException) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) StockLocation(com.axelor.apps.stock.db.StockLocation) I18n(com.axelor.i18n.I18n) StringTool(com.axelor.apps.tool.StringTool) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) StockConfigService(com.axelor.apps.stock.service.config.StockConfigService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Beans(com.axelor.inject.Beans) Unit(com.axelor.apps.base.db.Unit) SupplyChainConfigRepository(com.axelor.apps.supplychain.db.repo.SupplyChainConfigRepository) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) AxelorException(com.axelor.exception.AxelorException) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate)

Aggregations

StockMove (com.axelor.apps.stock.db.StockMove)129 AxelorException (com.axelor.exception.AxelorException)57 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)50 ArrayList (java.util.ArrayList)36 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)33 Transactional (com.google.inject.persist.Transactional)32 StockMoveService (com.axelor.apps.stock.service.StockMoveService)31 BigDecimal (java.math.BigDecimal)30 List (java.util.List)25 Company (com.axelor.apps.base.db.Company)23 Map (java.util.Map)21 Product (com.axelor.apps.base.db.Product)19 Invoice (com.axelor.apps.account.db.Invoice)18 StockLocation (com.axelor.apps.stock.db.StockLocation)18 Beans (com.axelor.inject.Beans)17 Optional (java.util.Optional)16 StockMoveLineService (com.axelor.apps.stock.service.StockMoveLineService)15 I18n (com.axelor.i18n.I18n)15 Inject (com.google.inject.Inject)14 HashMap (java.util.HashMap)14