use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class ReservedQtyServiceImpl method requestQty.
@Override
@Transactional(rollbackOn = { Exception.class })
public void requestQty(SaleOrderLine saleOrderLine) throws AxelorException {
if (saleOrderLine.getProduct() == null || !saleOrderLine.getProduct().getStockManaged()) {
return;
}
saleOrderLine.setIsQtyRequested(true);
if (saleOrderLine.getQty().signum() < 0) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SALE_ORDER_LINE_REQUEST_QTY_NEGATIVE));
}
StockMoveLine stockMoveLine = getPlannedStockMoveLine(saleOrderLine);
if (stockMoveLine != null) {
stockMoveLine.setIsQtyRequested(true);
}
this.updateRequestedReservedQty(saleOrderLine, saleOrderLine.getQty());
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class ReservedQtyServiceImpl method updateReservedQty.
@Override
public void updateReservedQty(SaleOrderLine saleOrderLine) throws AxelorException {
// compute from stock move lines
List<StockMoveLine> stockMoveLineList = stockMoveLineRepository.all().filter("self.saleOrderLine.id = :saleOrderLineId " + "AND self.stockMove.statusSelect = :planned").bind("saleOrderLineId", saleOrderLine.getId()).bind("planned", StockMoveRepository.STATUS_PLANNED).fetch();
BigDecimal reservedQty = BigDecimal.ZERO;
for (StockMoveLine stockMoveLine : stockMoveLineList) {
reservedQty = reservedQty.add(convertUnitWithProduct(stockMoveLine.getUnit(), saleOrderLine.getUnit(), stockMoveLine.getReservedQty(), saleOrderLine.getProduct()));
}
saleOrderLine.setReservedQty(reservedQty);
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class ReservedQtyServiceImpl method updateRequestedReservedQuantityInStockMoveLines.
@Override
public BigDecimal updateRequestedReservedQuantityInStockMoveLines(SaleOrderLine saleOrderLine, Product product, BigDecimal newReservedQty) throws AxelorException {
if (product == null || !product.getStockManaged()) {
return BigDecimal.ZERO;
}
List<StockMoveLine> stockMoveLineList = getPlannedStockMoveLines(saleOrderLine);
BigDecimal deliveredQty = saleOrderLine.getDeliveredQty();
BigDecimal allocatedRequestedQty = newReservedQty.subtract(deliveredQty);
if (allocatedRequestedQty.signum() < 0) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SALE_ORDER_LINE_REQUESTED_QTY_TOO_LOW));
}
for (StockMoveLine stockMoveLine : stockMoveLineList) {
BigDecimal stockMoveRequestedQty = convertUnitWithProduct(saleOrderLine.getUnit(), stockMoveLine.getUnit(), allocatedRequestedQty, product);
BigDecimal requestedQtyInStockMoveLine = stockMoveLine.getQty().min(stockMoveRequestedQty);
stockMoveLine.setRequestedReservedQty(requestedQtyInStockMoveLine);
BigDecimal saleOrderRequestedQtyInStockMoveLine = convertUnitWithProduct(stockMoveLine.getUnit(), saleOrderLine.getUnit(), requestedQtyInStockMoveLine, product);
allocatedRequestedQty = allocatedRequestedQty.subtract(saleOrderRequestedQtyInStockMoveLine);
}
saleOrderLine.setRequestedReservedQty(newReservedQty.subtract(allocatedRequestedQty));
return saleOrderLine.getRequestedReservedQty().subtract(deliveredQty);
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class AccountingCutOffServiceImpl method getStockMoveLines.
public List<Long> getStockMoveLines(Batch batch) {
int offset = 0;
Boolean includeNotStockManagedProduct = batch.getSupplychainBatch().getIncludeNotStockManagedProduct();
List<StockMoveLine> stockMoveLineList;
List<Long> stockMoveLineIdList = new ArrayList<>();
Query<StockMove> stockMoveQuery = stockMoverepository.all().filter(":batch MEMBER OF self.batchSet").bind("batch", batch);
List<Long> stockMoveIdList = stockMoveQuery.select("id").fetch(0, 0).stream().map(m -> (Long) m.get("id")).collect(Collectors.toList());
if (stockMoveIdList.isEmpty()) {
stockMoveLineIdList.add(0L);
} else {
Query<StockMoveLine> stockMoveLineQuery = stockMoveLineRepository.all().filter("self.stockMove.id IN :stockMoveIdList").bind("stockMoveIdList", stockMoveIdList).order("id");
while (!(stockMoveLineList = stockMoveLineQuery.fetch(FETCH_LIMIT, offset)).isEmpty()) {
offset += stockMoveLineList.size();
for (StockMoveLine stockMoveLine : stockMoveLineList) {
Product product = stockMoveLine.getProduct();
if (!checkStockMoveLine(stockMoveLine, product, includeNotStockManagedProduct)) {
stockMoveLineIdList.add(stockMoveLine.getId());
}
}
JPA.clear();
}
}
return stockMoveLineIdList;
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class AccountingCutOffServiceImpl method generateProductMoveLine.
protected MoveLine generateProductMoveLine(Move move, StockMoveLine stockMoveLine, String origin, boolean isPurchase, boolean recoveredTax, boolean ati, String moveDescription, boolean isReverse, LocalDate originDate) throws AxelorException {
SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
PurchaseOrderLine purchaseOrderLine = stockMoveLine.getPurchaseOrderLine();
Company company = move.getCompany();
LocalDate moveDate = move.getDate();
Partner partner = move.getPartner();
boolean isFixedAssets = false;
BigDecimal amountInCurrency = null;
BigDecimal totalQty = null;
BigDecimal notInvoicedQty = null;
if (isPurchase && purchaseOrderLine != null) {
totalQty = purchaseOrderLine.getQty();
notInvoicedQty = unitConversionService.convert(stockMoveLine.getUnit(), purchaseOrderLine.getUnit(), stockMoveLine.getRealQty().subtract(stockMoveLine.getQtyInvoiced()), stockMoveLine.getRealQty().scale(), purchaseOrderLine.getProduct());
isFixedAssets = purchaseOrderLine.getFixedAssets();
if (ati && !recoveredTax) {
amountInCurrency = purchaseOrderLine.getInTaxTotal();
} else {
amountInCurrency = purchaseOrderLine.getExTaxTotal();
}
}
if (!isPurchase && saleOrderLine != null) {
totalQty = saleOrderLine.getQty();
notInvoicedQty = unitConversionService.convert(stockMoveLine.getUnit(), saleOrderLine.getUnit(), stockMoveLine.getRealQty().subtract(stockMoveLine.getQtyInvoiced()), stockMoveLine.getRealQty().scale(), saleOrderLine.getProduct());
if (ati) {
amountInCurrency = saleOrderLine.getInTaxTotal();
} else {
amountInCurrency = saleOrderLine.getExTaxTotal();
}
}
if (totalQty == null || BigDecimal.ZERO.compareTo(totalQty) == 0) {
return null;
}
BigDecimal qtyRate = notInvoicedQty.divide(totalQty, 10, RoundingMode.HALF_UP);
amountInCurrency = amountInCurrency.multiply(qtyRate).setScale(2, RoundingMode.HALF_UP);
if (amountInCurrency == null || amountInCurrency.compareTo(BigDecimal.ZERO) == 0) {
return null;
}
Product product = stockMoveLine.getProduct();
Account account = accountManagementAccountService.getProductAccount(product, company, partner.getFiscalPosition(), isPurchase, isFixedAssets);
boolean isDebit = false;
if ((isPurchase && amountInCurrency.compareTo(BigDecimal.ZERO) == 1) || !isPurchase && amountInCurrency.compareTo(BigDecimal.ZERO) == -1) {
isDebit = true;
}
if (isReverse) {
isDebit = !isDebit;
}
MoveLine moveLine = moveLineService.createMoveLine(move, partner, account, amountInCurrency, isDebit, originDate, ++counter, origin, moveDescription);
moveLine.setDate(moveDate);
moveLine.setDueDate(moveDate);
getAndComputeAnalyticDistribution(product, move, moveLine);
move.addMoveLineListItem(moveLine);
if (recoveredTax) {
TaxLine taxLine = accountManagementAccountService.getTaxLine(originDate, product, company, partner.getFiscalPosition(), isPurchase);
if (taxLine != null) {
moveLine.setTaxLine(taxLine);
moveLine.setTaxRate(taxLine.getValue());
moveLine.setTaxCode(taxLine.getTax().getCode());
if (taxLine.getValue().compareTo(BigDecimal.ZERO) != 0) {
generateTaxMoveLine(move, moveLine, origin, isPurchase, isFixedAssets, moveDescription);
}
}
}
return moveLine;
}
Aggregations