use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.
the class SaleOrderStockServiceImpl method createStockMove.
protected Optional<StockMove> createStockMove(SaleOrder saleOrder, LocalDate estimatedDeliveryDate, List<SaleOrderLine> saleOrderLineList) throws AxelorException {
StockMove stockMove = this.createStockMove(saleOrder, saleOrder.getCompany(), estimatedDeliveryDate);
stockMove.setDeliveryCondition(saleOrder.getDeliveryCondition());
for (SaleOrderLine saleOrderLine : saleOrderLineList) {
if (saleOrderLine.getProduct() != null) {
BigDecimal qty = saleOrderLineServiceSupplyChain.computeUndeliveredQty(saleOrderLine);
if (qty.signum() > 0 && !existActiveStockMoveForSaleOrderLine(saleOrderLine)) {
createStockMoveLine(stockMove, saleOrderLine, qty);
}
}
}
if (stockMove.getStockMoveLineList() == null || stockMove.getStockMoveLineList().isEmpty()) {
return Optional.empty();
}
if (stockMove.getStockMoveLineList().stream().noneMatch(stockMoveLine -> stockMoveLine.getSaleOrderLine() != null && stockMoveLine.getSaleOrderLine().getTypeSelect() == SaleOrderLineRepository.TYPE_NORMAL)) {
stockMove.setFullySpreadOverLogisticalFormsFlag(true);
}
boolean isNeedingConformityCertificate = saleOrder.getIsNeedingConformityCertificate();
stockMove.setIsNeedingConformityCertificate(isNeedingConformityCertificate);
if (isNeedingConformityCertificate) {
stockMove.setSignatoryUser(stockConfigService.getStockConfig(stockMove.getCompany()).getSignatoryUser());
}
SupplyChainConfig supplychainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(saleOrder.getCompany());
if (supplychainConfig.getDefaultEstimatedDate() != null && supplychainConfig.getDefaultEstimatedDate() == SupplyChainConfigRepository.CURRENT_DATE && stockMove.getEstimatedDate() == null) {
stockMove.setEstimatedDate(appBaseService.getTodayDate(saleOrder.getCompany()));
} else if (supplychainConfig.getDefaultEstimatedDate() == SupplyChainConfigRepository.CURRENT_DATE_PLUS_DAYS && stockMove.getEstimatedDate() == null) {
stockMove.setEstimatedDate(appBaseService.getTodayDate(saleOrder.getCompany()).plusDays(supplychainConfig.getNumberOfDays().longValue()));
}
setReservationDateTime(stockMove, saleOrder);
stockMoveService.plan(stockMove);
return Optional.of(stockMove);
}
use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.
the class SaleOrderStockServiceImpl method getAllSaleOrderLinePerDate.
protected Map<LocalDate, List<SaleOrderLine>> getAllSaleOrderLinePerDate(SaleOrder saleOrder) {
Map<LocalDate, List<SaleOrderLine>> saleOrderLinePerDateMap = new HashMap<>();
for (SaleOrderLine saleOrderLine : saleOrder.getSaleOrderLineList()) {
if (saleOrderLineServiceSupplyChain.computeUndeliveredQty(saleOrderLine).signum() <= 0) {
continue;
}
LocalDate dateKey = saleOrderLine.getEstimatedDelivDate();
if (dateKey == null) {
dateKey = saleOrderLine.getSaleOrder().getDeliveryDate();
}
if (dateKey == null) {
dateKey = saleOrderLine.getDesiredDelivDate();
}
List<SaleOrderLine> saleOrderLineLists = saleOrderLinePerDateMap.get(dateKey);
if (saleOrderLineLists == null) {
saleOrderLineLists = new ArrayList<>();
saleOrderLinePerDateMap.put(dateKey, saleOrderLineLists);
}
saleOrderLineLists.add(saleOrderLine);
}
return saleOrderLinePerDateMap;
}
use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.
the class SaleOrderStockServiceImpl method createStocksMovesFromSaleOrder.
@Override
@Transactional(rollbackOn = { Exception.class })
public List<Long> createStocksMovesFromSaleOrder(SaleOrder saleOrder) throws AxelorException {
if (!this.isSaleOrderWithProductsToDeliver(saleOrder)) {
return null;
}
if (saleOrder.getStockLocation() == null) {
throw new AxelorException(saleOrder, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.SO_MISSING_STOCK_LOCATION), saleOrder.getSaleOrderSeq());
}
List<Long> stockMoveList = new ArrayList<>();
Map<LocalDate, List<SaleOrderLine>> saleOrderLinePerDateMap = getAllSaleOrderLinePerDate(saleOrder);
for (LocalDate estimatedDeliveryDate : saleOrderLinePerDateMap.keySet().stream().filter(x -> x != null).sorted((x, y) -> x.compareTo(y)).collect(Collectors.toList())) {
List<SaleOrderLine> saleOrderLineList = saleOrderLinePerDateMap.get(estimatedDeliveryDate);
Optional<StockMove> stockMove = createStockMove(saleOrder, estimatedDeliveryDate, saleOrderLineList);
stockMove.map(StockMove::getId).ifPresent(stockMoveList::add);
}
Optional<List<SaleOrderLine>> saleOrderLineList = Optional.ofNullable(saleOrderLinePerDateMap.get(null));
if (saleOrderLineList.isPresent()) {
Optional<StockMove> stockMove = createStockMove(saleOrder, null, saleOrderLineList.get());
stockMove.map(StockMove::getId).ifPresent(stockMoveList::add);
}
return stockMoveList;
}
use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.
the class StockLocationLineReservationServiceImpl method deallocateAll.
@Override
@Transactional(rollbackOn = { Exception.class })
public void deallocateAll(StockLocationLine stockLocationLine) throws AxelorException {
List<StockMoveLine> stockMoveLineList = Beans.get(StockMoveLineRepository.class).all().filter("self.product = :product " + "AND self.stockMove.fromStockLocation = :stockLocation " + "AND self.stockMove.statusSelect = :planned " + "AND (self.stockMove.availabilityRequest IS FALSE " + "OR self.stockMove.availabilityRequest IS NULL) " + "AND self.reservedQty > 0").bind("product", stockLocationLine.getProduct()).bind("stockLocation", stockLocationLine.getStockLocation()).bind("planned", StockMoveRepository.STATUS_PLANNED).fetch();
for (StockMoveLine stockMoveLine : stockMoveLineList) {
stockMoveLine.setReservedQty(BigDecimal.ZERO);
SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
if (saleOrderLine != null) {
saleOrderLine.setReservedQty(BigDecimal.ZERO);
}
}
Beans.get(ReservedQtyService.class).updateReservedQty(stockLocationLine);
}
use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.
the class WorkflowCancelServiceSupplychainImpl method saleOrderLineProcess.
public SaleOrder saleOrderLineProcess(Invoice invoice, InvoiceLine invoiceLine) throws AxelorException {
SaleOrderLine saleOrderLine = invoiceLine.getSaleOrderLine();
if (saleOrderLine == null) {
return null;
}
SaleOrder saleOrder = saleOrderLine.getSaleOrder();
// Update invoiced amount on sale order line
BigDecimal invoicedAmountToAdd = invoiceLine.getExTaxTotal();
// If is it a refund invoice, so we negate the amount invoiced
if (InvoiceToolService.isRefund(invoiceLine.getInvoice())) {
invoicedAmountToAdd = invoicedAmountToAdd.negate();
}
if (!invoice.getCurrency().equals(saleOrder.getCurrency()) && saleOrderLine.getCompanyExTaxTotal().compareTo(BigDecimal.ZERO) != 0) {
// If the sale order currency is different from the invoice currency, use company currency to
// calculate a rate. This rate will be applied to sale order line
BigDecimal currentCompanyInvoicedAmount = invoiceLine.getCompanyExTaxTotal();
BigDecimal rate = currentCompanyInvoicedAmount.divide(saleOrderLine.getCompanyExTaxTotal(), 4, RoundingMode.HALF_UP);
invoicedAmountToAdd = rate.multiply(saleOrderLine.getExTaxTotal());
}
saleOrderLine.setAmountInvoiced(saleOrderLine.getAmountInvoiced().subtract(invoicedAmountToAdd));
return saleOrder;
}
Aggregations