Search in sources :

Example 6 with Inventory

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

the class InventoryController method setInventorySequence.

public void setInventorySequence(ActionRequest request, ActionResponse response) {
    try {
        Inventory inventory = request.getContext().asType(Inventory.class);
        SequenceService sequenceService = Beans.get(SequenceService.class);
        if (sequenceService.isEmptyOrDraftSequenceNumber(inventory.getInventorySeq())) {
            StockLocation stockLocation = inventory.getStockLocation();
            response.setValue("inventorySeq", Beans.get(InventoryService.class).getInventorySequence(stockLocation.getCompany()));
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : StockLocation(com.axelor.apps.stock.db.StockLocation) SequenceService(com.axelor.apps.base.service.administration.SequenceService) Inventory(com.axelor.apps.stock.db.Inventory) BirtException(org.eclipse.birt.core.exception.BirtException) NoResultException(javax.persistence.NoResultException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException)

Example 7 with Inventory

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

the class InventoryController method showStockMoves.

public void showStockMoves(ActionRequest request, ActionResponse response) {
    try {
        Inventory inventory = request.getContext().asType(Inventory.class);
        List<StockMove> stockMoveList = Beans.get(InventoryService.class).findStockMoves(inventory);
        ActionViewBuilder builder = ActionView.define(I18n.get("Internal Stock Moves")).model(StockMove.class.getName()).add("grid", "stock-move-grid").add("form", "stock-move-form").param("search-filters", "internal-stock-move-filters");
        if (stockMoveList.isEmpty()) {
            response.setFlash(I18n.get("No stock moves found for this inventory."));
        } else {
            builder.context("_showSingle", true).domain(String.format("self.originTypeSelect = '%s' AND self.originId = %s", StockMoveRepository.ORIGIN_INVENTORY, inventory.getId()));
            response.setView(builder.map());
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) InventoryService(com.axelor.apps.stock.service.InventoryService) Inventory(com.axelor.apps.stock.db.Inventory) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) BirtException(org.eclipse.birt.core.exception.BirtException) NoResultException(javax.persistence.NoResultException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException)

Example 8 with Inventory

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

the class InventoryController method importFile.

public void importFile(ActionRequest request, ActionResponse response) {
    try {
        Inventory inventory = Beans.get(InventoryRepository.class).find(request.getContext().asType(Inventory.class).getId());
        Path filePath = Beans.get(InventoryService.class).importFile(inventory);
        response.setFlash(String.format(I18n.get(IExceptionMessage.INVENTORY_8), filePath.toString()));
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Path(java.nio.file.Path) InventoryRepository(com.axelor.apps.stock.db.repo.InventoryRepository) InventoryService(com.axelor.apps.stock.service.InventoryService) Inventory(com.axelor.apps.stock.db.Inventory) BirtException(org.eclipse.birt.core.exception.BirtException) NoResultException(javax.persistence.NoResultException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException)

Example 9 with Inventory

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

the class ImportInventory method validateInventory.

@Transactional(rollbackOn = { Exception.class })
public Object validateInventory(Object bean, Map<String, Object> values) throws AxelorException {
    assert bean instanceof InventoryLine;
    Inventory inventory = (Inventory) bean;
    inventoryService.validateInventory(inventory);
    return inventory;
}
Also used : Inventory(com.axelor.apps.stock.db.Inventory) InventoryLine(com.axelor.apps.stock.db.InventoryLine) Transactional(com.google.inject.persist.Transactional)

Example 10 with Inventory

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

Aggregations

Inventory (com.axelor.apps.stock.db.Inventory)18 AxelorException (com.axelor.exception.AxelorException)12 IOException (java.io.IOException)9 NoResultException (javax.persistence.NoResultException)9 BirtException (org.eclipse.birt.core.exception.BirtException)8 InventoryService (com.axelor.apps.stock.service.InventoryService)7 InventoryLine (com.axelor.apps.stock.db.InventoryLine)5 InventoryRepository (com.axelor.apps.stock.db.repo.InventoryRepository)4 SequenceService (com.axelor.apps.base.service.administration.SequenceService)3 StockLocation (com.axelor.apps.stock.db.StockLocation)3 Product (com.axelor.apps.base.db.Product)2 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)2 StockMove (com.axelor.apps.stock.db.StockMove)2 TrackingNumber (com.axelor.apps.stock.db.TrackingNumber)2 StockLocationLineRepository (com.axelor.apps.stock.db.repo.StockLocationLineRepository)2 Beans (com.axelor.inject.Beans)2 MetaFile (com.axelor.meta.db.MetaFile)2 Transactional (com.google.inject.persist.Transactional)2 Company (com.axelor.apps.base.db.Company)1 ProductCategory (com.axelor.apps.base.db.ProductCategory)1