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