Search in sources :

Example 1 with PartnerProductQualityRating

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

the class PartnerProductQualityRatingServiceImpl method undoCalculation.

@Override
@Transactional(rollbackOn = { Exception.class })
public void undoCalculation(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();
            Optional<PartnerProductQualityRating> optional = searchPartnerProductQualityRating(partner, product);
            if (optional.isPresent()) {
                PartnerProductQualityRating partnerProductQualityRating = optional.get();
                updatePartnerProductQualityRating(partnerProductQualityRating, stockMoveLine, true);
            }
        }
    }
    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 2 with PartnerProductQualityRating

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

the class PartnerProductQualityRatingServiceImpl method updateSupplier.

/**
 * Update supplier's quality rating and arrival product quantity.
 *
 * @param partner
 */
private void updateSupplier(Partner partner) {
    BigDecimal supplierQualityRating = BigDecimal.ZERO;
    BigDecimal supplierArrivalProductQty = BigDecimal.ZERO;
    List<PartnerProductQualityRating> partnerProductQualityRatingList = partner.getPartnerProductQualityRatingList();
    if (partnerProductQualityRatingList != null) {
        for (PartnerProductQualityRating partnerProductQualityRating : partnerProductQualityRatingList) {
            BigDecimal qualityRating = partnerProductQualityRating.getQualityRating();
            BigDecimal arrivalProductQty = partnerProductQualityRating.getArrivalProductQty();
            supplierQualityRating = supplierQualityRating.add(qualityRating.multiply(arrivalProductQty));
            supplierArrivalProductQty = supplierArrivalProductQty.add(arrivalProductQty);
        }
        if (supplierArrivalProductQty.signum() > 0) {
            supplierQualityRating = supplierQualityRating.divide(supplierArrivalProductQty, 2, RoundingMode.HALF_UP);
        } else {
            supplierQualityRating = BigDecimal.ZERO;
        }
    }
    partner.setSupplierQualityRating(supplierQualityRating);
    partner.setSupplierQualityRatingSelect(computeQualityRatingSelect(supplierQualityRating));
    partner.setSupplierArrivalProductQty(supplierArrivalProductQty);
}
Also used : PartnerProductQualityRating(com.axelor.apps.stock.db.PartnerProductQualityRating) BigDecimal(java.math.BigDecimal)

Example 3 with PartnerProductQualityRating

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

the class PartnerProductQualityRatingServiceImpl method createPartnerProductQualityRating.

/**
 * Create partner product quality rating.
 *
 * @param partner
 * @param product
 * @return
 */
@Transactional
protected PartnerProductQualityRating createPartnerProductQualityRating(Partner partner, Product product) {
    PartnerProductQualityRating partnerProductQualityRating = new PartnerProductQualityRating(product);
    partner.addPartnerProductQualityRatingListItem(partnerProductQualityRating);
    partnerProductQualityRatingRepo.persist(partnerProductQualityRating);
    return partnerProductQualityRating;
}
Also used : PartnerProductQualityRating(com.axelor.apps.stock.db.PartnerProductQualityRating) Transactional(com.google.inject.persist.Transactional)

Example 4 with PartnerProductQualityRating

use of com.axelor.apps.stock.db.PartnerProductQualityRating 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)

Aggregations

PartnerProductQualityRating (com.axelor.apps.stock.db.PartnerProductQualityRating)4 Transactional (com.google.inject.persist.Transactional)3 Partner (com.axelor.apps.base.db.Partner)2 Product (com.axelor.apps.base.db.Product)2 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)2 BigDecimal (java.math.BigDecimal)1