use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class SaleOrderStockServiceImpl method createStockMoveLine.
@Override
public StockMoveLine createStockMoveLine(StockMove stockMove, SaleOrderLine saleOrderLine, BigDecimal qty) throws AxelorException {
if (this.isStockMoveProduct(saleOrderLine)) {
Unit unit = saleOrderLine.getProduct().getUnit();
BigDecimal priceDiscounted = saleOrderLine.getPriceDiscounted();
BigDecimal requestedReservedQty = saleOrderLine.getRequestedReservedQty().subtract(saleOrderLine.getDeliveredQty());
BigDecimal companyUnitPriceUntaxed = (BigDecimal) productCompanyService.get(saleOrderLine.getProduct(), "costPrice", saleOrderLine.getSaleOrder() != null ? saleOrderLine.getSaleOrder().getCompany() : null);
if (unit != null && !unit.equals(saleOrderLine.getUnit())) {
qty = unitConversionService.convert(saleOrderLine.getUnit(), unit, qty, qty.scale(), saleOrderLine.getProduct());
priceDiscounted = unitConversionService.convert(unit, saleOrderLine.getUnit(), priceDiscounted, appBaseService.getNbDecimalDigitForUnitPrice(), saleOrderLine.getProduct());
requestedReservedQty = unitConversionService.convert(saleOrderLine.getUnit(), unit, requestedReservedQty, requestedReservedQty.scale(), saleOrderLine.getProduct());
}
BigDecimal taxRate = BigDecimal.ZERO;
TaxLine taxLine = saleOrderLine.getTaxLine();
if (taxLine != null) {
taxRate = taxLine.getValue();
}
if (saleOrderLine.getQty().signum() != 0) {
companyUnitPriceUntaxed = saleOrderLine.getCompanyExTaxTotal().divide(saleOrderLine.getQty(), Beans.get(AppBaseService.class).getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP);
}
StockMoveLine stockMoveLine = stockMoveLineSupplychainService.createStockMoveLine(saleOrderLine.getProduct(), saleOrderLine.getProductName(), saleOrderLine.getDescription(), qty, requestedReservedQty, priceDiscounted, companyUnitPriceUntaxed, null, unit, stockMove, StockMoveLineService.TYPE_SALES, saleOrderLine.getSaleOrder().getInAti(), taxRate, saleOrderLine, null);
if (saleOrderLine.getDeliveryState() == 0) {
saleOrderLine.setDeliveryState(SaleOrderLineRepository.DELIVERY_STATE_NOT_DELIVERED);
}
return stockMoveLine;
}
return null;
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class DeclarationOfExchangesExporterServices method exportToCSV.
// TODO: factorize code to parent.
@Override
protected String exportToCSV() throws AxelorException {
Path path = getFilePath();
Period period = declarationOfExchanges.getPeriod();
List<StockMoveLine> stockMoveLines = Beans.get(StockMoveLineRepository.class).findForDeclarationOfExchanges(period.getFromDate(), period.getToDate(), declarationOfExchanges.getProductTypeSelect(), declarationOfExchanges.getStockMoveTypeSelect(), declarationOfExchanges.getCountry(), declarationOfExchanges.getCompany()).fetch();
List<String[]> dataList = new ArrayList<>(stockMoveLines.size());
int lineNum = 1;
for (StockMoveLine stockMoveLine : stockMoveLines) {
String[] data = new String[columnHeadersList.size()];
StockMove stockMove = stockMoveLine.getStockMove();
BigDecimal fiscalValue = stockMoveLine.getUnitPriceUntaxed().multiply(stockMoveLine.getRealQty()).setScale(0, RoundingMode.HALF_UP);
String taxNbr;
if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING && stockMoveLine.getRegime() != Regime.OTHER_EXPEDITIONS) {
if (stockMove.getPartner() == null) {
taxNbr = String.format(I18n.get("Partner is missing on stock move %s."), stockMove.getName());
}
if (StringUtils.isBlank(stockMove.getPartner().getTaxNbr())) {
taxNbr = String.format(I18n.get("Tax number is missing on partner %s."), stockMove.getPartner().getName());
}
taxNbr = stockMove.getPartner().getTaxNbr();
} else {
taxNbr = "";
}
data[columnHeadersList.indexOf(LINE_NUM)] = String.valueOf(lineNum++);
data[columnHeadersList.indexOf(FISC_VAL)] = String.valueOf(fiscalValue);
data[columnHeadersList.indexOf(TAKER)] = taxNbr;
dataList.add(data);
}
try {
MoreFiles.createParentDirectories(path);
CsvTool.csvWriter(path.getParent().toString(), path.getFileName().toString(), ';', getTranslatedHeaders(), dataList);
} catch (IOException e) {
throw new AxelorException(e, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, e.getLocalizedMessage());
}
return attach(path.toString());
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class FixedAssetServiceSupplyChainImpl method createFixedAssets.
@Transactional
@Override
public List<FixedAsset> createFixedAssets(Invoice invoice) throws AxelorException {
List<FixedAsset> fixedAssetList = super.createFixedAssets(invoice);
if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
return fixedAssetList;
}
if (fixedAssetList.isEmpty()) {
return new ArrayList<>();
}
StockLocation stockLocation = invoice.getPurchaseOrder() != null ? invoice.getPurchaseOrder().getStockLocation() : null;
for (FixedAsset fixedAsset : fixedAssetList) {
PurchaseOrderLine pol = fixedAsset.getInvoiceLine().getPurchaseOrderLine();
fixedAsset.setStockLocation(stockLocation);
if (fixedAsset.getInvoiceLine().getIncomingStockMove() != null && CollectionUtils.isNotEmpty(fixedAsset.getInvoiceLine().getIncomingStockMove().getStockMoveLineList())) {
fixedAsset.setTrackingNumber(fixedAsset.getInvoiceLine().getIncomingStockMove().getStockMoveLineList().stream().filter(l -> pol.equals(l.getPurchaseOrderLine())).findFirst().map(StockMoveLine::getTrackingNumber).orElse(null));
fixedAsset.setStockLocation(fixedAsset.getInvoiceLine().getIncomingStockMove().getToStockLocation());
}
}
return fixedAssetList;
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class StockMoveServiceSupplychainImpl method verifyProductStock.
@Override
public void verifyProductStock(StockMove stockMove) throws AxelorException {
AppSupplychain appSupplychain = appSupplyChainService.getAppSupplychain();
if (stockMove.getAvailabilityRequest() && stockMove.getStockMoveLineList() != null && appSupplychain.getIsVerifyProductStock() && stockMove.getFromStockLocation() != null) {
StringJoiner notAvailableProducts = new StringJoiner(",");
int counter = 1;
for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
boolean isAvailableProduct = stockMoveLineServiceSupplychain.isAvailableProduct(stockMove, stockMoveLine);
if (!isAvailableProduct && counter <= 10) {
notAvailableProducts.add(stockMoveLine.getProduct().getFullName());
counter++;
}
}
if (!Strings.isNullOrEmpty(notAvailableProducts.toString())) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, String.format(I18n.get(IExceptionMessage.STOCK_MOVE_VERIFY_PRODUCT_STOCK_ERROR), notAvailableProducts.toString()));
}
}
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class StockMoveServiceSupplychainImpl method realize.
@Override
@Transactional(rollbackOn = { Exception.class })
public String realize(StockMove stockMove, boolean check) throws AxelorException {
if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
return super.realize(stockMove, check);
}
LOG.debug("RĂ©alisation du mouvement de stock : {} ", stockMove.getStockMoveSeq());
String newStockSeq = super.realize(stockMove, check);
AppSupplychain appSupplychain = appSupplyChainService.getAppSupplychain();
if (StockMoveRepository.ORIGIN_SALE_ORDER.equals(stockMove.getOriginTypeSelect())) {
updateSaleOrderLinesDeliveryState(stockMove, !stockMove.getIsReversion());
// Update linked saleOrder delivery state depending on BackOrder's existence
SaleOrder saleOrder = saleOrderRepo.find(stockMove.getOriginId());
if (newStockSeq != null) {
saleOrder.setDeliveryState(SaleOrderRepository.DELIVERY_STATE_PARTIALLY_DELIVERED);
} else {
Beans.get(SaleOrderStockService.class).updateDeliveryState(saleOrder);
if (appSupplychain.getTerminateSaleOrderOnDelivery()) {
terminateOrConfirmSaleOrderStatus(saleOrder);
}
}
Beans.get(SaleOrderRepository.class).save(saleOrder);
} else if (StockMoveRepository.ORIGIN_PURCHASE_ORDER.equals(stockMove.getOriginTypeSelect())) {
updatePurchaseOrderLines(stockMove, !stockMove.getIsReversion());
// Update linked purchaseOrder receipt state depending on BackOrder's existence
PurchaseOrder purchaseOrder = purchaseOrderRepo.find(stockMove.getOriginId());
if (newStockSeq != null) {
purchaseOrder.setReceiptState(PurchaseOrderRepository.STATE_PARTIALLY_RECEIVED);
} else {
Beans.get(PurchaseOrderStockService.class).updateReceiptState(purchaseOrder);
if (appSupplychain.getTerminatePurchaseOrderOnReceipt()) {
finishOrValidatePurchaseOrderStatus(purchaseOrder);
}
}
Beans.get(PurchaseOrderRepository.class).save(purchaseOrder);
}
if (appSupplyChainService.getAppSupplychain().getManageStockReservation()) {
Beans.get(ReservedQtyService.class).updateReservedQuantity(stockMove, StockMoveRepository.STATUS_REALIZED);
}
detachNonDeliveredStockMoveLines(stockMove);
List<Long> trackingNumberIds = stockMove.getStockMoveLineList().stream().map(StockMoveLine::getTrackingNumber).filter(Objects::nonNull).map(TrackingNumber::getId).filter(Objects::nonNull).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(trackingNumberIds)) {
Query update = JPA.em().createQuery("UPDATE FixedAsset self SET self.stockLocation = :stockLocation WHERE self.trackingNumber.id IN (:trackingNumber)");
update.setParameter("stockLocation", stockMove.getToStockLocation());
update.setParameter("trackingNumber", trackingNumberIds);
update.executeUpdate();
}
return newStockSeq;
}
Aggregations