Search in sources :

Example 11 with StockConfig

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

use of com.axelor.apps.stock.db.StockConfig 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)

Example 13 with StockConfig

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

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

the class StockLocationServiceImpl method getDefaultReceiptStockLocation.

@Override
public StockLocation getDefaultReceiptStockLocation(Company company) {
    try {
        StockConfigService stockConfigService = Beans.get(StockConfigService.class);
        StockConfig stockConfig = stockConfigService.getStockConfig(company);
        return stockConfigService.getReceiptDefaultStockLocation(stockConfig);
    } catch (Exception e) {
        return null;
    }
}
Also used : StockConfig(com.axelor.apps.stock.db.StockConfig) StockConfigService(com.axelor.apps.stock.service.config.StockConfigService) AxelorException(com.axelor.exception.AxelorException)

Example 15 with StockConfig

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

the class StockLocationServiceImpl method getPickupDefaultStockLocation.

@Override
public StockLocation getPickupDefaultStockLocation(Company company) {
    try {
        StockConfigService stockConfigService = Beans.get(StockConfigService.class);
        StockConfig stockConfig = stockConfigService.getStockConfig(company);
        return stockConfigService.getPickupDefaultStockLocation(stockConfig);
    } catch (Exception e) {
        return null;
    }
}
Also used : StockConfig(com.axelor.apps.stock.db.StockConfig) StockConfigService(com.axelor.apps.stock.service.config.StockConfigService) AxelorException(com.axelor.exception.AxelorException)

Aggregations

StockConfig (com.axelor.apps.stock.db.StockConfig)16 StockLocation (com.axelor.apps.stock.db.StockLocation)8 Company (com.axelor.apps.base.db.Company)7 StockConfigProductionService (com.axelor.apps.production.service.config.StockConfigProductionService)7 AxelorException (com.axelor.exception.AxelorException)7 StockMove (com.axelor.apps.stock.db.StockMove)6 StockConfigService (com.axelor.apps.stock.service.config.StockConfigService)6 Transactional (com.google.inject.persist.Transactional)5 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)3 BigDecimal (java.math.BigDecimal)3 ArrayList (java.util.ArrayList)3 Product (com.axelor.apps.base.db.Product)2 ProdProcessLine (com.axelor.apps.production.db.ProdProcessLine)2 ProdProduct (com.axelor.apps.production.db.ProdProduct)2 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)2 StockMoveLineService (com.axelor.apps.stock.service.StockMoveLineService)2 StockMoveService (com.axelor.apps.stock.service.StockMoveService)2 Beans (com.axelor.inject.Beans)2 Inject (com.google.inject.Inject)2 List (java.util.List)2