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);
}
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);
}
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;
}
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);
}
Aggregations