Search in sources :

Example 6 with StockMove

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

the class StockMoveManagementRepository method save.

@Override
public StockMove save(StockMove entity) {
    try {
        StockMove stockMove = super.save(entity);
        SequenceService sequenceService = Beans.get(SequenceService.class);
        if (Strings.isNullOrEmpty(stockMove.getStockMoveSeq())) {
            stockMove.setStockMoveSeq(sequenceService.getDraftSequenceNumber(stockMove));
        }
        if (Strings.isNullOrEmpty(stockMove.getName()) || stockMove.getName().startsWith(stockMove.getStockMoveSeq())) {
            stockMove.setName(Beans.get(StockMoveToolService.class).computeName(stockMove));
        }
        return stockMove;
    } catch (Exception e) {
        TraceBackService.traceExceptionFromSaveMethod(e);
        throw new PersistenceException(e.getMessage(), e);
    }
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) PersistenceException(javax.persistence.PersistenceException) SequenceService(com.axelor.apps.base.service.administration.SequenceService) PersistenceException(javax.persistence.PersistenceException)

Example 7 with StockMove

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

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

the class StockMoveServiceImpl method createStockMove.

/**
 * Generic method to create any stock move for internal stock move (without partner information)
 *
 * @param fromAddress
 * @param toAddress
 * @param company
 * @param fromStockLocation
 * @param toStockLocation
 * @param realDate
 * @param estimatedDate
 * @param note
 * @param typeSelect
 * @return
 * @throws AxelorException No Stock move sequence defined
 */
@Override
public StockMove createStockMove(Address fromAddress, Address toAddress, Company company, StockLocation fromStockLocation, StockLocation toStockLocation, LocalDate realDate, LocalDate estimatedDate, String note, int typeSelect) throws AxelorException {
    StockMove stockMove = new StockMove();
    if (stockMove.getStockMoveLineList() == null) {
        stockMove.setStockMoveLineList(new ArrayList<>());
    }
    stockMove.setFromAddress(fromAddress);
    stockMove.setToAddress(toAddress);
    stockMoveToolService.computeAddressStr(stockMove);
    stockMove.setCompany(company);
    stockMove.setStatusSelect(StockMoveRepository.STATUS_DRAFT);
    stockMove.setRealDate(realDate);
    stockMove.setEstimatedDate(estimatedDate);
    stockMove.setFromStockLocation(fromStockLocation);
    stockMove.setToStockLocation(toStockLocation);
    stockMove.setNote(note);
    stockMove.setPrintingSettings(Beans.get(TradingNameService.class).getDefaultPrintingSettings(null, company));
    stockMove.setTypeSelect(typeSelect);
    stockMove.setIsWithBackorder(company.getStockConfig().getIsWithBackorder());
    if (typeSelect == StockMoveRepository.TYPE_INCOMING) {
        stockMove.setIsWithReturnSurplus(company.getStockConfig().getIsWithReturnSurplus());
    }
    return stockMove;
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove)

Example 9 with StockMove

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

the class StockMoveServiceImpl method printStockMove.

@Override
public String printStockMove(StockMove stockMove, List<Integer> lstSelectedMove, String reportType) throws AxelorException {
    List<Long> selectedStockMoveListId;
    if (lstSelectedMove != null && !lstSelectedMove.isEmpty()) {
        selectedStockMoveListId = lstSelectedMove.stream().map(integer -> Long.parseLong(integer.toString())).collect(Collectors.toList());
        stockMove = stockMoveRepo.find(selectedStockMoveListId.get(0));
    } else if (stockMove != null && stockMove.getId() != null) {
        selectedStockMoveListId = new ArrayList<>();
        selectedStockMoveListId.add(stockMove.getId());
    } else {
        throw new AxelorException(StockMove.class, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.STOCK_MOVE_10));
    }
    List<StockMove> stockMoveList = stockMoveRepo.all().filter("self.id IN (" + selectedStockMoveListId.stream().map(Object::toString).collect(Collectors.joining(",")) + ") AND self.printingSettings IS NULL").fetch();
    if (!stockMoveList.isEmpty()) {
        String exceptionMessage = String.format(I18n.get(IExceptionMessage.STOCK_MOVES_MISSING_PRINTING_SETTINGS), "<ul>" + stockMoveList.stream().map(StockMove::getStockMoveSeq).collect(Collectors.joining("</li><li>", "<li>", "</li>")) + "<ul>");
        throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, exceptionMessage);
    }
    String stockMoveIds = selectedStockMoveListId.stream().map(Object::toString).collect(Collectors.joining(","));
    String title = I18n.get("Stock move");
    if (stockMove.getStockMoveSeq() != null) {
        title = selectedStockMoveListId.size() == 1 ? I18n.get("StockMove") + " " + stockMove.getStockMoveSeq() : I18n.get("StockMove(s)");
    }
    String locale = reportType.equals(IReport.PICKING_STOCK_MOVE) ? Beans.get(UserService.class).getLanguage() : ReportSettings.getPrintingLocale(stockMove.getPartner());
    ReportSettings reportSettings = ReportFactory.createReport(reportType, title + "-${date}").addParam("StockMoveId", stockMoveIds).addParam("Timezone", null).addParam("Locale", locale);
    if (reportType.equals(IReport.CONFORMITY_CERTIFICATE)) {
        reportSettings.toAttach(stockMove);
    }
    return reportSettings.generate().getFileLink();
}
Also used : AxelorException(com.axelor.exception.AxelorException) StockMove(com.axelor.apps.stock.db.StockMove) ReportSettings(com.axelor.apps.report.engine.ReportSettings) ArrayList(java.util.ArrayList)

Example 10 with StockMove

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

the class StockMoveServiceImpl method copyAndSplitStockMove.

@Override
public Optional<StockMove> copyAndSplitStockMove(StockMove stockMove, List<StockMoveLine> stockMoveLines) throws AxelorException {
    stockMoveLines = MoreObjects.firstNonNull(stockMoveLines, Collections.emptyList());
    StockMove newStockMove = stockMoveRepo.copy(stockMove, false);
    // In copy OriginTypeSelect set null.
    newStockMove.setOriginTypeSelect(stockMove.getOriginTypeSelect());
    newStockMove.setOriginId(stockMove.getOriginId());
    newStockMove.setOrigin(stockMove.getOrigin());
    for (StockMoveLine stockMoveLine : stockMoveLines) {
        if (stockMoveLine.getQty().compareTo(stockMoveLine.getRealQty()) > 0) {
            StockMoveLine newStockMoveLine = copySplittedStockMoveLine(stockMoveLine);
            newStockMove.addStockMoveLineListItem(newStockMoveLine);
        }
    }
    if (ObjectUtils.isEmpty(newStockMove.getStockMoveLineList())) {
        return Optional.empty();
    }
    newStockMove.setRealDate(null);
    newStockMove.setStockMoveSeq(stockMoveToolService.getSequenceStockMove(newStockMove.getTypeSelect(), newStockMove.getCompany()));
    newStockMove.setName(stockMoveToolService.computeName(newStockMove, newStockMove.getStockMoveSeq() + " " + I18n.get(IExceptionMessage.STOCK_MOVE_7) + " " + stockMove.getStockMoveSeq() + " )"));
    newStockMove.setExTaxTotal(stockMoveToolService.compute(newStockMove));
    plan(newStockMove);
    newStockMove.setStockMoveOrigin(stockMove);
    stockMoveRepo.save(newStockMove);
    stockMove.setBackorderId(newStockMove.getId());
    return Optional.of(newStockMove);
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine)

Aggregations

StockMove (com.axelor.apps.stock.db.StockMove)129 AxelorException (com.axelor.exception.AxelorException)57 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)50 ArrayList (java.util.ArrayList)36 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)33 Transactional (com.google.inject.persist.Transactional)32 StockMoveService (com.axelor.apps.stock.service.StockMoveService)31 BigDecimal (java.math.BigDecimal)30 List (java.util.List)25 Company (com.axelor.apps.base.db.Company)23 Map (java.util.Map)21 Product (com.axelor.apps.base.db.Product)19 Invoice (com.axelor.apps.account.db.Invoice)18 StockLocation (com.axelor.apps.stock.db.StockLocation)18 Beans (com.axelor.inject.Beans)17 Optional (java.util.Optional)16 StockMoveLineService (com.axelor.apps.stock.service.StockMoveLineService)15 I18n (com.axelor.i18n.I18n)15 Inject (com.google.inject.Inject)14 HashMap (java.util.HashMap)14