use of com.axelor.apps.supplychain.db.MrpLine in project axelor-open-suite by axelor.
the class MrpLineController method toggleOne.
@Transactional(rollbackOn = { Exception.class })
public void toggleOne(ActionRequest request, ActionResponse response) {
try {
MrpLine mrpLine = request.getContext().asType(MrpLine.class);
mrpLine = Beans.get(MrpLineRepository.class).find(mrpLine.getId());
Beans.get(MrpLineService.class).updateProposalToProcess(mrpLine, !mrpLine.getProposalToProcess());
response.setAttr("mrpLinePanel", "refresh", true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.supplychain.db.MrpLine in project axelor-open-suite by axelor.
the class ProjectedStockController method showChartProjectedStock.
public void showChartProjectedStock(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
List<Map<String, Object>> dataList = new ArrayList<>();
@SuppressWarnings("unchecked") Collection<Map<String, Object>> contextMrpLineList = (Collection<Map<String, Object>>) context.get("_mrpLineListToProject");
List<MrpLine> mrpLineList = contextMrpLineList.stream().map(map -> Mapper.toBean(MrpLine.class, map)).collect(Collectors.toList());
if (!mrpLineList.isEmpty()) {
List<MrpLine> mrpLineLastList = new ArrayList<>();
MrpLine lastMrpLine = mrpLineList.get(0);
for (int i = 1; i < mrpLineList.size(); ++i) {
MrpLine mrpLine = mrpLineList.get(i);
if (mrpLine.getMaturityDate().isAfter(lastMrpLine.getMaturityDate())) {
mrpLineLastList.add(lastMrpLine);
}
lastMrpLine = mrpLine;
}
mrpLineLastList.add(lastMrpLine);
lastMrpLine = mrpLineList.get(0);
LocalDate mrpDate = lastMrpLine.getMaturityDate();
for (MrpLine mrpLine : mrpLineLastList) {
mrpDate = addInterElementForProjectedStockChart(dataList, lastMrpLine, mrpDate, mrpLine);
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("name", mrpLine.getMaturityDate());
dataMap.put("cumulativeQty", mrpLine.getCumulativeQty());
dataList.add(dataMap);
lastMrpLine = mrpLine;
}
}
response.setData(dataList);
}
use of com.axelor.apps.supplychain.db.MrpLine in project axelor-open-suite by axelor.
the class MrpServiceProductionImpl method createManufOrderMrpLines.
@Transactional(rollbackOn = { Exception.class })
protected void createManufOrderMrpLines(Mrp mrp, ManufOrder manufOrder, MrpLineType manufOrderMrpLineType, MrpLineType manufOrderNeedMrpLineType) throws AxelorException {
StockLocation stockLocation = manufOrder.getProdProcess().getStockLocation();
LocalDate maturityDate = null;
if (manufOrder.getPlannedEndDateT() != null) {
maturityDate = manufOrder.getPlannedEndDateT().toLocalDate();
} else {
maturityDate = manufOrder.getPlannedStartDateT().toLocalDate();
}
maturityDate = this.computeMaturityDate(maturityDate, manufOrderMrpLineType);
for (ProdProduct prodProduct : manufOrder.getToProduceProdProductList()) {
Product product = prodProduct.getProduct();
if ((this.isBeforeEndDate(maturityDate) || manufOrderMrpLineType.getIgnoreEndDate()) && this.isMrpProduct(product)) {
MrpLine mrpLine = this.createMrpLine(mrp, product, manufOrderMrpLineType, prodProduct.getQty(), maturityDate, BigDecimal.ZERO, stockLocation, manufOrder);
if (mrpLine != null) {
mrpLineRepository.save(mrpLine);
}
}
}
if (manufOrderNeedMrpLineType == null) {
return;
}
if (manufOrder.getIsConsProOnOperation()) {
for (OperationOrder operationOrder : manufOrder.getOperationOrderList()) {
for (ProdProduct prodProduct : operationOrder.getToConsumeProdProductList()) {
Product product = prodProduct.getProduct();
if (this.isMrpProduct(product)) {
maturityDate = null;
if (operationOrder.getPlannedEndDateT() != null) {
maturityDate = operationOrder.getPlannedEndDateT().toLocalDate();
} else {
maturityDate = operationOrder.getPlannedStartDateT().toLocalDate();
}
maturityDate = this.computeMaturityDate(maturityDate, manufOrderNeedMrpLineType);
MrpLine mrpLine = this.createMrpLine(mrp, prodProduct.getProduct(), manufOrderNeedMrpLineType, computeQtyLeftToConsume(operationOrder, prodProduct), maturityDate, BigDecimal.ZERO, stockLocation, operationOrder);
if (mrpLine != null) {
mrpLineRepository.save(mrpLine);
}
}
}
}
} else {
for (ProdProduct prodProduct : manufOrder.getToConsumeProdProductList()) {
Product product = prodProduct.getProduct();
if (this.isMrpProduct(product)) {
// add it with the level of manuf order product + 1.
if (!this.productMap.containsKey(product.getId())) {
this.assignProductAndLevel(product, manufOrder.getProduct());
this.createAvailableStockMrpLine(product, manufOrder.getProdProcess().getStockLocation());
}
MrpLine mrpLine = this.createMrpLine(mrp, product, manufOrderNeedMrpLineType, computeQtyLeftToConsume(manufOrder, prodProduct), maturityDate, BigDecimal.ZERO, stockLocation, manufOrder);
if (mrpLine != null) {
mrpLineRepository.save(mrpLine);
}
}
}
}
}
use of com.axelor.apps.supplychain.db.MrpLine in project axelor-open-suite by axelor.
the class MrpServiceProductionImpl method createMPSLines.
protected void createMPSLines() throws AxelorException {
MrpLineType mpsNeedMrpLineType = this.getMrpLineType(MrpLineTypeRepository.ELEMENT_MASTER_PRODUCTION_SCHEDULING);
if (mpsNeedMrpLineType == null || mrp.getMrpTypeSelect() != MrpRepository.MRP_TYPE_MRP) {
return;
}
List<MrpLine> mpsMrpLineList = mrpLineRepository.all().filter("self.product.id in (?1) AND self.stockLocation in (?2) AND self.mrp.mrpTypeSelect = ?3 " + "AND self.mrp.statusSelect = ?4 AND self.mrpLineType.elementSelect = ?5 AND self.maturityDate >= ?6 AND (?7 is true OR self.maturityDate <= ?8)", this.productMap.keySet(), this.stockLocationList, MrpRepository.MRP_TYPE_MPS, MrpRepository.STATUS_CALCULATION_ENDED, MrpLineTypeRepository.ELEMENT_MASTER_PRODUCTION_SCHEDULING, today.atStartOfDay(), mrp.getEndDate() == null, mrp.getEndDate()).fetch();
for (MrpLine mpsMrpLine : mpsMrpLineList) {
this.createMpsMrpLines(mrpRepository.find(mrp.getId()), mrpLineRepository.find(mpsMrpLine.getId()), mrpLineTypeRepository.find(mpsNeedMrpLineType.getId()));
JPA.clear();
}
}
Aggregations