use of com.axelor.apps.stock.db.StockRules in project axelor-open-suite by axelor.
the class MrpServiceImpl method checkInsufficientCumulativeQty.
@Transactional(rollbackOn = { Exception.class })
protected boolean checkInsufficientCumulativeQty(MrpLine mrpLine, Product product, boolean firstPass) throws AxelorException {
BigDecimal cumulativeQty = mrpLine.getCumulativeQty();
MrpLineType mrpLineType = mrpLine.getMrpLineType();
boolean isProposalElement = this.isProposalElement(mrpLineType);
BigDecimal minQty = mrpLine.getMinQty();
if ((((mrpLine.getMrpLineType().getElementSelect() != MrpLineTypeRepository.ELEMENT_AVAILABLE_STOCK) && (!isProposalElement || mrpLineType.getTypeSelect() == MrpLineTypeRepository.TYPE_OUT)) || (mrpLine.getMrpLineType().getElementSelect() == MrpLineTypeRepository.ELEMENT_AVAILABLE_STOCK && firstPass)) && cumulativeQty.compareTo(mrpLine.getMinQty()) < 0) {
Company company = null;
StockLocation stockLocation = mrpLine.getStockLocation();
log.debug("Cumulative qty ({} < {}) is insufficient for product ({}) at the maturity date ({})", cumulativeQty, minQty, product.getFullName(), mrpLine.getMaturityDate());
BigDecimal reorderQty = minQty.subtract(cumulativeQty);
StockRules stockRules = stockRulesService.getStockRules(product, stockLocation, StockRulesRepository.TYPE_FUTURE, StockRulesRepository.USE_CASE_USED_FOR_MRP);
if (stockRules != null) {
reorderQty = reorderQty.max(stockRules.getReOrderQty());
}
if (stockLocation.getCompany() != null) {
company = stockLocation.getCompany();
}
MrpLineType mrpLineTypeProposal = this.getMrpLineTypeForProposal(stockRules, product, company);
if (mrpLineTypeProposal == null) {
return false;
}
long duplicateCount = mrpLineRepository.all().filter("self.mrp.id = ?1 AND self.isEditedByUser = ?2 AND self.product = ?3 AND self.relatedToSelectName = ?4", mrp.getId(), true, product, mrpLine.getRelatedToSelectName()).count();
if (duplicateCount != 0) {
return false;
}
this.createProposalMrpLine(mrpLine.getMrp(), product, mrpLineTypeProposal, reorderQty, stockLocation, mrpLine.getMaturityDate(), mrpLine.getMrpLineOriginList(), mrpLine.getRelatedToSelectName());
return true;
}
return false;
}
use of com.axelor.apps.stock.db.StockRules in project axelor-open-suite by axelor.
the class StockRulesServiceProductionImpl method generateOrder.
public void generateOrder(Product product, BigDecimal qty, StockLocationLine stockLocationLine, int type) throws AxelorException {
StockLocation stockLocation = stockLocationLine.getStockLocation();
if (stockLocation == null) {
return;
}
StockRules stockRules = this.getStockRules(product, stockLocation, type, StockRulesRepository.USE_CASE_STOCK_CONTROL);
if (stockRules == null) {
return;
}
if (stockRules.getOrderAlertSelect().equals(StockRulesRepository.ORDER_ALERT_PRODUCTION_ORDER)) {
this.generateProductionOrder(product, qty, stockLocationLine, type, stockRules);
} else {
this.generatePurchaseOrder(product, qty, stockLocationLine, type);
}
}
Aggregations