Search in sources :

Example 91 with StockMove

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

the class ManufOrderServiceImpl method updateStockMoveFromManufOrder.

@Override
public void updateStockMoveFromManufOrder(List<StockMoveLine> stockMoveLineList, StockMove stockMove) throws AxelorException {
    if (stockMoveLineList == null) {
        return;
    }
    // add missing lines in stock move
    stockMoveLineList.stream().filter(stockMoveLine -> stockMoveLine.getStockMove() == null).forEach(stockMove::addStockMoveLineListItem);
    // remove lines in stock move removed in manuf order
    if (stockMove.getStockMoveLineList() != null) {
        stockMove.getStockMoveLineList().removeIf(stockMoveLine -> !stockMoveLineList.contains(stockMoveLine));
    }
    StockMoveService stockMoveService = Beans.get(StockMoveService.class);
    // update stock location by cancelling then planning stock move.
    stockMoveService.cancel(stockMove);
    stockMoveService.plan(stockMove);
}
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) StockMoveService(com.axelor.apps.stock.service.StockMoveService) OperationOrderStockMoveService(com.axelor.apps.production.service.operationorder.OperationOrderStockMoveService)

Example 92 with StockMove

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

the class ManufOrderStockMoveService method partialFinish.

/**
 * Allows to create and realize in or out stock moves for the given manufacturing order.
 *
 * @param manufOrder
 * @param inOrOut can be {@link ManufOrderStockMoveService#PART_FINISH_IN} or {@link
 *     ManufOrderStockMoveService#PART_FINISH_OUT}
 * @throws AxelorException
 */
protected void partialFinish(ManufOrder manufOrder, int inOrOut) throws AxelorException {
    if (inOrOut != PART_FINISH_IN && inOrOut != PART_FINISH_OUT) {
        throw new IllegalArgumentException(I18n.get(IExceptionMessage.IN_OR_OUT_INVALID_ARG));
    }
    Company company = manufOrder.getCompany();
    StockConfigProductionService stockConfigService = Beans.get(StockConfigProductionService.class);
    StockConfig stockConfig = stockConfigService.getStockConfig(company);
    StockLocation fromStockLocation;
    StockLocation toStockLocation;
    List<StockMove> stockMoveList;
    if (inOrOut == PART_FINISH_IN) {
        stockMoveList = manufOrder.getInStockMoveList();
        fromStockLocation = getDefaultStockLocation(manufOrder, company, STOCK_LOCATION_IN);
        toStockLocation = stockConfigService.getProductionVirtualStockLocation(stockConfig, manufOrder.getProdProcess().getOutsourcing());
    } else {
        stockMoveList = manufOrder.getOutStockMoveList();
        fromStockLocation = stockConfigService.getProductionVirtualStockLocation(stockConfig, manufOrder.getProdProcess().getOutsourcing());
        toStockLocation = getDefaultStockLocation(manufOrder, company, STOCK_LOCATION_OUT);
    }
    // realize current stock move and update the price
    Optional<StockMove> stockMoveToRealize = getPlannedStockMove(stockMoveList);
    if (stockMoveToRealize.isPresent()) {
        updateRealPrice(manufOrder, stockMoveToRealize.get());
        finishStockMove(stockMoveToRealize.get());
    }
    // generate new stock move
    StockMove newStockMove = stockMoveService.createStockMove(null, null, company, fromStockLocation, toStockLocation, null, manufOrder.getPlannedStartDateT().toLocalDate(), null, StockMoveRepository.TYPE_INTERNAL);
    newStockMove.setStockMoveLineList(new ArrayList<>());
    newStockMove.setOrigin(manufOrder.getManufOrderSeq());
    newStockMove.setOriginId(manufOrder.getId());
    newStockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_MANUF_ORDER);
    createNewStockMoveLines(manufOrder, newStockMove, inOrOut);
    if (!newStockMove.getStockMoveLineList().isEmpty()) {
        // plan the stockmove
        stockMoveService.plan(newStockMove);
        if (inOrOut == PART_FINISH_IN) {
            manufOrder.addInStockMoveListItem(newStockMove);
            newStockMove.getStockMoveLineList().forEach(manufOrder::addConsumedStockMoveLineListItem);
            manufOrder.clearDiffConsumeProdProductList();
        } else {
            manufOrder.addOutStockMoveListItem(newStockMove);
            newStockMove.getStockMoveLineList().forEach(manufOrder::addProducedStockMoveLineListItem);
        }
    }
}
Also used : 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)

Example 93 with StockMove

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

the class ManufOrderStockMoveService method _createToProduceStockMove.

protected StockMove _createToProduceStockMove(ManufOrder manufOrder, Company company) throws AxelorException {
    StockConfigProductionService stockConfigService = Beans.get(StockConfigProductionService.class);
    StockConfig stockConfig = stockConfigService.getStockConfig(company);
    StockLocation virtualStockLocation = stockConfigService.getProductionVirtualStockLocation(stockConfig, manufOrder.getProdProcess().getOutsourcing());
    LocalDateTime plannedEndDateT = manufOrder.getPlannedEndDateT();
    LocalDate plannedEndDate = plannedEndDateT != null ? plannedEndDateT.toLocalDate() : null;
    StockLocation producedProductStockLocation = manufOrder.getProdProcess().getProducedProductStockLocation();
    if (producedProductStockLocation == null) {
        producedProductStockLocation = stockConfigService.getFinishedProductsDefaultStockLocation(stockConfig);
    }
    StockMove stockMove = stockMoveService.createStockMove(null, null, company, virtualStockLocation, producedProductStockLocation, null, plannedEndDate, null, StockMoveRepository.TYPE_INTERNAL);
    stockMove.setOriginId(manufOrder.getId());
    stockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_MANUF_ORDER);
    stockMove.setOrigin(manufOrder.getManufOrderSeq());
    return stockMove;
}
Also used : LocalDateTime(java.time.LocalDateTime) 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) LocalDate(java.time.LocalDate)

Example 94 with StockMove

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

the class ManufOrderStockMoveService method createNewProducedStockMoveLineList.

/**
 * Clear the produced list and create a new one with the right quantity.
 *
 * @param manufOrder
 * @param qtyToUpdate
 */
public void createNewProducedStockMoveLineList(ManufOrder manufOrder, BigDecimal qtyToUpdate) throws AxelorException {
    Optional<StockMove> stockMoveOpt = getPlannedStockMove(manufOrder.getOutStockMoveList());
    if (!stockMoveOpt.isPresent()) {
        return;
    }
    StockMove stockMove = stockMoveOpt.get();
    stockMoveService.cancel(stockMove);
    // clear all lists
    manufOrder.getProducedStockMoveLineList().removeIf(stockMoveLine -> stockMoveLine.getStockMove().getStatusSelect() == StockMoveRepository.STATUS_CANCELED);
    stockMove.clearStockMoveLineList();
    // create a new list
    for (ProdProduct prodProduct : manufOrder.getToProduceProdProductList()) {
        BigDecimal qty = getFractionQty(manufOrder, prodProduct, qtyToUpdate);
        BigDecimal productCostPrice = prodProduct.getProduct() != null ? (BigDecimal) productCompanyService.get(prodProduct.getProduct(), "costPrice", manufOrder.getCompany()) : BigDecimal.ZERO;
        _createStockMoveLine(prodProduct, stockMove, StockMoveLineService.TYPE_OUT_PRODUCTIONS, qty, productCostPrice);
        // Update produced StockMoveLineList with created stock move lines
        stockMove.getStockMoveLineList().stream().filter(stockMoveLine1 -> !manufOrder.getProducedStockMoveLineList().contains(stockMoveLine1)).forEach(manufOrder::addProducedStockMoveLineListItem);
    }
    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 95 with StockMove

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

the class ManufOrderStockMoveService method _createToConsumeStockMove.

public StockMove _createToConsumeStockMove(ManufOrder manufOrder, Company company) throws AxelorException {
    StockConfigProductionService stockConfigService = Beans.get(StockConfigProductionService.class);
    StockConfig stockConfig = stockConfigService.getStockConfig(company);
    StockLocation virtualStockLocation = manufOrder.getOutsourcing() ? manufOrder.getProdProcess().getProducedProductStockLocation() : stockConfigService.getProductionVirtualStockLocation(stockConfig, manufOrder.getProdProcess().getOutsourcing());
    StockLocation fromStockLocation = manufOrder.getOutsourcing() ? company.getStockConfig().getOutsourcingReceiptStockLocation() : getDefaultStockLocation(manufOrder, company, STOCK_LOCATION_IN);
    StockMove stockMove = stockMoveService.createStockMove(null, null, company, fromStockLocation, virtualStockLocation, null, manufOrder.getPlannedStartDateT().toLocalDate(), null, StockMoveRepository.TYPE_INTERNAL);
    stockMove.setOriginId(manufOrder.getId());
    stockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_MANUF_ORDER);
    stockMove.setOrigin(manufOrder.getManufOrderSeq());
    return stockMove;
}
Also used : 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)

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