Search in sources :

Example 51 with StockLocation

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

the class StockMoveLineController method computeAvailableQty.

@SuppressWarnings({ "unchecked", "rawtypes" })
public void computeAvailableQty(ActionRequest request, ActionResponse response) throws AxelorException {
    Context context = request.getContext();
    StockMoveLine stockMoveLineContext = context.asType(StockMoveLine.class);
    StockMoveLine stockMoveLine = null;
    if (stockMoveLineContext.getId() != null) {
        stockMoveLine = Beans.get(StockMoveLineRepository.class).find(stockMoveLineContext.getId());
        if (stockMoveLineContext.getProduct() != null && !stockMoveLineContext.getProduct().equals(stockMoveLine.getProduct())) {
            stockMoveLine = stockMoveLineContext;
        }
    } else {
        stockMoveLine = stockMoveLineContext;
    }
    StockLocation stockLocation = null;
    if (context.get("_parent") != null && ((Map) context.get("_parent")).get("fromStockLocation") != null) {
        Map<String, Object> _parent = (Map<String, Object>) context.get("_parent");
        stockLocation = Beans.get(StockLocationRepository.class).find(Long.parseLong(((Map) _parent.get("fromStockLocation")).get("id").toString()));
    } else if (stockMoveLine.getStockMove() != null) {
        stockLocation = stockMoveLine.getStockMove().getFromStockLocation();
    }
    if (stockLocation != null) {
        Beans.get(StockMoveLineService.class).updateAvailableQty(stockMoveLine, stockLocation);
        response.setValue("$availableQty", stockMoveLine.getAvailableQty());
        response.setValue("$availableQtyForProduct", stockMoveLine.getAvailableQtyForProduct());
    }
}
Also used : Context(com.axelor.rpc.Context) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) StockLocation(com.axelor.apps.stock.db.StockLocation) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 52 with StockLocation

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

the class StockLocationController method print.

/**
 * Method that generate inventory as a pdf
 *
 * @param request
 * @param response
 * @return
 * @throws BirtException
 * @throws IOException
 */
public void print(ActionRequest request, ActionResponse response) throws AxelorException {
    Context context = request.getContext();
    @SuppressWarnings("unchecked") LinkedHashMap<String, Object> stockLocationMap = (LinkedHashMap<String, Object>) context.get("_stockLocation");
    Integer stockLocationId = (Integer) stockLocationMap.get("id");
    StockLocationService stockLocationService = Beans.get(StockLocationService.class);
    StockLocationRepository stockLocationRepository = Beans.get(StockLocationRepository.class);
    StockLocation stockLocation = stockLocationId != null ? stockLocationRepository.find(new Long(stockLocationId)) : null;
    String locationIds = "";
    String printType = (String) context.get("printingType");
    String exportType = (String) context.get("exportTypeSelect");
    @SuppressWarnings("unchecked") List<Integer> lstSelectedLocations = (List<Integer>) context.get("_ids");
    if (lstSelectedLocations != null) {
        for (Integer it : lstSelectedLocations) {
            Set<Long> idSet = stockLocationService.getContentStockLocationIds(stockLocationRepository.find(new Long(it)));
            if (!idSet.isEmpty()) {
                locationIds += Joiner.on(",").join(idSet) + ",";
            }
        }
    }
    if (!locationIds.equals("")) {
        locationIds = locationIds.substring(0, locationIds.length() - 1);
        stockLocation = stockLocationRepository.find(new Long(lstSelectedLocations.get(0)));
    } else if (stockLocation != null && stockLocation.getId() != null) {
        Set<Long> idSet = stockLocationService.getContentStockLocationIds(stockLocationRepository.find(stockLocation.getId()));
        if (!idSet.isEmpty()) {
            locationIds = Joiner.on(",").join(idSet);
        }
    }
    if (!locationIds.equals("")) {
        String language = ReportSettings.getPrintingLocale(null);
        String title = I18n.get("Stock location");
        if (stockLocation.getName() != null) {
            title = lstSelectedLocations == null ? I18n.get("Stock location") + " " + stockLocation.getName() : I18n.get("Stock location(s)");
        }
        if (stockLocationService.isConfigMissing(stockLocation, Integer.parseInt(printType))) {
            response.setNotify(I18n.get(IExceptionMessage.STOCK_CONFIGURATION_MISSING));
        }
        String fileLink = ReportFactory.createReport(IReport.STOCK_LOCATION, title + "-${date}").addParam("StockLocationId", locationIds).addParam("Timezone", null).addParam("Locale", language).addFormat(exportType).addParam("PrintType", printType).generate().getFileLink();
        logger.debug("Printing " + title);
        response.setView(ActionView.define(title).add("html", fileLink).map());
    } else {
        response.setFlash(I18n.get(IExceptionMessage.LOCATION_2));
    }
    response.setCanClose(true);
}
Also used : Context(com.axelor.rpc.Context) StockLocationService(com.axelor.apps.stock.service.StockLocationService) Set(java.util.Set) StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) StockLocation(com.axelor.apps.stock.db.StockLocation) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List)

Example 53 with StockLocation

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

the class StockLocationController method openPrintWizard.

public void openPrintWizard(ActionRequest request, ActionResponse response) {
    StockLocation stockLocation = request.getContext().asType(StockLocation.class);
    @SuppressWarnings("unchecked") List<Integer> lstSelectedLocations = (List<Integer>) request.getContext().get("_ids");
    response.setView(ActionView.define(I18n.get(IExceptionMessage.STOCK_LOCATION_PRINT_WIZARD_TITLE)).model(Wizard.class.getName()).add("form", "stock-location-print-wizard-form").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").context("_ids", lstSelectedLocations).context("_stockLocation", stockLocation).map());
}
Also used : StockLocation(com.axelor.apps.stock.db.StockLocation) List(java.util.List)

Example 54 with StockLocation

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

the class StockMoveServiceImpl method checkOngoingInventory.

/**
 * Check and raise an exception if the provided stock move is involved in an ongoing inventory.
 *
 * @param stockMove
 * @throws AxelorException
 */
private void checkOngoingInventory(StockMove stockMove) throws AxelorException {
    List<StockLocation> stockLocationList = new ArrayList<>();
    if (stockMove.getFromStockLocation().getTypeSelect() != StockLocationRepository.TYPE_VIRTUAL) {
        stockLocationList.add(stockMove.getFromStockLocation());
    }
    if (stockMove.getToStockLocation().getTypeSelect() != StockLocationRepository.TYPE_VIRTUAL) {
        stockLocationList.add(stockMove.getToStockLocation());
    }
    if (stockLocationList.isEmpty()) {
        return;
    }
    List<Product> productList = stockMove.getStockMoveLineList().stream().map(StockMoveLine::getProduct).filter(Objects::nonNull).collect(Collectors.toList());
    if (productList.isEmpty()) {
        return;
    }
    InventoryLineRepository inventoryLineRepo = Beans.get(InventoryLineRepository.class);
    InventoryLine inventoryLine = inventoryLineRepo.all().filter("self.inventory.statusSelect BETWEEN :startStatus AND :endStatus\n" + "AND self.inventory.stockLocation IN (:stockLocationList)\n" + "AND self.product IN (:productList)").bind("startStatus", InventoryRepository.STATUS_IN_PROGRESS).bind("endStatus", InventoryRepository.STATUS_COMPLETED).bind("stockLocationList", stockLocationList).bind("productList", productList).fetchOne();
    if (inventoryLine != null) {
        throw new AxelorException(inventoryLine, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.STOCK_MOVE_19), inventoryLine.getInventory().getInventorySeq());
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) StockLocation(com.axelor.apps.stock.db.StockLocation) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) InventoryLineRepository(com.axelor.apps.stock.db.repo.InventoryLineRepository) InventoryLine(com.axelor.apps.stock.db.InventoryLine)

Example 55 with StockLocation

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

the class StockMoveServiceImpl method plan.

@Override
@Transactional(rollbackOn = { Exception.class })
public void plan(StockMove stockMove) throws AxelorException {
    LOG.debug("Planification du mouvement de stock : {} ", stockMove.getStockMoveSeq());
    if (stockMove.getExTaxTotal().compareTo(BigDecimal.ZERO) == 0) {
        stockMove.setExTaxTotal(stockMoveToolService.compute(stockMove));
    }
    StockLocation fromStockLocation = stockMove.getFromStockLocation();
    StockLocation toStockLocation = stockMove.getToStockLocation();
    if (fromStockLocation == null) {
        throw new AxelorException(stockMove, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.STOCK_MOVE_5), stockMove.getName());
    }
    if (toStockLocation == null) {
        throw new AxelorException(stockMove, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.STOCK_MOVE_6), stockMove.getName());
    }
    // Set the type select
    if (stockMove.getTypeSelect() == null || stockMove.getTypeSelect() == 0) {
        stockMove.setTypeSelect(stockMoveToolService.getStockMoveType(fromStockLocation, toStockLocation));
    }
    String draftSeq;
    // Set the sequence.
    if (Beans.get(SequenceService.class).isEmptyOrDraftSequenceNumber(stockMove.getStockMoveSeq())) {
        draftSeq = stockMove.getStockMoveSeq();
        stockMove.setStockMoveSeq(stockMoveToolService.getSequenceStockMove(stockMove.getTypeSelect(), stockMove.getCompany()));
    } else {
        draftSeq = null;
    }
    if (Strings.isNullOrEmpty(stockMove.getName()) || draftSeq != null && stockMove.getName().startsWith(draftSeq)) {
        stockMove.setName(stockMoveToolService.computeName(stockMove));
    }
    int initialStatus = stockMove.getStatusSelect();
    setPlannedStatus(stockMove);
    updateLocations(stockMove, fromStockLocation, toStockLocation, initialStatus);
    stockMove.setCancelReason(null);
    stockMoveRepo.save(stockMove);
    if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING && stockMove.getPlannedStockMoveAutomaticMail() != null && stockMove.getPlannedStockMoveAutomaticMail()) {
        sendMailForStockMove(stockMove, stockMove.getPlannedStockMoveMessageTemplate());
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) StockLocation(com.axelor.apps.stock.db.StockLocation) SequenceService(com.axelor.apps.base.service.administration.SequenceService) Transactional(com.google.inject.persist.Transactional)

Aggregations

StockLocation (com.axelor.apps.stock.db.StockLocation)56 Company (com.axelor.apps.base.db.Company)19 BigDecimal (java.math.BigDecimal)18 Product (com.axelor.apps.base.db.Product)15 AxelorException (com.axelor.exception.AxelorException)13 Transactional (com.google.inject.persist.Transactional)13 StockMove (com.axelor.apps.stock.db.StockMove)12 StockLocationRepository (com.axelor.apps.stock.db.repo.StockLocationRepository)12 ArrayList (java.util.ArrayList)12 StockConfig (com.axelor.apps.stock.db.StockConfig)10 StockConfigProductionService (com.axelor.apps.production.service.config.StockConfigProductionService)9 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)8 StockLocationService (com.axelor.apps.stock.service.StockLocationService)8 List (java.util.List)8 Partner (com.axelor.apps.base.db.Partner)6 Unit (com.axelor.apps.base.db.Unit)6 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)6 LocalDate (java.time.LocalDate)6 UnitConversionService (com.axelor.apps.base.service.UnitConversionService)5 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)5