Search in sources :

Example 6 with HuId

use of de.metas.handlingunits.HuId in project metasfresh-webui-api by metasfresh.

the class WEBUI_M_HU_Transform method removeHUsIfDestroyed.

/**
 * @return true if at least one HU was removed
 */
private boolean removeHUsIfDestroyed(final Collection<HuId> huIds) {
    final ImmutableSet<HuId> destroyedHUIds = huIds.stream().distinct().map(huId -> load(huId, I_M_HU.class)).filter(Services.get(IHandlingUnitsBL.class)::isDestroyed).map(I_M_HU::getM_HU_ID).map(HuId::ofRepoId).collect(ImmutableSet.toImmutableSet());
    if (destroyedHUIds.isEmpty()) {
        return false;
    }
    final HUEditorView view = getView();
    final boolean changes = view.removeHUIds(destroyedHUIds);
    return changes;
}
Also used : IHandlingUnitsBL(de.metas.handlingunits.IHandlingUnitsBL) I_M_HU(de.metas.handlingunits.model.I_M_HU) HuId(de.metas.handlingunits.HuId) HUEditorView(de.metas.ui.web.handlingunits.HUEditorView)

Example 7 with HuId

use of de.metas.handlingunits.HuId in project metasfresh-webui-api by metasfresh.

the class WEBUI_M_HU_Transform method removeSelectedRowsIfHUDestoyed.

/**
 * @return true if view was changed and needs invalidation
 */
private final boolean removeSelectedRowsIfHUDestoyed() {
    final DocumentIdsSelection selectedRowIds = getSelectedRowIds();
    if (selectedRowIds.isEmpty()) {
        return false;
    } else if (selectedRowIds.isAll()) {
        return false;
    }
    final HUEditorView view = getView();
    final ImmutableSet<HuId> selectedHUIds = view.streamByIds(selectedRowIds).map(row -> row.getHuId()).filter(Objects::nonNull).collect(ImmutableSet.toImmutableSet());
    return removeHUsIfDestroyed(selectedHUIds);
}
Also used : DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) HuId(de.metas.handlingunits.HuId) HUEditorView(de.metas.ui.web.handlingunits.HUEditorView)

Example 8 with HuId

use of de.metas.handlingunits.HuId in project metasfresh-webui-api by metasfresh.

the class WebuiHUTransformCommand method action_SplitCU_To_ExistingTU.

/**
 * Split selected CU to an existing TU.
 *
 * @param cuRow
 * @param tuHU
 * @param qtyCU quantity to split
 * @return
 */
private WebuiHUTransformCommandResult action_SplitCU_To_ExistingTU(final HUEditorRow cuRow, final I_M_HU tuHU, final Quantity qtyCU) {
    final IHandlingUnitsBL handlingUnitsBL = Services.get(IHandlingUnitsBL.class);
    final List<I_M_HU> createdCUs = newHUTransformation().cuToExistingTU(cuRow.getM_HU(), qtyCU, tuHU);
    final HuId huIdChanged = cuRow.getHURowId().getTopLevelHUId();
    final HuId topLevelHuIdChanged = HuId.ofRepoId(handlingUnitsBL.getTopLevelParent(tuHU).getM_HU_ID());
    final ImmutableList<HuId> huIdsCreated = createdCUs.stream().map(I_M_HU::getM_HU_ID).map(HuId::ofRepoId).collect(ImmutableList.toImmutableList());
    return WebuiHUTransformCommandResult.builder().huIdChanged(huIdChanged).huIdChanged(topLevelHuIdChanged).huIdsCreated(huIdsCreated).build();
}
Also used : IHandlingUnitsBL(de.metas.handlingunits.IHandlingUnitsBL) I_M_HU(de.metas.handlingunits.model.I_M_HU) HuId(de.metas.handlingunits.HuId)

Example 9 with HuId

use of de.metas.handlingunits.HuId in project metasfresh-webui-api by metasfresh.

the class WEBUIHUCreationWithSerialNumberService method action_CreateCUs_With_SerialNumbers.

public final WebuiHUTransformCommandResult action_CreateCUs_With_SerialNumbers(final HUEditorRow.HUEditorRowHierarchy huEditorRowHierarchy, final List<String> availableSerialNumbers) {
    final HUEditorRow selectedCuRow = huEditorRowHierarchy.getCuRow();
    final int qtyCU = selectedCuRow.getQtyCU().intValueExact();
    if (qtyCU == 1) {
        final String serialNo = availableSerialNumbers.remove(0);
        assignSerialNumberToCU(selectedCuRow.getHuId(), serialNo);
        huIDsChanged.add(selectedCuRow.getHuId());
    } else {
        final int serialNoCount = availableSerialNumbers.size();
        final int cusToCreateCount = qtyCU < serialNoCount ? qtyCU : serialNoCount;
        final Set<HuId> splittedCUIDs = splitIntoCUs(huEditorRowHierarchy, cusToCreateCount);
        assignSerialNumbersToCUs(splittedCUIDs, availableSerialNumbers);
        huIDsAdded.addAll(splittedCUIDs);
    }
    return WebuiHUTransformCommandResult.builder().huIdsChanged(huIDsChanged).huIdsToRemoveFromView(huIDsToRemove).huIdsToAddToView(huIDsAdded).build();
}
Also used : HuId(de.metas.handlingunits.HuId) HUEditorRow(de.metas.ui.web.handlingunits.HUEditorRow)

Example 10 with HuId

use of de.metas.handlingunits.HuId in project metasfresh-webui-api by metasfresh.

the class HUEditorRowFilters method toPredicate.

public static Predicate<HUEditorRow> toPredicate(@NonNull final HUEditorRowFilter filter) {
    Predicate<HUEditorRow> predicate = Predicates.alwaysTrue();
    if (filter == HUEditorRowFilter.ALL) {
        return predicate;
    }
    // Filter by row type
    final Select rowType = filter.getSelect();
    if (rowType == Select.ALL) {
    // nothing
    } else if (rowType == Select.ONLY_TOPLEVEL) {
        predicate = predicate.and(HUEditorRow::isTopLevel);
    } else if (rowType == Select.LU) {
        predicate = predicate.and(HUEditorRow::isLU);
    } else if (rowType == Select.TU) {
        predicate = predicate.and(HUEditorRow::isTU);
    } else if (rowType == Select.CU) {
        predicate = predicate.and(HUEditorRow::isCU);
    } else {
        throw new AdempiereException("Unknown: " + rowType);
    }
    // Filter by string filter
    final String stringFilter = filter.getUserInputFilter();
    if (!Check.isEmpty(stringFilter, true)) {
        predicate = predicate.and(row -> row.matchesStringFilter(stringFilter));
    }
    // Exclude M_HU_IDs
    final ImmutableSet<HuId> excludeHUIds = filter.getExcludeHUIds();
    if (!excludeHUIds.isEmpty()) {
        predicate = predicate.and(row -> !excludeHUIds.contains(row.getHuId()));
    }
    // Include HUStatuses
    final ImmutableSet<String> onlyHUStatuses = filter.getOnlyHUStatuses();
    if (!onlyHUStatuses.isEmpty()) {
        predicate = predicate.and(row -> onlyHUStatuses.contains(row.getHUStatus()));
    }
    // Exclude HUStatuses
    final ImmutableSet<String> excludeHUStatuses = filter.getExcludeHUStatuses();
    if (!excludeHUStatuses.isEmpty()) {
        predicate = predicate.and(row -> !excludeHUStatuses.contains(row.getHUStatus()));
    }
    return predicate;
}
Also used : UtilityClass(lombok.experimental.UtilityClass) ImmutableSet(com.google.common.collect.ImmutableSet) HuId(de.metas.handlingunits.HuId) Select(de.metas.ui.web.handlingunits.HUEditorRowFilter.Select) AdempiereException(org.adempiere.exceptions.AdempiereException) Predicate(java.util.function.Predicate) Check(de.metas.printing.esb.base.util.Check) NonNull(lombok.NonNull) IHUQueryBuilder(de.metas.handlingunits.IHUQueryBuilder) Predicates(com.google.common.base.Predicates) IHandlingUnitsDAO(de.metas.handlingunits.IHandlingUnitsDAO) Services(de.metas.util.Services) AdempiereException(org.adempiere.exceptions.AdempiereException) Select(de.metas.ui.web.handlingunits.HUEditorRowFilter.Select) HuId(de.metas.handlingunits.HuId)

Aggregations

HuId (de.metas.handlingunits.HuId)54 I_M_HU (de.metas.handlingunits.model.I_M_HU)17 AdempiereException (org.adempiere.exceptions.AdempiereException)11 ProductId (de.metas.product.ProductId)10 HUEditorRow (de.metas.ui.web.handlingunits.HUEditorRow)8 ImmutableSet (com.google.common.collect.ImmutableSet)7 IHandlingUnitsBL (de.metas.handlingunits.IHandlingUnitsBL)7 NonNull (lombok.NonNull)7 ImmutableList (com.google.common.collect.ImmutableList)6 IHandlingUnitsDAO (de.metas.handlingunits.IHandlingUnitsDAO)6 DocumentIdsSelection (de.metas.ui.web.window.datatypes.DocumentIdsSelection)6 Services (de.metas.util.Services)6 List (java.util.List)6 Set (java.util.Set)6 IHUQueryBuilder (de.metas.handlingunits.IHUQueryBuilder)5 PickingSlotId (de.metas.picking.api.PickingSlotId)5 Quantity (de.metas.quantity.Quantity)5 HUEditorView (de.metas.ui.web.handlingunits.HUEditorView)5 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)5 OrderLineId (de.metas.order.OrderLineId)4