use of com.axelor.apps.supplychain.db.MrpLineType in project axelor-open-suite by axelor.
the class MrpServiceImpl method createSaleForecastMrpLines.
protected void createSaleForecastMrpLines() throws AxelorException {
MrpLineType saleForecastMrpLineType = this.getMrpLineType(MrpLineTypeRepository.ELEMENT_SALE_FORECAST);
if (saleForecastMrpLineType == null) {
return;
}
List<MrpForecast> mrpForecastList = new ArrayList<>();
mrp = mrpRepository.find(mrp.getId());
if (mrp.getMrpForecastSet().isEmpty()) {
mrpForecastList.addAll(mrpForecastRepository.all().filter("self.product.id in (?1) AND self.stockLocation in (?2) AND self.forecastDate >= ?3 AND self.statusSelect = ?4", this.productMap.keySet(), this.stockLocationList, today, MrpForecastRepository.STATUS_CONFIRMED).fetch());
} else {
mrpForecastList.addAll(mrp.getMrpForecastSet());
}
for (MrpForecast mrpForecast : mrpForecastList) {
this.createSaleForecastMrpLines(mrpRepository.find(mrp.getId()), mrpForecastRepository.find(mrpForecast.getId()), mrpLineTypeRepository.find(saleForecastMrpLineType.getId()));
JPA.clear();
}
}
use of com.axelor.apps.supplychain.db.MrpLineType in project axelor-open-suite by axelor.
the class MrpServiceImpl method createSaleOrderMrpLines.
protected void createSaleOrderMrpLines() throws AxelorException {
MrpLineType saleOrderMrpLineType = this.getMrpLineType(MrpLineTypeRepository.ELEMENT_SALE_ORDER);
if (saleOrderMrpLineType == null) {
return;
}
String statusSelect = saleOrderMrpLineType.getStatusSelect();
List<Integer> statusList = StringTool.getIntegerList(statusSelect);
List<SaleOrderLine> saleOrderLineList = new ArrayList<>();
mrp = mrpRepository.find(mrp.getId());
if (mrp.getSaleOrderLineSet().isEmpty()) {
saleOrderLineList.addAll(saleOrderLineRepository.all().filter("self.product.id in (?1) AND self.saleOrder.stockLocation in (?2) AND self.deliveryState != ?3 " + "AND self.saleOrder.statusSelect IN (?4)", this.productMap.keySet(), this.stockLocationList, SaleOrderLineRepository.DELIVERY_STATE_DELIVERED, statusList).fetch());
} else {
saleOrderLineList.addAll(mrp.getSaleOrderLineSet());
}
for (SaleOrderLine saleOrderLine : saleOrderLineList) {
this.createSaleOrderMrpLines(mrpRepository.find(mrp.getId()), saleOrderLineRepository.find(saleOrderLine.getId()), mrpLineTypeRepository.find(saleOrderMrpLineType.getId()), statusList);
JPA.clear();
}
}
use of com.axelor.apps.supplychain.db.MrpLineType in project axelor-open-suite by axelor.
the class MrpServiceProductionImpl method createAvailableStockMrpLine.
protected void createAvailableStockMrpLine(Product product, StockLocation stockLocation) throws AxelorException {
MrpLineType availableStockMrpLineType = this.getMrpLineType(MrpLineTypeRepository.ELEMENT_AVAILABLE_STOCK);
if (availableStockMrpLineType == null) {
return;
}
mrpLineRepository.save(this.createAvailableStockMrpLine(mrpRepository.find(mrp.getId()), productRepository.find(product.getId()), stockLocation, availableStockMrpLineType));
}
use of com.axelor.apps.supplychain.db.MrpLineType 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.supplychain.db.MrpLineType in project axelor-open-suite by axelor.
the class MrpServiceImpl method createPurchaseMrpLines.
protected void createPurchaseMrpLines() throws AxelorException {
MrpLineType purchaseOrderMrpLineType = this.getMrpLineType(MrpLineTypeRepository.ELEMENT_PURCHASE_ORDER);
if (purchaseOrderMrpLineType == null) {
return;
}
String statusSelect = purchaseOrderMrpLineType.getStatusSelect();
List<Integer> statusList = StringTool.getIntegerList(statusSelect);
if (statusList.isEmpty()) {
statusList.add(PurchaseOrderRepository.STATUS_VALIDATED);
}
// TODO : Manage the case where order is partially delivered
List<PurchaseOrderLine> purchaseOrderLineList = purchaseOrderLineRepository.all().filter("self.product.id in (?1) AND self.purchaseOrder.stockLocation in (?2) AND self.receiptState != ?3 " + "AND self.purchaseOrder.statusSelect IN (?4)", this.productMap.keySet(), this.stockLocationList, PurchaseOrderRepository.STATE_RECEIVED, statusList).fetch();
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
this.createPurchaseMrpLines(mrpRepository.find(mrp.getId()), purchaseOrderLineRepository.find(purchaseOrderLine.getId()), mrpLineTypeRepository.find(purchaseOrderMrpLineType.getId()));
JPA.clear();
}
}
Aggregations