use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class StockLocationLineServiceImpl method createDetailLocationLine.
@Override
public StockLocationLine createDetailLocationLine(StockLocation stockLocation, Product product, TrackingNumber trackingNumber) {
LOG.debug("Création d'une ligne de détail de stock : Entrepot? {}, Produit? {}, Num de suivi? {} ", stockLocation.getName(), product.getCode(), trackingNumber.getTrackingNumberSeq());
StockLocationLine detailLocationLine = new StockLocationLine();
detailLocationLine.setDetailsStockLocation(stockLocation);
stockLocation.addDetailsStockLocationLineListItem(detailLocationLine);
detailLocationLine.setProduct(product);
detailLocationLine.setUnit(product.getUnit());
detailLocationLine.setCurrentQty(BigDecimal.ZERO);
detailLocationLine.setFutureQty(BigDecimal.ZERO);
detailLocationLine.setTrackingNumber(trackingNumber);
return detailLocationLine;
}
use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class ABCAnalysisServiceStockImpl method createABCAnalysisLine.
@Override
protected Optional<ABCAnalysisLine> createABCAnalysisLine(ABCAnalysis abcAnalysis, Product product) throws AxelorException {
ABCAnalysisLine abcAnalysisLine = null;
List<StockLocation> stockLocationList = stockLocationService.getAllLocationAndSubLocation(abcAnalysis.getStockLocation(), false);
BigDecimal productQty = BigDecimal.ZERO;
BigDecimal productWorth = BigDecimal.ZERO;
List<StockLocationLine> stockLocationLineList;
int offset = 0;
Query<StockLocationLine> stockLocationLineQuery = stockLocationLineRepository.all().filter("self.stockLocation IN :stockLocationList AND self.product.id = :productId AND self.currentQty != 0 ").bind("stockLocationList", stockLocationList).bind("productId", product.getId());
while (!(stockLocationLineList = stockLocationLineQuery.fetch(FETCH_LIMIT, offset)).isEmpty()) {
offset += stockLocationLineList.size();
abcAnalysis = abcAnalysisRepository.find(abcAnalysis.getId());
if (abcAnalysisLine == null) {
abcAnalysisLine = super.createABCAnalysisLine(abcAnalysis, product).get();
}
for (StockLocationLine stockLocationLine : stockLocationLineList) {
BigDecimal convertedQty = unitConversionService.convert(stockLocationLine.getUnit(), product.getUnit(), stockLocationLine.getCurrentQty(), 5, product);
productQty = productQty.add(convertedQty);
productWorth = productWorth.add(stockLocationLine.getAvgPrice());
}
super.incTotalQty(productQty);
super.incTotalWorth(productWorth);
JPA.clear();
}
if (abcAnalysisLine != null) {
setQtyWorth(abcAnalysisLineRepository.find(abcAnalysisLine.getId()), productQty, productWorth);
}
return Optional.ofNullable(abcAnalysisLine);
}
use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class StockCorrectionController method setDefaultDetails.
public void setDefaultDetails(ActionRequest request, ActionResponse response) {
try {
Long stockLocaLocationLineId = Long.valueOf(request.getContext().get("_stockLocationLineId").toString());
StockLocationLine stockLocationLine = Beans.get(StockLocationLineRepository.class).find(stockLocaLocationLineId);
Map<String, Object> stockCorrectionDetails;
if (stockLocationLine != null) {
stockCorrectionDetails = Beans.get(StockCorrectionService.class).fillDefaultValues(stockLocationLine);
response.setValues(stockCorrectionDetails);
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class ReservedQtyServiceImpl method updateRequestedReservedQty.
@Override
@Transactional(rollbackOn = { Exception.class })
public void updateRequestedReservedQty(StockMoveLine stockMoveLine, BigDecimal newReservedQty) throws AxelorException {
StockLocationLine stockLocationLine = stockLocationLineService.getOrCreateStockLocationLine(stockMoveLine.getStockMove().getFromStockLocation(), stockMoveLine.getProduct());
updateRequestedReservedQty(stockLocationLine, stockMoveLine, newReservedQty);
}
use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class ReservedQtyServiceImpl method changeRequestedQtyLowerThanQty.
/**
* On planning, we want the requested quantity to be equal or lower to the quantity of the line.
* So, if the requested quantity is greater than the quantity, we change it to be equal.
*
* @param stockMoveLine
* @throws AxelorException
*/
protected void changeRequestedQtyLowerThanQty(StockMoveLine stockMoveLine) throws AxelorException {
BigDecimal qty = stockMoveLine.getRealQty().max(BigDecimal.ZERO);
BigDecimal requestedReservedQty = stockMoveLine.getRequestedReservedQty();
if (requestedReservedQty.compareTo(qty) > 0) {
Product product = stockMoveLine.getProduct();
BigDecimal diffRequestedQty = requestedReservedQty.subtract(qty);
stockMoveLine.setRequestedReservedQty(qty);
// update in stock location line
StockLocationLine stockLocationLine = stockLocationLineService.getOrCreateStockLocationLine(stockMoveLine.getStockMove().getFromStockLocation(), product);
BigDecimal diffRequestedQuantityLocation = convertUnitWithProduct(stockMoveLine.getUnit(), stockLocationLine.getUnit(), diffRequestedQty, product);
stockLocationLine.setRequestedReservedQty(stockLocationLine.getRequestedReservedQty().add(diffRequestedQuantityLocation));
}
}
Aggregations