Search in sources :

Example 1 with ManufOrderStockMoveService

use of com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService in project axelor-open-suite by axelor.

the class StockMoveLineController method compute.

public void compute(ActionRequest request, ActionResponse response) throws AxelorException {
    StockMoveLine stockMoveLine = request.getContext().asType(StockMoveLine.class);
    Optional<StockMove> stockMove = Optional.ofNullable(stockMoveLine.getStockMove());
    if (!stockMove.isPresent()) {
        Context parentContext = request.getContext().getParent();
        if (parentContext.getContextClass().equals(StockMove.class)) {
            stockMove = Optional.ofNullable(parentContext.asType(StockMove.class));
        } else if (parentContext.getContextClass().equals(ManufOrder.class)) {
            ManufOrder manufOrder = parentContext.asType(ManufOrder.class);
            ManufOrderStockMoveService manufOrderStockMoveService = Beans.get(ManufOrderStockMoveService.class);
            stockMove = manufOrderStockMoveService.getPlannedStockMove(manufOrder.getInStockMoveList());
        }
        if (!stockMove.isPresent()) {
            return;
        }
    }
    stockMoveLine = Beans.get(StockMoveLineService.class).compute(stockMoveLine, stockMove.get());
    response.setValue("companyPurchasePrice", stockMoveLine.getCompanyPurchasePrice());
    response.setValue("unitPriceUntaxed", stockMoveLine.getUnitPriceUntaxed());
    response.setValue("unitPriceTaxed", stockMoveLine.getUnitPriceTaxed());
}
Also used : Context(com.axelor.rpc.Context) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Example 2 with ManufOrderStockMoveService

use of com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService in project axelor-open-suite by axelor.

the class ManufOrderController method consumeStockMove.

/**
 * Called from manuf order form on clicking realize button. Call {@link
 * ManufOrderStockMoveService#consumeInStockMoves(ManufOrder)} to consume material used in manuf
 * order.
 *
 * @param request
 * @param response
 */
public void consumeStockMove(ActionRequest request, ActionResponse response) {
    try {
        ManufOrder manufOrder = request.getContext().asType(ManufOrder.class);
        manufOrder = Beans.get(ManufOrderRepository.class).find(manufOrder.getId());
        Beans.get(ManufOrderStockMoveService.class).consumeInStockMoves(manufOrder);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) BirtException(org.eclipse.birt.core.exception.BirtException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Example 3 with ManufOrderStockMoveService

use of com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService 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 4 with ManufOrderStockMoveService

use of com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService 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)

Aggregations

ManufOrder (com.axelor.apps.production.db.ManufOrder)4 ManufOrderStockMoveService (com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService)4 StockMove (com.axelor.apps.stock.db.StockMove)3 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)3 AxelorException (com.axelor.exception.AxelorException)3 Company (com.axelor.apps.base.db.Company)2 ProductCompanyService (com.axelor.apps.base.service.ProductCompanyService)2 OperationOrder (com.axelor.apps.production.db.OperationOrder)2 ProdProcessLine (com.axelor.apps.production.db.ProdProcessLine)2 ProdProduct (com.axelor.apps.production.db.ProdProduct)2 StockConfigProductionService (com.axelor.apps.production.service.config.StockConfigProductionService)2 StockConfig (com.axelor.apps.stock.db.StockConfig)2 StockLocation (com.axelor.apps.stock.db.StockLocation)2 StockLocationRepository (com.axelor.apps.stock.db.repo.StockLocationRepository)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 Transactional (com.google.inject.persist.Transactional)2