Search in sources :

Example 6 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.

the class StockCorrectionServiceImpl method generateStockMove.

public StockMove generateStockMove(StockCorrection stockCorrection) throws AxelorException {
    StockLocation toStockLocation = stockCorrection.getStockLocation();
    Company company = toStockLocation.getCompany();
    StockLocation fromStockLocation = stockConfigService.getInventoryVirtualStockLocation(stockConfigService.getStockConfig(company));
    StockMoveService stockMoveService = Beans.get(StockMoveService.class);
    StockMoveLineService stockMoveLineService = Beans.get(StockMoveLineService.class);
    StockLocationLine stockLocationLine = null;
    StockLocationLineService stockLocationLineService = Beans.get(StockLocationLineService.class);
    if (stockCorrection.getTrackingNumber() == null) {
        stockLocationLine = stockLocationLineService.getStockLocationLine(stockCorrection.getStockLocation(), stockCorrection.getProduct());
    } else {
        stockLocationLine = stockLocationLineService.getDetailLocationLine(stockCorrection.getStockLocation(), stockCorrection.getProduct(), stockCorrection.getTrackingNumber());
    }
    BigDecimal realQty = stockCorrection.getRealQty();
    Product product = stockCorrection.getProduct();
    TrackingNumber trackingNumber = stockCorrection.getTrackingNumber();
    BigDecimal diff = realQty.subtract(stockLocationLine.getCurrentQty());
    StockMove stockMove = null;
    if (diff.compareTo(BigDecimal.ZERO) == 0) {
        return null;
    } else if (diff.compareTo(BigDecimal.ZERO) > 0) {
        stockMove = this.createStockMoveHeader(company, fromStockLocation, toStockLocation);
    } else {
        stockMove = this.createStockMoveHeader(company, toStockLocation, fromStockLocation);
    }
    stockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_STOCK_CORRECTION);
    stockMove.setOriginId(stockCorrection.getId());
    stockMove.setStockCorrectionReason(stockCorrection.getStockCorrectionReason());
    BigDecimal productCostPrice = (BigDecimal) productCompanyService.get(product, "costPrice", company);
    StockMoveLine stockMoveLine = stockMoveLineService.createStockMoveLine(product, product.getName(), product.getDescription(), diff.abs(), productCostPrice, productCostPrice, product.getUnit(), stockMove, StockMoveLineService.TYPE_NULL, false, BigDecimal.ZERO);
    if (stockMoveLine == null) {
        throw new AxelorException(stockCorrection, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.STOCK_CORRECTION_1));
    }
    if (trackingNumber != null && stockMoveLine.getTrackingNumber() == null) {
        stockMoveLine.setTrackingNumber(trackingNumber);
    }
    stockMoveService.plan(stockMove);
    stockMoveService.copyQtyToRealQty(stockMove);
    stockMoveService.realize(stockMove, false);
    return stockMove;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) StockLocation(com.axelor.apps.stock.db.StockLocation) Product(com.axelor.apps.base.db.Product) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) BigDecimal(java.math.BigDecimal)

Example 7 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.

the class StockMoveLineServiceImpl method storeCustomsCodes.

@Override
public void storeCustomsCodes(List<StockMoveLine> stockMoveLineList) {
    if (stockMoveLineList == null) {
        return;
    }
    for (StockMoveLine stockMoveLine : stockMoveLineList) {
        Product product = stockMoveLine.getProduct();
        CustomsCodeNomenclature customsCodeNomenclature = product != null ? product.getCustomsCodeNomenclature() : null;
        stockMoveLine.setCustomsCodeNomenclature(customsCodeNomenclature);
        stockMoveLine.setCustomsCode(customsCodeNomenclature != null ? customsCodeNomenclature.getCode() : null);
    }
}
Also used : CustomsCodeNomenclature(com.axelor.apps.stock.db.CustomsCodeNomenclature) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product)

Example 8 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.

the class StockMoveLineServiceImpl method splitStockMoveLineByTrackingNumber.

@Override
@Transactional
public void splitStockMoveLineByTrackingNumber(StockMoveLine stockMoveLine, List<LinkedHashMap<String, Object>> trackingNumbers) {
    // boolean draft = true;
    // if (stockMoveLine.getStockMove() != null
    // && stockMoveLine.getStockMove().getStatusSelect() ==
    // StockMoveRepository.STATUS_PLANNED) {
    // draft = false;
    // }
    BigDecimal totalSplitQty = BigDecimal.ZERO;
    for (LinkedHashMap<String, Object> trackingNumberItem : trackingNumbers) {
        BigDecimal counter = new BigDecimal(trackingNumberItem.get("counter").toString());
        if (counter.compareTo(BigDecimal.ZERO) == 0) {
            continue;
        }
        totalSplitQty = totalSplitQty.add(counter);
        TrackingNumber trackingNumber = trackingNumberRepo.all().filter("self.product.id = ?1 and self.trackingNumberSeq = ?2", stockMoveLine.getProduct(), trackingNumberItem.get("trackingNumberSeq").toString()).fetchOne();
        if (trackingNumber == null) {
            trackingNumber = new TrackingNumber();
            trackingNumber.setCounter(counter);
            trackingNumber.setTrackingNumberSeq(trackingNumberItem.get("trackingNumberSeq").toString());
            if (trackingNumberItem.get("warrantyExpirationDate") != null) {
                trackingNumber.setWarrantyExpirationDate(LocalDate.parse(trackingNumberItem.get("warrantyExpirationDate").toString()));
            }
            if (trackingNumberItem.get("perishableExpirationDate") != null) {
                trackingNumber.setPerishableExpirationDate(LocalDate.parse(trackingNumberItem.get("perishableExpirationDate").toString()));
            }
            if (trackingNumberItem.get("origin") != null) {
                trackingNumber.setOrigin(trackingNumberItem.get("origin").toString());
            }
            if (trackingNumberItem.get("note") != null) {
                trackingNumber.setNote(trackingNumberItem.get("note").toString());
            }
            trackingNumber.setProduct(stockMoveLine.getProduct());
        }
        StockMoveLine newStockMoveLine = stockMoveLineRepository.copy(stockMoveLine, true);
        // if (draft) {
        newStockMoveLine.setQty(counter);
        // } else {
        newStockMoveLine.setRealQty(counter);
        // }
        newStockMoveLine.setTrackingNumber(trackingNumber);
        newStockMoveLine.setStockMove(stockMoveLine.getStockMove());
        stockMoveLineRepository.save(newStockMoveLine);
    }
    if (totalSplitQty.compareTo(stockMoveLine.getQty()) < 0) {
        BigDecimal remainingQty = stockMoveLine.getQty().subtract(totalSplitQty);
        stockMoveLine.setQty(remainingQty);
        stockMoveLine.setRealQty(remainingQty);
        stockMoveLine.setTrackingNumber(null);
        stockMoveLine.setStockMove(stockMoveLine.getStockMove());
    } else {
        stockMoveLineRepository.remove(stockMoveLine);
    }
}
Also used : TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 9 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.

the class StockMoveLineServiceImpl method checkExpirationDates.

@Override
public void checkExpirationDates(StockMove stockMove) throws AxelorException {
    List<String> errorList = new ArrayList<>();
    for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
        TrackingNumber trackingNumber = stockMoveLine.getTrackingNumber();
        if (trackingNumber == null) {
            continue;
        }
        Product product = trackingNumber.getProduct();
        if (product == null || !product.getCheckExpirationDateAtStockMoveRealization()) {
            continue;
        }
        if (product.getHasWarranty() && trackingNumber.getWarrantyExpirationDate().isBefore(appBaseService.getTodayDate(stockMove.getCompany())) || product.getIsPerishable() && trackingNumber.getPerishableExpirationDate().isBefore(appBaseService.getTodayDate(stockMove.getCompany()))) {
            errorList.add(product.getName());
        }
    }
    if (!errorList.isEmpty()) {
        String errorStr = errorList.stream().collect(Collectors.joining(", "));
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.STOCK_MOVE_LINE_EXPIRED_PRODUCTS), errorStr);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) ArrayList(java.util.ArrayList) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product)

Example 10 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.

the class StockMoveLineServiceImpl method splitStockMoveLine.

@Override
public StockMoveLine splitStockMoveLine(StockMoveLine stockMoveLine, BigDecimal qty, TrackingNumber trackingNumber) throws AxelorException {
    StockMoveLine newStockMoveLine = this.createStockMoveLine(stockMoveLine.getProduct(), stockMoveLine.getProductName(), stockMoveLine.getDescription(), qty, stockMoveLine.getUnitPriceUntaxed(), stockMoveLine.getUnitPriceTaxed(), stockMoveLine.getCompanyUnitPriceUntaxed(), stockMoveLine.getCompanyPurchasePrice(), stockMoveLine.getUnit(), stockMoveLine.getStockMove(), trackingNumber);
    stockMoveLine.setQty(stockMoveLine.getQty().subtract(qty));
    stockMoveLine.setRealQty(stockMoveLine.getRealQty().subtract(qty));
    return newStockMoveLine;
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine)

Aggregations

StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)121 BigDecimal (java.math.BigDecimal)59 StockMove (com.axelor.apps.stock.db.StockMove)44 AxelorException (com.axelor.exception.AxelorException)41 Product (com.axelor.apps.base.db.Product)33 Transactional (com.google.inject.persist.Transactional)31 ArrayList (java.util.ArrayList)28 List (java.util.List)18 Company (com.axelor.apps.base.db.Company)16 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)16 StockLocation (com.axelor.apps.stock.db.StockLocation)14 StockMoveLineService (com.axelor.apps.stock.service.StockMoveLineService)14 Unit (com.axelor.apps.base.db.Unit)13 Beans (com.axelor.inject.Beans)13 ProdProduct (com.axelor.apps.production.db.ProdProduct)12 StockMoveService (com.axelor.apps.stock.service.StockMoveService)12 I18n (com.axelor.i18n.I18n)12 Inject (com.google.inject.Inject)12 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)10 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)10