use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class ReservedQtyServiceImpl method updateReservedQty.
@Override
@Transactional(rollbackOn = { Exception.class })
public void updateReservedQty(SaleOrderLine saleOrderLine, BigDecimal newReservedQty) throws AxelorException {
if (saleOrderLine.getProduct() == null || !saleOrderLine.getProduct().getStockManaged()) {
return;
}
StockMoveLine stockMoveLine = getPlannedStockMoveLine(saleOrderLine);
checkBeforeUpdatingQties(stockMoveLine, newReservedQty);
if (Beans.get(AppSupplychainService.class).getAppSupplychain().getBlockDeallocationOnAvailabilityRequest()) {
checkAvailabilityRequest(stockMoveLine, newReservedQty, false);
}
BigDecimal newRequestedReservedQty = newReservedQty.add(saleOrderLine.getDeliveredQty());
// update requested reserved qty
if (newRequestedReservedQty.compareTo(saleOrderLine.getRequestedReservedQty()) > 0 && newReservedQty.compareTo(BigDecimal.ZERO) > 0) {
requestQty(saleOrderLine);
}
StockLocationLine stockLocationLine = stockLocationLineService.getOrCreateStockLocationLine(stockMoveLine.getStockMove().getFromStockLocation(), stockMoveLine.getProduct());
BigDecimal availableQtyToBeReserved = stockLocationLine.getCurrentQty().subtract(stockLocationLine.getReservedQty());
BigDecimal diffReservedQuantity = newReservedQty.subtract(saleOrderLine.getReservedQty());
Product product = stockMoveLine.getProduct();
BigDecimal diffReservedQuantityLocation = convertUnitWithProduct(saleOrderLine.getUnit(), stockLocationLine.getUnit(), diffReservedQuantity, product);
if (availableQtyToBeReserved.compareTo(diffReservedQuantityLocation) < 0) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SALE_ORDER_LINE_QTY_NOT_AVAILABLE));
}
// update in stock move line and sale order line
updateReservedQuantityInStockMoveLineFromSaleOrderLine(saleOrderLine, stockMoveLine.getProduct(), newReservedQty);
// update in stock location line
updateReservedQty(stockLocationLine);
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class StockMoveLineSupplychainRepository method populate.
@Override
public Map<String, Object> populate(Map<String, Object> json, Map<String, Object> context) {
Long stockMoveLineId = (Long) json.get("id");
StockMoveLine stockMoveLine = find(stockMoveLineId);
StockMove stockMove = stockMoveLine.getStockMove();
Map<String, Object> stockMoveLineMap = super.populate(json, context);
if (stockMove != null && stockMove.getStatusSelect() == StockMoveRepository.STATUS_REALIZED) {
Beans.get(StockMoveLineServiceSupplychain.class).setInvoiceStatus(stockMoveLine);
json.put("availableStatus", stockMoveLine.getProduct() != null && stockMoveLine.getProduct().getStockManaged() ? stockMoveLine.getAvailableStatus() : null);
json.put("availableStatusSelect", stockMoveLine.getAvailableStatusSelect());
}
return stockMoveLineMap;
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class StockMoveSupplychainRepository method copy.
@Override
public StockMove copy(StockMove entity, boolean deep) {
StockMove copy = super.copy(entity, deep);
copy.setInvoiceSet(null);
copy.setOriginTypeSelect(null);
copy.setOrigin(null);
copy.setOriginId(null);
if (copy.getStockMoveLineList() != null) {
for (StockMoveLine stockMoveLine : copy.getStockMoveLineList()) {
stockMoveLine.setReservedQty(BigDecimal.ZERO);
stockMoveLine.setRequestedReservedQty(BigDecimal.ZERO);
stockMoveLine.setIsQtyRequested(false);
stockMoveLine.setReservationDateTime(null);
stockMoveLine.setQtyInvoiced(null);
stockMoveLine.setSaleOrderLine(null);
stockMoveLine.setPurchaseOrderLine(null);
}
}
copy.setInvoicingStatusSelect(StockMoveRepository.STATUS_NOT_INVOICED);
return copy;
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class LogisticalFormLineServiceImpl method getStockMoveLineDomain.
@Override
public String getStockMoveLineDomain(LogisticalFormLine logisticalFormLine) {
long partnerId = 0;
List<String> domainList = new ArrayList<>();
LogisticalForm logisticalForm = logisticalFormLine.getLogisticalForm();
if (logisticalForm != null) {
Partner deliverToCustomerPartner = logisticalForm.getDeliverToCustomerPartner();
if (deliverToCustomerPartner != null) {
partnerId = deliverToCustomerPartner.getId();
}
}
domainList.add(String.format("self.stockMove.partner.id = %d", partnerId));
domainList.add(String.format("self.stockMove.typeSelect = %d", StockMoveRepository.TYPE_OUTGOING));
domainList.add(String.format("self.stockMove.statusSelect in (%d, %d)", StockMoveRepository.STATUS_PLANNED, StockMoveRepository.STATUS_REALIZED));
domainList.add("self.realQty > 0");
domainList.add("COALESCE(self.stockMove.fullySpreadOverLogisticalFormsFlag, FALSE) = FALSE");
if (logisticalForm.getStockLocation() != null) {
domainList.add(String.format("self.stockMove.fromStockLocation.id = %d", logisticalForm.getStockLocation().getId()));
}
List<StockMoveLine> fullySpreadStockMoveLineList = Beans.get(LogisticalFormService.class).getFullySpreadStockMoveLineList(logisticalForm);
if (!fullySpreadStockMoveLineList.isEmpty()) {
String idListString = StringTool.getIdListString(fullySpreadStockMoveLineList);
domainList.add(String.format("self.id NOT IN (%s)", idListString));
}
return domainList.stream().map(domain -> String.format("(%s)", domain)).collect(Collectors.joining(" AND "));
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class LogisticalFormServiceImpl method checkInconsistentQties.
protected void checkInconsistentQties(LogisticalForm logisticalForm, List<String> errorMessageList) {
Map<StockMoveLine, BigDecimal> spreadableQtyMap = getSpreadableQtyMap(logisticalForm);
Map<StockMoveLine, BigDecimal> spreadQtyMap = getSpreadQtyMap(logisticalForm);
Locale locale = AppFilter.getLocale();
NumberFormat nf = NumberFormat.getInstance(locale);
for (Entry<StockMoveLine, BigDecimal> entry : spreadableQtyMap.entrySet()) {
StockMoveLine stockMoveLine = entry.getKey();
BigDecimal spreadableQty = entry.getValue();
if (spreadableQty.signum() != 0) {
BigDecimal spreadQty = spreadQtyMap.getOrDefault(stockMoveLine, BigDecimal.ZERO);
BigDecimal expectedQty = spreadQty.add(spreadableQty);
String errorMessage = String.format(locale, I18n.get(IExceptionMessage.LOGISTICAL_FORM_LINES_INCONSISTENT_QUANTITY), String.format("%s (%s)", stockMoveLine.getProductName(), stockMoveLine.getStockMove().getStockMoveSeq()), nf.format(spreadQty), nf.format(expectedQty));
errorMessageList.add(errorMessage);
}
}
}
Aggregations