use of com.axelor.apps.production.db.repo.ProdProductRepository in project axelor-open-suite by axelor.
the class ManufOrderController method generateMultiLevelManufOrder.
/**
* Called from multi-level-planing-wizard-form, on clicking "Generate MO" button.
*
* @param request
* @param response
*/
@SuppressWarnings("unchecked")
public void generateMultiLevelManufOrder(ActionRequest request, ActionResponse response) {
try {
Long moId = Long.valueOf(request.getContext().get("id").toString());
ManufOrder mo = Beans.get(ManufOrderRepository.class).find(moId);
ProdProductRepository prodProductRepository = Beans.get(ProdProductRepository.class);
List<ProdProduct> prodProductList = ((List<LinkedHashMap<String, Object>>) request.getContext().get("components")).stream().filter(map -> (boolean) map.get("selected")).map(map -> prodProductRepository.find(Long.valueOf(map.get("id").toString()))).collect(Collectors.toList());
if (prodProductList.isEmpty()) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.NO_PRODUCT_SELECTED));
}
List<Product> selectedProductList = new ArrayList<>();
for (ProdProduct prod : prodProductList) {
if (selectedProductList.contains(prod.getProduct())) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.DUPLICATE_PRODUCT_SELECTED));
}
selectedProductList.add(prod.getProduct());
}
List<ManufOrder> moList = Beans.get(ManufOrderService.class).generateAllSubManufOrder(selectedProductList, mo);
response.setCanClose(true);
response.setView(ActionView.define(I18n.get("Manufacturing orders")).model(ManufOrder.class.getName()).add("grid", "generated-manuf-order-grid").add("form", "manuf-order-form").param("popup", "true").param("popup-save", "false").param("show-toolbar", "false").param("show-confirm", "false").domain("self.id in (" + StringTool.getIdListString(moList) + ")").map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations