Search in sources :

Example 71 with StockMoveLine

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

the class StockMoveLineStockRepository method copy.

@Override
public StockMoveLine copy(StockMoveLine entity, boolean deep) {
    StockMoveLine copy = super.copy(entity, deep);
    copy.setStockMove(null);
    copy.setPlannedStockMove(null);
    return copy;
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine)

Example 72 with StockMoveLine

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

the class StockMoveLineStockRepository method populate.

@Override
public Map<String, Object> populate(Map<String, Object> json, Map<String, Object> context) {
    Long stockMoveLineId = (Long) json.get("id");
    StockMoveLine stockMoveLine = find(stockMoveLineId);
    StockMove stockMove = stockMoveLine.getStockMove();
    if (stockMove == null || (stockMove.getFromStockLocation() != null && stockMove.getFromStockLocation().getTypeSelect() == StockLocationRepository.TYPE_VIRTUAL)) {
        return super.populate(json, context);
    }
    if (stockMove.getStatusSelect() < StockMoveRepository.STATUS_REALIZED) {
        Beans.get(StockMoveLineService.class).setAvailableStatus(stockMoveLine);
        json.put("availableStatus", stockMoveLine.getProduct() != null && stockMoveLine.getProduct().getStockManaged() ? stockMoveLine.getAvailableStatus() : null);
        json.put("availableStatusSelect", stockMoveLine.getAvailableStatusSelect());
    }
    return super.populate(json, context);
}
Also used : StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine)

Example 73 with StockMoveLine

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

the class StockMoveManagementRepository method populate.

@Override
public Map<String, Object> populate(Map<String, Object> json, Map<String, Object> context) {
    Long stockMoveId = (Long) json.get("id");
    StockMove stockMove = find(stockMoveId);
    if (stockMove.getStatusSelect() > STATUS_PLANNED || stockMove.getStockMoveLineList() == null || (stockMove.getFromStockLocation() != null && stockMove.getFromStockLocation().getTypeSelect() == StockLocationRepository.TYPE_VIRTUAL)) {
        return super.populate(json, context);
    }
    int available = 0, availableForProduct = 0, missing = 0;
    for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
        if (stockMoveLine != null && stockMoveLine.getProduct() != null && stockMoveLine.getProduct().getProductTypeSelect() != null && stockMoveLine.getProduct().getProductTypeSelect().equals(ProductRepository.PRODUCT_TYPE_SERVICE)) {
            continue;
        }
        Beans.get(StockMoveLineService.class).updateAvailableQty(stockMoveLine, stockMove.getFromStockLocation());
        Product product = stockMoveLine.getProduct();
        if (stockMoveLine.getAvailableQty().compareTo(stockMoveLine.getRealQty()) >= 0 || product != null && !product.getStockManaged()) {
            available++;
        } else if (stockMoveLine.getAvailableQtyForProduct().compareTo(stockMoveLine.getRealQty()) >= 0) {
            availableForProduct++;
        } else if (stockMoveLine.getAvailableQty().compareTo(stockMoveLine.getRealQty()) < 0 && stockMoveLine.getAvailableQtyForProduct().compareTo(stockMoveLine.getRealQty()) < 0) {
            missing++;
        }
    }
    if ((available > 0 || availableForProduct > 0) && missing == 0) {
        json.put("availableStatusSelect", StockMoveRepository.STATUS_AVAILABLE);
    } else if ((available > 0 || availableForProduct > 0) && missing > 0) {
        json.put("availableStatusSelect", StockMoveRepository.STATUS_PARTIALLY_AVAILABLE);
    } else if (available == 0 && availableForProduct == 0 && missing > 0) {
        json.put("availableStatusSelect", StockMoveRepository.STATUS_UNAVAILABLE);
    }
    return super.populate(json, context);
}
Also used : StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product)

Example 74 with StockMoveLine

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

the class PartnerProductQualityRatingServiceImpl method calculate.

@Override
@Transactional(rollbackOn = { Exception.class })
public void calculate(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();
            PartnerProductQualityRating partnerProductQualityRating = searchPartnerProductQualityRating(partner, product).orElseGet(() -> createPartnerProductQualityRating(partner, product));
            updatePartnerProductQualityRating(partnerProductQualityRating, stockMoveLine);
        }
    }
    updateSupplier(partner);
}
Also used : PartnerProductQualityRating(com.axelor.apps.stock.db.PartnerProductQualityRating) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Example 75 with StockMoveLine

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

the class StockMoveLineController method updateRealQty.

public List<StockMoveLine> updateRealQty(List<StockMoveLine> moveLines, BigDecimal oldKitQty, BigDecimal newKitQty, boolean isRealQty) {
    BigDecimal qty = BigDecimal.ZERO;
    int scale = appBaseService.getNbDecimalDigitForQty();
    if (moveLines != null) {
        if (newKitQty.compareTo(BigDecimal.ZERO) != 0) {
            for (StockMoveLine line : moveLines) {
                qty = (line.getRealQty().divide(oldKitQty, scale, RoundingMode.HALF_UP)).multiply(newKitQty);
                line.setRealQty(qty.setScale(scale, RoundingMode.HALF_UP));
            }
        } else {
            for (StockMoveLine line : moveLines) {
                line.setRealQty(qty.setScale(scale, RoundingMode.HALF_UP));
            }
        }
    }
    return moveLines;
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal)

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