Search in sources :

Example 11 with DocumentIdsSelection

use of de.metas.ui.web.window.datatypes.DocumentIdsSelection in project metasfresh-webui-api by metasfresh.

the class WEBUI_M_HU_MoveTUsToDirectWarehouse method checkPreconditionsApplicable.

@Override
protected ProcessPreconditionsResolution checkPreconditionsApplicable() {
    if (!isHUEditorView()) {
        return ProcessPreconditionsResolution.rejectWithInternalReason("not the HU view");
    }
    final DocumentIdsSelection selectedRowIds = getSelectedRowIds();
    if (!selectedRowIds.isSingleDocumentId()) {
        return ProcessPreconditionsResolution.rejectBecauseNotSingleSelection();
    }
    final DocumentId rowId = selectedRowIds.getSingleDocumentId();
    final HUEditorRow huRow = getView().getById(rowId);
    if (huRow.isLU()) {
        if (!huRow.hasIncludedTUs()) {
            return ProcessPreconditionsResolution.rejectWithInternalReason("no TUs");
        }
    } else if (huRow.isTU()) {
    // OK
    } else {
        return ProcessPreconditionsResolution.rejectWithInternalReason("not a LU or TU");
    }
    if (!huRow.isHUStatusActive()) {
        return ProcessPreconditionsResolution.rejectWithInternalReason("HUStatus is not Active");
    }
    return ProcessPreconditionsResolution.accept();
}
Also used : DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) HUEditorRow(de.metas.ui.web.handlingunits.HUEditorRow)

Example 12 with DocumentIdsSelection

use of de.metas.ui.web.window.datatypes.DocumentIdsSelection in project metasfresh-webui-api by metasfresh.

the class WEBUI_M_HU_Receipt_Base method checkPreconditionsApplicable.

@Override
public ProcessPreconditionsResolution checkPreconditionsApplicable() {
    if (!isViewClass(HUEditorView.class)) {
        return ProcessPreconditionsResolution.rejectWithInternalReason("The current view is not an HUEditorView");
    }
    final DocumentIdsSelection selectedRowIds = getSelectedRowIds();
    if (selectedRowIds.isEmpty()) {
        return ProcessPreconditionsResolution.rejectBecauseNoSelection();
    }
    final MutableInt checkedDocumentsCount = new MutableInt(0);
    final ProcessPreconditionsResolution firstRejection = getView(HUEditorView.class).streamByIds(selectedRowIds).filter(document -> document.isPureHU()).peek(// count checked documents
    document -> checkedDocumentsCount.incrementAndGet()).map(// create reject resolution if any
    document -> rejectResolutionOrNull(document)).filter(// filter out those which are not errors
    resolution -> resolution != null).findFirst().orElse(null);
    if (firstRejection != null) {
        // found a record which is not eligible => don't run the process
        return firstRejection;
    }
    if (checkedDocumentsCount.getValue() <= 0) {
        return ProcessPreconditionsResolution.rejectWithInternalReason("no eligible rows");
    }
    return ProcessPreconditionsResolution.accept();
}
Also used : MutableInt(org.adempiere.util.lang.MutableInt) ProcessPreconditionsResolution(de.metas.process.ProcessPreconditionsResolution) HUEditorRow(de.metas.ui.web.handlingunits.HUEditorRow) ViewBasedProcessTemplate(de.metas.ui.web.process.adprocess.ViewBasedProcessTemplate) HUEditorView(de.metas.ui.web.handlingunits.HUEditorView) IProcessPrecondition(de.metas.process.IProcessPrecondition) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) ProcessPreconditionsResolution(de.metas.process.ProcessPreconditionsResolution) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) MutableInt(org.adempiere.util.lang.MutableInt) HUEditorView(de.metas.ui.web.handlingunits.HUEditorView)

Example 13 with DocumentIdsSelection

use of de.metas.ui.web.window.datatypes.DocumentIdsSelection in project metasfresh-webui-api by metasfresh.

the class WEBUI_M_HU_ReturnTUsToVendor method checkPreconditionsApplicable.

@Override
protected ProcessPreconditionsResolution checkPreconditionsApplicable() {
    if (!isHUEditorView()) {
        return ProcessPreconditionsResolution.rejectWithInternalReason("not the HU view");
    }
    final DocumentIdsSelection selectedRowIds = getSelectedRowIds();
    if (!selectedRowIds.isSingleDocumentId()) {
        return ProcessPreconditionsResolution.rejectBecauseNotSingleSelection();
    }
    final DocumentId rowId = selectedRowIds.getSingleDocumentId();
    final HUEditorRow huRow = getView().getById(rowId);
    if (huRow.isLU()) {
        if (!huRow.hasIncludedTUs()) {
            return ProcessPreconditionsResolution.rejectWithInternalReason("no TUs");
        }
    } else if (huRow.isTU()) {
    // OK
    } else {
        return ProcessPreconditionsResolution.rejectWithInternalReason("not a LU or TU");
    }
    return ProcessPreconditionsResolution.accept();
}
Also used : DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) HUEditorRow(de.metas.ui.web.handlingunits.HUEditorRow)

Example 14 with DocumentIdsSelection

use of de.metas.ui.web.window.datatypes.DocumentIdsSelection in project metasfresh-webui-api by metasfresh.

the class C_Invoice_Candidate_ApproveForInvoicing method retrieveInvoiceCandidatesToApproveQuery.

private final IQuery<I_C_Invoice_Candidate> retrieveInvoiceCandidatesToApproveQuery() {
    final IQueryBuilder<I_C_Invoice_Candidate> queryBuilder = Services.get(IQueryBL.class).createQueryBuilder(I_C_Invoice_Candidate.class).filter(getProcessInfo().getQueryFilter()).addOnlyActiveRecordsFilter().addNotEqualsFilter(I_C_Invoice_Candidate.COLUMN_Processed, // not processed
    true).addNotEqualsFilter(I_C_Invoice_Candidate.COLUMN_ApprovalForInvoicing, // not already approved
    true);
    // Only selected rows
    final DocumentIdsSelection selectedRowIds = getSelectedRowIds();
    if (!selectedRowIds.isAll()) {
        final Set<Integer> invoiceCandidateIds = selectedRowIds.toIntSet();
        if (invoiceCandidateIds.isEmpty()) {
            // shall not happen
            throw new AdempiereException("@NoSelection@");
        }
        queryBuilder.addInArrayFilter(I_C_Invoice_Candidate.COLUMN_C_Invoice_Candidate_ID, invoiceCandidateIds);
    }
    return queryBuilder.create();
}
Also used : IQueryBL(org.adempiere.ad.dao.IQueryBL) AdempiereException(org.adempiere.exceptions.AdempiereException) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) I_C_Invoice_Candidate(de.metas.invoicecandidate.model.I_C_Invoice_Candidate)

Example 15 with DocumentIdsSelection

use of de.metas.ui.web.window.datatypes.DocumentIdsSelection in project metasfresh-webui-api by metasfresh.

the class HUReportProcessInstancesRepository method checkApplies.

private boolean checkApplies(WebuiHUProcessDescriptor descriptor, ViewAsPreconditionsContext viewContext) {
    final DocumentIdsSelection rowIds = viewContext.getSelectedRowIds();
    if (rowIds.isEmpty()) {
        return false;
    }
    final HUEditorView huView = viewContext.getView(HUEditorView.class);
    final boolean foundNotMatchingRows = huView.streamByIds(rowIds).anyMatch(row -> !checkApplies(row, descriptor));
    return !foundNotMatchingRows;
}
Also used : DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) HUEditorView(de.metas.ui.web.handlingunits.HUEditorView)

Aggregations

DocumentIdsSelection (de.metas.ui.web.window.datatypes.DocumentIdsSelection)25 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)8 HUEditorRow (de.metas.ui.web.handlingunits.HUEditorRow)6 IProcessPrecondition (de.metas.process.IProcessPrecondition)5 ProcessPreconditionsResolution (de.metas.process.ProcessPreconditionsResolution)5 List (java.util.List)5 TableRecordReference (org.adempiere.util.lang.impl.TableRecordReference)5 ImmutableList (com.google.common.collect.ImmutableList)4 HUEditorView (de.metas.ui.web.handlingunits.HUEditorView)4 IView (de.metas.ui.web.view.IView)4 AdempiereException (org.adempiere.exceptions.AdempiereException)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 ViewBasedProcessTemplate (de.metas.ui.web.process.adprocess.ViewBasedProcessTemplate)3 Collection (java.util.Collection)3 Set (java.util.Set)3 NonNull (lombok.NonNull)3 Services (org.adempiere.util.Services)3 IHandlingUnitsBL (de.metas.handlingunits.IHandlingUnitsBL)2 I_M_HU (de.metas.handlingunits.model.I_M_HU)2 Param (de.metas.process.Param)2