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());
}
}
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);
}
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());
}
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());
}
}
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());
}
}
Aggregations