Search in sources :

Example 96 with StockMove

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

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

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

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

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

the class CostSheetServiceImpl method getTotalQtyPerProductAndUnit.

protected Map<List<Object>, BigDecimal> getTotalQtyPerProductAndUnit(List<StockMoveLine> stockMoveLineList, LocalDate calculationDate, LocalDate previousCostSheetDate, int calculationType) {
    Map<List<Object>, BigDecimal> stockMoveLinePerProductAndUnitMap = new HashMap<>();
    if (stockMoveLineList == null) {
        return stockMoveLinePerProductAndUnitMap;
    }
    for (StockMoveLine stockMoveLine : stockMoveLineList) {
        StockMove stockMove = stockMoveLine.getStockMove();
        if (stockMove == null || StockMoveRepository.STATUS_REALIZED != stockMoveLine.getStockMove().getStatusSelect()) {
            continue;
        }
        if ((calculationType == CostSheetRepository.CALCULATION_PARTIAL_END_OF_PRODUCTION || calculationType == CostSheetRepository.CALCULATION_END_OF_PRODUCTION) && previousCostSheetDate != null && !previousCostSheetDate.isBefore(stockMove.getRealDate())) {
            continue;
        } else if (calculationType == CostSheetRepository.CALCULATION_WORK_IN_PROGRESS && calculationDate.isBefore(stockMove.getRealDate())) {
            continue;
        }
        Product productKey = stockMoveLine.getProduct();
        Unit unitKey = stockMoveLine.getUnit();
        List<Object> keys = new ArrayList<Object>();
        keys.add(productKey);
        keys.add(unitKey);
        BigDecimal qty = stockMoveLinePerProductAndUnitMap.get(keys);
        if (qty == null) {
            qty = BigDecimal.ZERO;
        }
        stockMoveLinePerProductAndUnitMap.put(keys, qty.add(stockMoveLine.getRealQty()));
    }
    return stockMoveLinePerProductAndUnitMap;
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) ProdProduct(com.axelor.apps.production.db.ProdProduct) Product(com.axelor.apps.base.db.Product) ProdResidualProduct(com.axelor.apps.production.db.ProdResidualProduct) ArrayList(java.util.ArrayList) List(java.util.List) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

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