Search in sources :

Example 1 with Inventory

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

the class InventoryLineService method updateInventoryLine.

public InventoryLine updateInventoryLine(InventoryLine inventoryLine, Inventory inventory) {
    StockLocation stockLocation = inventory.getStockLocation();
    Product product = inventoryLine.getProduct();
    if (product != null) {
        StockLocationLine stockLocationLine = Beans.get(StockLocationLineService.class).getOrCreateStockLocationLine(stockLocation, product);
        if (stockLocationLine != null) {
            inventoryLine.setCurrentQty(stockLocationLine.getCurrentQty());
            inventoryLine.setRack(stockLocationLine.getRack());
            if (inventoryLine.getTrackingNumber() != null) {
                inventoryLine.setCurrentQty(Beans.get(StockLocationLineRepository.class).all().filter("self.product = :product and self.detailsStockLocation = :stockLocation and self.trackingNumber = :trackingNumber").bind("product", inventoryLine.getProduct()).bind("stockLocation", stockLocation).bind("trackingNumber", inventoryLine.getTrackingNumber()).fetchStream().map(it -> it.getCurrentQty()).reduce(BigDecimal.ZERO, (a, b) -> a.add(b)));
            }
        } else {
            inventoryLine.setCurrentQty(null);
            inventoryLine.setRack(null);
        }
    }
    return inventoryLine;
}
Also used : BigDecimal(java.math.BigDecimal) StockLocationLineRepository(com.axelor.apps.stock.db.repo.StockLocationLineRepository) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) StockLocation(com.axelor.apps.stock.db.StockLocation) StockConfigRepository(com.axelor.apps.stock.db.repo.StockConfigRepository) Inventory(com.axelor.apps.stock.db.Inventory) TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) InventoryLine(com.axelor.apps.stock.db.InventoryLine) RoundingMode(java.math.RoundingMode) StockLocation(com.axelor.apps.stock.db.StockLocation) StockLocationLineRepository(com.axelor.apps.stock.db.repo.StockLocationLineRepository) Product(com.axelor.apps.base.db.Product) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine)

Example 2 with Inventory

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

the class InventoryManagementRepository method save.

@Override
public Inventory save(Inventory entity) {
    Inventory inventory = super.save(entity);
    SequenceService sequenceService = Beans.get(SequenceService.class);
    try {
        if (Strings.isNullOrEmpty(inventory.getInventorySeq())) {
            inventory.setInventorySeq(sequenceService.getDraftSequenceNumber(inventory));
        }
    } catch (AxelorException e) {
        TraceBackService.traceExceptionFromSaveMethod(e);
        throw new PersistenceException(e.getMessage(), e);
    }
    entity.setInventoryTitle(Beans.get(InventoryService.class).computeTitle(entity));
    return inventory;
}
Also used : AxelorException(com.axelor.exception.AxelorException) PersistenceException(javax.persistence.PersistenceException) SequenceService(com.axelor.apps.base.service.administration.SequenceService) Inventory(com.axelor.apps.stock.db.Inventory)

Example 3 with Inventory

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

the class InventoryManagementRepository method copy.

@Override
public Inventory copy(Inventory entity, boolean deep) {
    Inventory copy = super.copy(entity, deep);
    copy.setStatusSelect(STATUS_DRAFT);
    copy.setInventorySeq(null);
    return copy;
}
Also used : Inventory(com.axelor.apps.stock.db.Inventory)

Example 4 with Inventory

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

the class InventoryController method exportInventory.

public void exportInventory(ActionRequest request, ActionResponse response) {
    try {
        Inventory inventory = request.getContext().asType(Inventory.class);
        inventory = Beans.get(InventoryRepository.class).find(inventory.getId());
        String name = I18n.get("Inventory") + " " + inventory.getInventorySeq();
        MetaFile metaFile = Beans.get(InventoryService.class).exportInventoryAsCSV(inventory);
        response.setView(ActionView.define(name).add("html", "ws/rest/com.axelor.meta.db.MetaFile/" + metaFile.getId() + "/content/download?v=" + metaFile.getVersion()).map());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : InventoryService(com.axelor.apps.stock.service.InventoryService) MetaFile(com.axelor.meta.db.MetaFile) 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 5 with Inventory

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

the class InventoryController method checkDuplicateProduct.

public void checkDuplicateProduct(ActionRequest request, ActionResponse response) throws AxelorException {
    Inventory inventory = request.getContext().asType(Inventory.class);
    Query query = JPA.em().createQuery("select COUNT(*) FROM InventoryLine self WHERE self.inventory.id = :invent GROUP BY self.product, self.trackingNumber HAVING COUNT(self) > 1");
    try {
        query.setParameter("invent", inventory.getId()).getSingleResult();
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.INVENTORY_PRODUCT_TRACKING_NUMBER_ERROR));
    } catch (NoResultException e) {
    // if control came here means no duplicate product.
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException) Inventory(com.axelor.apps.stock.db.Inventory)

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