Search in sources :

Example 36 with StockLocationLine

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

the class InventoryService method fillInventoryLineList.

@Transactional(rollbackOn = { Exception.class })
public Boolean fillInventoryLineList(Inventory inventory) throws AxelorException {
    if (inventory.getStockLocation() == null) {
        throw new AxelorException(inventory, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.INVENTORY_1));
    }
    this.initInventoryLines(inventory);
    List<? extends StockLocationLine> stockLocationLineList = this.getStockLocationLines(inventory);
    if (stockLocationLineList != null) {
        Boolean succeed = false;
        for (StockLocationLine stockLocationLine : stockLocationLineList) {
            if (stockLocationLine.getTrackingNumber() == null) {
                // if no tracking number on stockLocationLine, check if there is a tracking
                // number on the product
                long numberOfTrackingNumberOnAProduct = stockLocationLineList.stream().filter(sll -> stockLocationLine.getProduct() != null && stockLocationLine.getProduct().equals(sll.getProduct()) && sll.getTrackingNumber() != null && inventory.getStockLocation().equals(sll.getDetailsStockLocation())).count();
                if (numberOfTrackingNumberOnAProduct != 0) {
                    // there is a tracking number on the product
                    continue;
                }
            }
            inventory.addInventoryLineListItem(this.createInventoryLine(inventory, stockLocationLine));
            succeed = true;
        }
        inventoryRepo.save(inventory);
        return succeed;
    }
    return null;
}
Also used : Arrays(java.util.Arrays) ProductFamily(com.axelor.apps.base.db.ProductFamily) Inject(com.google.inject.Inject) ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) Inventory(com.axelor.apps.stock.db.Inventory) StringUtils(org.apache.commons.lang3.StringUtils) TrackingNumberRepository(com.axelor.apps.stock.db.repo.TrackingNumberRepository) Transactional(com.google.inject.persist.Transactional) BigDecimal(java.math.BigDecimal) SequenceRepository(com.axelor.apps.base.db.repo.SequenceRepository) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) CsvTool(com.axelor.apps.tool.file.CsvTool) ZoneOffset(java.time.ZoneOffset) Path(java.nio.file.Path) RoundingMode(java.math.RoundingMode) StockLocationLineRepository(com.axelor.apps.stock.db.repo.StockLocationLineRepository) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) MethodHandles(java.lang.invoke.MethodHandles) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) InventoryLine(com.axelor.apps.stock.db.InventoryLine) SequenceService(com.axelor.apps.base.service.administration.SequenceService) List(java.util.List) Product(com.axelor.apps.base.db.Product) LocalDate(java.time.LocalDate) Company(com.axelor.apps.base.db.Company) IExceptionMessage(com.axelor.apps.stock.exception.IExceptionMessage) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) AxelorException(com.axelor.exception.AxelorException) ProductCategory(com.axelor.apps.base.db.ProductCategory) StockLocation(com.axelor.apps.stock.db.StockLocation) I18n(com.axelor.i18n.I18n) MetaFiles(com.axelor.meta.MetaFiles) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) StockConfigService(com.axelor.apps.stock.service.config.StockConfigService) File(java.io.File) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) MetaFile(com.axelor.meta.db.MetaFile) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Beans(com.axelor.inject.Beans) DateTimeFormatter(java.time.format.DateTimeFormatter) InventoryRepository(com.axelor.apps.stock.db.repo.InventoryRepository) Comparator(java.util.Comparator) TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) Collections(java.util.Collections) AuthUtils(com.axelor.auth.AuthUtils) InputStream(java.io.InputStream) AxelorException(com.axelor.exception.AxelorException) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Transactional(com.google.inject.persist.Transactional)

Example 37 with StockLocationLine

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

the class InventoryService method storeLastInventoryData.

private void storeLastInventoryData(Inventory inventory) {
    Map<Pair<Product, TrackingNumber>, BigDecimal> realQties = new HashMap<>();
    Map<Product, BigDecimal> consolidatedRealQties = new HashMap<>();
    Map<Product, String> realRacks = new HashMap<>();
    List<InventoryLine> inventoryLineList = inventory.getInventoryLineList();
    if (inventoryLineList != null) {
        for (InventoryLine inventoryLine : inventoryLineList) {
            Product product = inventoryLine.getProduct();
            TrackingNumber trackingNumber = inventoryLine.getTrackingNumber();
            realQties.put(Pair.of(product, trackingNumber), inventoryLine.getRealQty());
            BigDecimal realQty = consolidatedRealQties.getOrDefault(product, BigDecimal.ZERO);
            realQty = realQty.add(inventoryLine.getRealQty());
            consolidatedRealQties.put(product, realQty);
            realRacks.put(product, inventoryLine.getRack());
        }
    }
    List<StockLocationLine> stockLocationLineList = inventory.getStockLocation().getStockLocationLineList();
    if (stockLocationLineList != null) {
        for (StockLocationLine stockLocationLine : stockLocationLineList) {
            Product product = stockLocationLine.getProduct();
            BigDecimal realQty = consolidatedRealQties.get(product);
            if (realQty != null) {
                stockLocationLine.setLastInventoryRealQty(realQty);
                stockLocationLine.setLastInventoryDateT(inventory.getValidatedOn().atStartOfDay().atZone(ZoneOffset.UTC));
            }
            String rack = realRacks.get(product);
            if (rack != null) {
                stockLocationLine.setRack(rack);
            }
        }
    }
    List<StockLocationLine> detailsStockLocationLineList = inventory.getStockLocation().getDetailsStockLocationLineList();
    if (detailsStockLocationLineList != null) {
        for (StockLocationLine detailsStockLocationLine : detailsStockLocationLineList) {
            Product product = detailsStockLocationLine.getProduct();
            TrackingNumber trackingNumber = detailsStockLocationLine.getTrackingNumber();
            BigDecimal realQty = realQties.get(Pair.of(product, trackingNumber));
            if (realQty != null) {
                detailsStockLocationLine.setLastInventoryRealQty(realQty);
                detailsStockLocationLine.setLastInventoryDateT(inventory.getValidatedOn().atStartOfDay().atZone(ZoneOffset.UTC));
            }
            String rack = realRacks.get(product);
            if (rack != null) {
                detailsStockLocationLine.setRack(rack);
            }
        }
    }
}
Also used : TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) HashMap(java.util.HashMap) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Pair(org.apache.commons.lang3.tuple.Pair) InventoryLine(com.axelor.apps.stock.db.InventoryLine)

Example 38 with StockLocationLine

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

the class StockLocationLineController method allocateAll.

/**
 * Called from stock location line form view, on allocateAll button click. Call {@link
 * StockLocationLineReservationService#allocateAll(StockLocationLine)}
 *
 * @param request
 * @param response
 */
public void allocateAll(ActionRequest request, ActionResponse response) {
    try {
        StockLocationLine stockLocationLine = request.getContext().asType(StockLocationLine.class);
        stockLocationLine = Beans.get(StockLocationLineRepository.class).find(stockLocationLine.getId());
        Beans.get(StockLocationLineReservationService.class).allocateAll(stockLocationLine);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : StockLocationLineReservationService(com.axelor.apps.supplychain.service.StockLocationLineReservationService) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine)

Example 39 with StockLocationLine

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

the class StockMoveLineController method displayAvailableTrackingNumber.

public void displayAvailableTrackingNumber(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    @SuppressWarnings("unchecked") LinkedHashMap<String, Object> stockMoveLineMap = (LinkedHashMap<String, Object>) context.get("_stockMoveLine");
    @SuppressWarnings("unchecked") LinkedHashMap<String, Object> stockMoveMap = (LinkedHashMap<String, Object>) context.get("_stockMove");
    Integer stockMoveLineId = (Integer) stockMoveLineMap.get("id");
    Integer stockMoveId = (Integer) stockMoveMap.get("id");
    StockMoveLine stockMoveLine = Beans.get(StockMoveLineRepository.class).find(new Long(stockMoveLineId));
    StockMove stockMove = Beans.get(StockMoveRepository.class).find(new Long(stockMoveId));
    if (stockMoveLine == null || stockMoveLine.getProduct() == null || stockMove == null || stockMove.getFromStockLocation() == null) {
        return;
    }
    List<TrackingNumber> trackingNumberList = Beans.get(StockMoveLineService.class).getAvailableTrackingNumbers(stockMoveLine, stockMove);
    if (trackingNumberList == null || trackingNumberList.isEmpty()) {
        return;
    }
    SortedSet<Map<String, Object>> trackingNumbers = new TreeSet<Map<String, Object>>(Comparator.comparing(m -> (String) m.get("trackingNumberSeq")));
    StockLocationLineService stockLocationLineService = Beans.get(StockLocationLineService.class);
    for (TrackingNumber trackingNumber : trackingNumberList) {
        StockLocationLine detailStockLocationLine = stockLocationLineService.getDetailLocationLine(stockMove.getFromStockLocation(), stockMoveLine.getProduct(), trackingNumber);
        BigDecimal availableQty = detailStockLocationLine != null ? detailStockLocationLine.getCurrentQty() : BigDecimal.ZERO;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("trackingNumber", trackingNumber);
        map.put("trackingNumberSeq", trackingNumber.getTrackingNumberSeq());
        map.put("counter", BigDecimal.ZERO);
        map.put("warrantyExpirationDate", trackingNumber.getWarrantyExpirationDate());
        map.put("perishableExpirationDate", trackingNumber.getPerishableExpirationDate());
        map.put("$availableQty", availableQty);
        map.put("$moveTypeSelect", stockMove.getTypeSelect());
        map.put("origin", trackingNumber.getOrigin());
        map.put("note", trackingNumber.getNote());
        trackingNumbers.add(map);
    }
    response.setValue("$trackingNumbers", trackingNumbers);
}
Also used : Context(com.axelor.rpc.Context) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) StockMoveLineRepository(com.axelor.apps.stock.db.repo.StockMoveLineRepository) IExceptionMessage(com.axelor.apps.stock.exception.IExceptionMessage) SortedSet(java.util.SortedSet) ActionView(com.axelor.meta.schema.actions.ActionView) HashMap(java.util.HashMap) Mapper(com.axelor.db.mapper.Mapper) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) StockLocation(com.axelor.apps.stock.db.StockLocation) ActionResponse(com.axelor.rpc.ActionResponse) Map(java.util.Map) I18n(com.axelor.i18n.I18n) Wizard(com.axelor.apps.base.db.Wizard) ActionRequest(com.axelor.rpc.ActionRequest) StockLocationLineService(com.axelor.apps.stock.service.StockLocationLineService) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) ResponseMessageType(com.axelor.exception.ResponseMessageType) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) TraceBackService(com.axelor.exception.service.TraceBackService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) List(java.util.List) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Beans(com.axelor.inject.Beans) Comparator(java.util.Comparator) TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) Context(com.axelor.rpc.Context) Singleton(com.google.inject.Singleton) StockLocationLineService(com.axelor.apps.stock.service.StockLocationLineService) StockMove(com.axelor.apps.stock.db.StockMove) TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) BigDecimal(java.math.BigDecimal) LinkedHashMap(java.util.LinkedHashMap) TreeSet(java.util.TreeSet) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) StockMoveLineRepository(com.axelor.apps.stock.db.repo.StockMoveLineRepository) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 40 with StockLocationLine

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

the class ProductStockController method updateStockLocation.

public void updateStockLocation(ActionRequest request, ActionResponse response) {
    try {
        Product product = request.getContext().asType(Product.class);
        StockLocationLineService stockLocationLineService = Beans.get(StockLocationLineService.class);
        if (product.getId() == null) {
            return;
        }
        product = Beans.get(ProductRepository.class).find(product.getId());
        List<StockLocationLine> stockLocationLineList = stockLocationLineService.getStockLocationLines(product);
        for (StockLocationLine stockLocationLine : stockLocationLineList) {
            stockLocationLineService.updateStockLocationFromProduct(stockLocationLine, product);
        }
        Beans.get(WeightedAveragePriceService.class).computeAvgPriceForProduct(product);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : StockLocationLineService(com.axelor.apps.stock.service.StockLocationLineService) WeightedAveragePriceService(com.axelor.apps.stock.service.WeightedAveragePriceService) Product(com.axelor.apps.base.db.Product) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine)

Aggregations

StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)42 BigDecimal (java.math.BigDecimal)25 Product (com.axelor.apps.base.db.Product)13 Transactional (com.google.inject.persist.Transactional)10 StockLocation (com.axelor.apps.stock.db.StockLocation)8 AxelorException (com.axelor.exception.AxelorException)8 Unit (com.axelor.apps.base.db.Unit)7 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)7 TrackingNumber (com.axelor.apps.stock.db.TrackingNumber)6 InventoryLine (com.axelor.apps.stock.db.InventoryLine)4 StockLocationLineRepository (com.axelor.apps.stock.db.repo.StockLocationLineRepository)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Company (com.axelor.apps.base.db.Company)3 StockMove (com.axelor.apps.stock.db.StockMove)3 Beans (com.axelor.inject.Beans)3 UnitConversionService (com.axelor.apps.base.service.UnitConversionService)2 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)2 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)2 Inventory (com.axelor.apps.stock.db.Inventory)2