use of com.qcadoo.mes.masterOrders.GenerationOrderResult in project mes by qcadoo.
the class SalesPlanOrdersController method generateOrders.
private GenerateOrdersSalePlanResponse generateOrders(GenerateOrdersSalePlanRequest generateOrdersSalePlanRequest) {
Entity helper = dataDefinitionService.get(MasterOrdersConstants.PLUGIN_IDENTIFIER, MasterOrdersConstants.MODEL_SALES_PLAN_ORDERS_GROUP_HELPER).get(generateOrdersSalePlanRequest.getEntityId());
List<OrderSalePlanPosition> positionsWithQuantities = generateOrdersSalePlanRequest.getPositions();
List<Entity> positions = helper.getHasManyField(SalesPlanOrdersGroupHelperFields.SALES_PLAN_ORDERS_GROUP_ENTRY_HELPERS);
Entity salesPlan = helper.getBelongsToField(SalesPlanOrdersGroupHelperFields.SALES_PLAN);
GenerationOrderResult result = new GenerationOrderResult(translationService, parameterService);
try {
generateOrders(result, salesPlan, positionsWithQuantities, positions);
GenerateOrdersSalePlanResponse response = new GenerateOrdersSalePlanResponse();
response.setStatus(GenerateOrdersSalePlanResponse.SimpleResponseStatus.OK);
response.setMessages(result.extractMessages());
return response;
} catch (Exception exc) {
GenerateOrdersSalePlanResponse response = new GenerateOrdersSalePlanResponse();
response.setStatus(GenerateOrdersSalePlanResponse.SimpleResponseStatus.ERROR);
response.setErrorMessages(Lists.newArrayList(translationService.translate("masterOrders.ordersGenerationFromProducts.error.ordersNotGenerated", LocaleContextHolder.getLocale())));
return response;
}
}
use of com.qcadoo.mes.masterOrders.GenerationOrderResult in project mes by qcadoo.
the class OrdersGenerationFromProductsListeners method generateOrders.
public void generateOrders(final ViewDefinitionState view, final ComponentState state, final String[] args) throws JSONException {
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
CheckBoxComponent generated = (CheckBoxComponent) view.getComponentByReference("generated");
Entity entity = form.getPersistedEntityWithIncludedFormValues();
entity = entity.getDataDefinition().validate(entity);
if (!entity.isValid()) {
form.setEntity(entity);
return;
}
JSONObject context = view.getJsonContext();
Set<Long> ids = Arrays.stream(context.getString("window.mainTab.form.gridLayout.selectedEntities").replaceAll("[\\[\\]]", "").split(",")).map(Long::valueOf).collect(Collectors.toSet());
GenerationOrderResult result = new GenerationOrderResult(translationService, parameterService);
try {
generateOrders(result, ids, entity);
result.showMessage(view);
} catch (Exception exc) {
view.addMessage("orders.ordersGenerationFromProducts.error.ordersNotGenerated", ComponentState.MessageType.FAILURE);
}
generated.setChecked(true);
}
Aggregations