use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class LogisticalFormServiceImpl method addDetailLines.
@Override
public void addDetailLines(LogisticalForm logisticalForm, StockMove stockMove) throws AxelorException {
Objects.requireNonNull(logisticalForm);
Objects.requireNonNull(stockMove);
if (logisticalForm.getDeliverToCustomerPartner() != null && !logisticalForm.getDeliverToCustomerPartner().equals(stockMove.getPartner())) {
throw new AxelorException(logisticalForm, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.LOGISTICAL_FORM_PARTNER_MISMATCH), logisticalForm.getDeliverToCustomerPartner().getName());
}
if (stockMove.getStockMoveLineList() == null) {
return;
}
StockMoveLineService stockMoveLineService = Beans.get(StockMoveLineService.class);
List<Pair<StockMoveLine, BigDecimal>> toAddList = new ArrayList<>();
for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
BigDecimal spreadableQty = stockMoveLineService.computeSpreadableQtyOverLogisticalFormLines(stockMoveLine, logisticalForm);
if (spreadableQty.signum() <= 0) {
continue;
}
if (testForDetailLine(stockMoveLine)) {
toAddList.add(Pair.of(stockMoveLine, spreadableQty));
}
}
if (!toAddList.isEmpty()) {
if (logisticalForm.getLogisticalFormLineList() == null || logisticalForm.getLogisticalFormLineList().isEmpty()) {
addParcelPalletLine(logisticalForm, LogisticalFormLineRepository.TYPE_PARCEL);
}
toAddList.forEach(item -> addDetailLine(logisticalForm, item.getLeft(), item.getRight()));
}
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class LogisticalFormServiceImpl method getFullySpreadStockMoveLineList.
@Override
public List<StockMoveLine> getFullySpreadStockMoveLineList(LogisticalForm logisticalForm) {
List<StockMoveLine> stockMoveLineList = new ArrayList<>();
Map<StockMoveLine, BigDecimal> spreadableQtyMap = new HashMap<>();
for (LogisticalForm item : findPendingLogisticalForms(logisticalForm)) {
spreadableQtyMap.putAll(getSpreadableQtyMap(item));
}
for (Entry<StockMoveLine, BigDecimal> entry : spreadableQtyMap.entrySet()) {
StockMoveLine stockMoveLine = entry.getKey();
BigDecimal spreadableQty = entry.getValue();
if (spreadableQty.signum() <= 0) {
stockMoveLineList.add(stockMoveLine);
}
}
return stockMoveLineList;
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class LogisticalFormServiceImpl method getSpreadableQtyMap.
@Override
public Map<StockMoveLine, BigDecimal> getSpreadableQtyMap(LogisticalForm logisticalForm) {
Set<StockMove> stockMoveSet = new LinkedHashSet<>();
Map<StockMoveLine, BigDecimal> spreadableQtyMap = new LinkedHashMap<>();
if (logisticalForm.getLogisticalFormLineList() != null) {
StockMoveLineService stockMoveLineService = Beans.get(StockMoveLineService.class);
logisticalForm.getLogisticalFormLineList().stream().filter(logisticalFormLine -> logisticalFormLine.getTypeSelect() == LogisticalFormLineRepository.TYPE_DETAIL && logisticalFormLine.getStockMoveLine() != null && logisticalFormLine.getStockMoveLine().getStockMove() != null).forEach(logisticalFormLine -> stockMoveSet.add(logisticalFormLine.getStockMoveLine().getStockMove()));
for (StockMove stockMove : stockMoveSet) {
if (stockMove.getStockMoveLineList() == null) {
continue;
}
for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
BigDecimal spreadableQty = stockMoveLineService.computeSpreadableQtyOverLogisticalFormLines(stockMoveLine, logisticalForm);
spreadableQtyMap.put(stockMoveLine, spreadableQty);
}
}
}
return spreadableQtyMap;
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class LogisticalFormServiceImpl method computeTotals.
@Override
public void computeTotals(LogisticalForm logisticalForm) throws LogisticalFormError {
BigDecimal totalNetMass = BigDecimal.ZERO;
BigDecimal totalGrossMass = BigDecimal.ZERO;
BigDecimal totalVolume = BigDecimal.ZERO;
if (logisticalForm.getLogisticalFormLineList() != null) {
ScriptHelper scriptHelper = getScriptHelper(logisticalForm);
LogisticalFormLineService logisticalFormLineService = Beans.get(LogisticalFormLineService.class);
for (LogisticalFormLine logisticalFormLine : logisticalForm.getLogisticalFormLineList()) {
StockMoveLine stockMoveLine = logisticalFormLine.getStockMoveLine();
if (logisticalFormLine.getTypeSelect() != LogisticalFormLineRepository.TYPE_DETAIL) {
if (logisticalFormLine.getGrossMass() != null) {
totalGrossMass = totalGrossMass.add(logisticalFormLine.getGrossMass());
}
BigDecimal toAdd = logisticalFormLineService.evalVolume(logisticalFormLine, scriptHelper);
if (toAdd == null) {
throw new LogisticalFormError(logisticalForm, I18n.get(IExceptionMessage.LOGISTICAL_FORM_INVALID_DIMENSIONS));
} else {
totalVolume = totalVolume.add(toAdd);
}
} else if (stockMoveLine != null) {
totalNetMass = totalNetMass.add(logisticalFormLine.getQty().multiply(stockMoveLine.getNetMass()));
}
}
totalVolume = totalVolume.divide(new BigDecimal(1_000_000), 10, RoundingMode.HALF_UP);
logisticalForm.setTotalNetMass(totalNetMass.setScale(3, RoundingMode.HALF_UP));
logisticalForm.setTotalGrossMass(totalGrossMass.setScale(3, RoundingMode.HALF_UP));
logisticalForm.setTotalVolume(totalVolume.setScale(3, RoundingMode.HALF_UP));
}
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class PartnerProductQualityRatingServiceImpl method undoCalculation.
@Override
@Transactional(rollbackOn = { Exception.class })
public void undoCalculation(StockMove stockMove) throws AxelorException {
Partner partner = stockMove.getPartner();
if (partner == null || !partner.getIsSupplier()) {
return;
}
List<StockMoveLine> stockMoveLines = stockMove.getStockMoveLineList();
if (stockMoveLines != null) {
for (StockMoveLine stockMoveLine : stockMoveLines) {
Product product = stockMoveLine.getProduct();
Optional<PartnerProductQualityRating> optional = searchPartnerProductQualityRating(partner, product);
if (optional.isPresent()) {
PartnerProductQualityRating partnerProductQualityRating = optional.get();
updatePartnerProductQualityRating(partnerProductQualityRating, stockMoveLine, true);
}
}
}
updateSupplier(partner);
}
Aggregations