use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class StockMoveLineController method deallocateAll.
/**
* Called from stock move form view, on clicking allocateAll button on one stock move line. Call
* {@link ReservedQtyService#updateReservedQty(stockMoveLine, BigDecimal.ZERO)}.
*
* @param request
* @param response
*/
public void deallocateAll(ActionRequest request, ActionResponse response) {
try {
StockMoveLine stockMoveLine = request.getContext().asType(StockMoveLine.class);
stockMoveLine = Beans.get(StockMoveLineRepository.class).find(stockMoveLine.getId());
Beans.get(ReservedQtyService.class).updateReservedQty(stockMoveLine, BigDecimal.ZERO);
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class StockMoveLineController method cancelReservation.
/**
* Called from stock move line form view, on request qty click. Call {@link
* ReservedQtyService#cancelReservation(StockMoveLine)}.
*
* @param request
* @param response
*/
public void cancelReservation(ActionRequest request, ActionResponse response) {
try {
StockMoveLine stockMoveLine = request.getContext().asType(StockMoveLine.class);
stockMoveLine = Beans.get(StockMoveLineRepository.class).find(stockMoveLine.getId());
Product product = stockMoveLine.getProduct();
if (product == null || !product.getStockManaged()) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SALE_ORDER_LINE_PRODUCT_NOT_STOCK_MANAGED));
}
Beans.get(ReservedQtyService.class).cancelReservation(stockMoveLine);
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class StockMoveLineController method requestQty.
/**
* Called from stock move line form view, on request qty click. Call {@link
* ReservedQtyService#requestQty(StockMoveLine)}.
*
* @param request
* @param response
*/
public void requestQty(ActionRequest request, ActionResponse response) {
try {
StockMoveLine stockMoveLine = request.getContext().asType(StockMoveLine.class);
stockMoveLine = Beans.get(StockMoveLineRepository.class).find(stockMoveLine.getId());
Product product = stockMoveLine.getProduct();
if (product == null || !product.getStockManaged()) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SALE_ORDER_LINE_PRODUCT_NOT_STOCK_MANAGED));
}
Beans.get(ReservedQtyService.class).requestQty(stockMoveLine);
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class SaleOrderServiceSupplychainImpl method enableEditOrder.
@Override
@Transactional(rollbackOn = { Exception.class })
public boolean enableEditOrder(SaleOrder saleOrder) throws AxelorException {
boolean checkAvailabiltyRequest = super.enableEditOrder(saleOrder);
if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
return checkAvailabiltyRequest;
}
List<StockMove> allStockMoves = Beans.get(StockMoveRepository.class).findAllBySaleOrderAndStatus(StockMoveRepository.ORIGIN_SALE_ORDER, saleOrder.getId(), StockMoveRepository.STATUS_PLANNED).fetch();
List<StockMove> stockMoves = !allStockMoves.isEmpty() ? allStockMoves.stream().filter(stockMove -> !stockMove.getAvailabilityRequest()).collect(Collectors.toList()) : allStockMoves;
checkAvailabiltyRequest = stockMoves.size() != allStockMoves.size() ? true : checkAvailabiltyRequest;
if (!stockMoves.isEmpty()) {
StockMoveService stockMoveService = Beans.get(StockMoveService.class);
CancelReason cancelReason = appSupplychain.getCancelReasonOnChangingSaleOrder();
if (cancelReason == null) {
throw new AxelorException(appSupplychain, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, IExceptionMessage.SUPPLYCHAIN_MISSING_CANCEL_REASON_ON_CHANGING_SALE_ORDER);
}
for (StockMove stockMove : stockMoves) {
stockMoveService.cancel(stockMove, cancelReason);
stockMove.setArchived(true);
for (StockMoveLine stockMoveline : stockMove.getStockMoveLineList()) {
stockMoveline.setSaleOrderLine(null);
stockMoveline.setArchived(true);
}
}
}
return checkAvailabiltyRequest;
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class SaleOrderStockServiceImpl method setReservationDateTime.
/**
* Fill reservation date time in stock move lines with sale order following supplychain
* configuration.
*
* @param stockMove
* @param saleOrder
*/
protected void setReservationDateTime(StockMove stockMove, SaleOrder saleOrder) throws AxelorException {
SupplyChainConfig supplyChainConfig = supplyChainConfigService.getSupplyChainConfig(saleOrder.getCompany());
List<StockMoveLine> stockMoveLineList = stockMove.getStockMoveLineList();
if (stockMoveLineList == null) {
stockMoveLineList = new ArrayList<>();
}
for (StockMoveLine stockMoveLine : stockMoveLineList) {
LocalDateTime reservationDateTime;
switch(supplyChainConfig.getSaleOrderReservationDateSelect()) {
case SupplyChainConfigRepository.SALE_ORDER_CONFIRMATION_DATE:
reservationDateTime = saleOrder.getConfirmationDateTime();
break;
case SupplyChainConfigRepository.SALE_ORDER_SHIPPING_DATE:
SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
if (saleOrderLine == null || saleOrderLine.getEstimatedDelivDate() == null) {
reservationDateTime = null;
} else {
reservationDateTime = saleOrderLine.getEstimatedDelivDate().atStartOfDay();
}
break;
default:
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.RESERVATION_SALE_ORDER_DATE_CONFIG_INCORRECT_VALUE));
}
if (reservationDateTime == null) {
reservationDateTime = Beans.get(AppBaseService.class).getTodayDateTime().toLocalDateTime();
}
stockMoveLine.setReservationDateTime(reservationDateTime);
}
}
Aggregations