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