Search in sources :

Example 16 with I_M_HU

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

the class SqlHUEditorViewRepository method createHUEditorRow.

private HUEditorRow createHUEditorRow(@NonNull final I_M_HU hu, final int topLevelHUId) {
    // final Stopwatch stopwatch = Stopwatch.createStarted();
    final IHandlingUnitsBL handlingUnitsBL = Services.get(IHandlingUnitsBL.class);
    final boolean aggregatedTU = handlingUnitsBL.isAggregateHU(hu);
    final String huUnitTypeCode = handlingUnitsBL.getHU_UnitType(hu);
    final HUEditorRowType huRecordType;
    if (aggregatedTU) {
        huRecordType = HUEditorRowType.TU;
    } else {
        huRecordType = HUEditorRowType.ofHU_UnitType(huUnitTypeCode);
    }
    final String huUnitTypeDisplayName = huRecordType.getName();
    final JSONLookupValue huUnitTypeLookupValue = JSONLookupValue.of(huUnitTypeCode, huUnitTypeDisplayName);
    final JSONLookupValue huStatus = createHUStatusLookupValue(hu);
    final boolean processed = rowProcessedPredicate.isProcessed(hu);
    final int huId = hu.getM_HU_ID();
    final HUEditorRowId rowId = HUEditorRowId.ofHU(huId, topLevelHUId);
    final HUEditorRow.Builder huEditorRow = HUEditorRow.builder(windowId).setRowId(rowId).setType(huRecordType).setTopLevel(topLevelHUId <= 0).setProcessed(processed).setBPartnerId(hu.getC_BPartner_ID()).setAttributesProvider(attributesProvider).setCode(hu.getValue()).setHUUnitType(huUnitTypeLookupValue).setHUStatus(huStatus).setPackingInfo(extractPackingInfo(hu, huRecordType));
    // Acquire Best Before Date if required
    if (showBestBeforeDate) {
        huEditorRow.setBestBeforeDate(extractBestBeforeDate(attributesProvider, rowId));
    }
    // Locator
    if (showLocator) {
        huEditorRow.setLocator(createLocatorLookupValue(hu.getM_Locator_ID()));
    }
    // 
    // Product/UOM/Qty if there is only one product stored
    final IHUProductStorage singleProductStorage = getSingleProductStorage(hu);
    if (singleProductStorage != null) {
        huEditorRow.setProduct(createProductLookupValue(singleProductStorage.getM_Product())).setUOM(createUOMLookupValue(singleProductStorage.getC_UOM())).setQtyCU(singleProductStorage.getQty());
    }
    // 
    // Included HUs
    final int topLevelHUIdEffective = topLevelHUId > 0 ? topLevelHUId : huId;
    if (aggregatedTU) {
        final IHUStorageFactory storageFactory = handlingUnitsBL.getStorageFactory();
        storageFactory.getStorage(hu).getProductStorages().stream().map(huStorage -> createHUEditorRow(huId, topLevelHUIdEffective, huStorage, processed)).forEach(huEditorRow::addIncludedRow);
    } else if (X_M_HU_PI_Version.HU_UNITTYPE_LoadLogistiqueUnit.equals(huUnitTypeCode)) {
        final IHandlingUnitsDAO handlingUnitsDAO = Services.get(IHandlingUnitsDAO.class);
        handlingUnitsDAO.retrieveIncludedHUs(hu).stream().map(includedHU -> createHUEditorRow(includedHU, topLevelHUIdEffective)).forEach(huEditorRow::addIncludedRow);
    } else if (X_M_HU_PI_Version.HU_UNITTYPE_TransportUnit.equals(huUnitTypeCode)) {
        final IHandlingUnitsDAO handlingUnitsDAO = Services.get(IHandlingUnitsDAO.class);
        final IHUStorageFactory storageFactory = handlingUnitsBL.getStorageFactory();
        handlingUnitsDAO.retrieveIncludedHUs(hu).stream().map(includedVHU -> storageFactory.getStorage(includedVHU)).flatMap(vhuStorage -> vhuStorage.getProductStorages().stream()).map(vhuProductStorage -> createHUEditorRow(huId, topLevelHUIdEffective, vhuProductStorage, processed)).forEach(huEditorRow::addIncludedRow);
    } else if (X_M_HU_PI_Version.HU_UNITTYPE_VirtualPI.equals(huUnitTypeCode)) {
    // do nothing
    } else {
        throw new HUException("Unknown HU_UnitType=" + huUnitTypeCode + " for " + hu);
    }
    final HUEditorRow huEditorRowBuilt = huEditorRow.build();
    return huEditorRowBuilt;
}
Also used : IHUStorageFactory(de.metas.handlingunits.storage.IHUStorageFactory) SqlViewRowIdsConverter(de.metas.ui.web.view.descriptor.SqlViewRowIdsConverter) Date(java.util.Date) ViewEvaluationCtx(de.metas.ui.web.view.ViewEvaluationCtx) ITrx(org.adempiere.ad.trx.api.ITrx) SqlDocumentFilterConverters(de.metas.ui.web.document.filter.sql.SqlDocumentFilterConverters) ResultSet(java.sql.ResultSet) IHUQueryBuilder(de.metas.handlingunits.IHUQueryBuilder) IADReferenceDAO(org.adempiere.ad.service.IADReferenceDAO) HUPackingInfos(de.metas.ui.web.handlingunits.util.HUPackingInfos) ImmutableSet(com.google.common.collect.ImmutableSet) NonNull(lombok.NonNull) Collection(java.util.Collection) Set(java.util.Set) IQueryBuilder(org.adempiere.ad.dao.IQueryBuilder) SqlViewBinding(de.metas.ui.web.view.descriptor.SqlViewBinding) PreparedStatement(java.sql.PreparedStatement) Collectors(java.util.stream.Collectors) I_M_Locator(de.metas.handlingunits.model.I_M_Locator) DBException(org.adempiere.exceptions.DBException) Services(org.adempiere.util.Services) List(java.util.List) SqlViewRowIdsOrderedSelectionFactory(de.metas.ui.web.view.SqlViewRowIdsOrderedSelectionFactory) Stream(java.util.stream.Stream) Builder(lombok.Builder) I_M_Warehouse(de.metas.handlingunits.model.I_M_Warehouse) LogManager(de.metas.logging.LogManager) IHandlingUnitsBL(de.metas.handlingunits.IHandlingUnitsBL) HUException(de.metas.handlingunits.exceptions.HUException) ViewRowIdsOrderedSelection(de.metas.ui.web.view.ViewRowIdsOrderedSelection) GuavaCollectors(org.adempiere.util.GuavaCollectors) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) InterfaceWrapperHelper.loadOutOfTrx(org.adempiere.model.InterfaceWrapperHelper.loadOutOfTrx) SqlOptions(de.metas.ui.web.window.model.sql.SqlOptions) SqlAndParams(de.metas.ui.web.view.descriptor.SqlAndParams) Page(org.adempiere.util.collections.PagedIterator.Page) HUIdsFilterData(de.metas.ui.web.handlingunits.HUIdsFilterHelper.HUIdsFilterData) PlainContextAware(org.adempiere.model.PlainContextAware) SqlViewSelectData(de.metas.ui.web.view.descriptor.SqlViewSelectData) SQLException(java.sql.SQLException) DB(org.compiere.util.DB) I_M_Product(org.compiere.model.I_M_Product) ImmutableList(com.google.common.collect.ImmutableList) X_M_HU_PI_Version(de.metas.handlingunits.model.X_M_HU_PI_Version) DocumentFilter(de.metas.ui.web.document.filter.DocumentFilter) DocumentQueryOrderBy(de.metas.ui.web.window.model.DocumentQueryOrderBy) I_M_HU(de.metas.handlingunits.model.I_M_HU) LinkedHashSet(java.util.LinkedHashSet) Nullable(javax.annotation.Nullable) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) JSONLookupValue(de.metas.ui.web.window.datatypes.json.JSONLookupValue) Logger(org.slf4j.Logger) SqlViewKeyColumnNamesMap(de.metas.ui.web.view.descriptor.SqlViewKeyColumnNamesMap) I_C_UOM(org.compiere.model.I_C_UOM) HUPackingInfoFormatter(de.metas.ui.web.handlingunits.util.HUPackingInfoFormatter) WindowId(de.metas.ui.web.window.datatypes.WindowId) ViewRowIdsOrderedSelectionFactory(de.metas.ui.web.view.ViewRowIdsOrderedSelectionFactory) IHandlingUnitsDAO(de.metas.handlingunits.IHandlingUnitsDAO) SqlViewSelectionQueryBuilder(de.metas.ui.web.view.descriptor.SqlViewSelectionQueryBuilder) SqlDocumentFilterConverter(de.metas.ui.web.document.filter.sql.SqlDocumentFilterConverter) Check(org.adempiere.util.Check) IHUProductStorage(de.metas.handlingunits.storage.IHUProductStorage) IHUStorage(de.metas.handlingunits.storage.IHUStorage) ViewId(de.metas.ui.web.view.ViewId) IHandlingUnitsBL(de.metas.handlingunits.IHandlingUnitsBL) JSONLookupValue(de.metas.ui.web.window.datatypes.json.JSONLookupValue) IHUStorageFactory(de.metas.handlingunits.storage.IHUStorageFactory) IHUProductStorage(de.metas.handlingunits.storage.IHUProductStorage) IHandlingUnitsDAO(de.metas.handlingunits.IHandlingUnitsDAO) HUException(de.metas.handlingunits.exceptions.HUException)

Example 17 with I_M_HU

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

the class SqlHUEditorViewRepository method retrieveForHUId.

@Override
public HUEditorRow retrieveForHUId(final int huId) {
    if (huId <= 0) {
        return null;
    }
    // TODO: check if the huId is part of our collection
    final I_M_HU hu = loadOutOfTrx(huId, I_M_HU.class);
    // assume given huId is a top level HU
    final int topLevelHUId = -1;
    return createHUEditorRow(hu, topLevelHUId);
}
Also used : I_M_HU(de.metas.handlingunits.model.I_M_HU)

Example 18 with I_M_HU

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

the class HUMoveToDirectWarehouseService method move.

public void move(@NonNull final Iterator<I_M_HU> hus) {
    checkPreconditions();
    // 
    // Move the HUs, one by one
    int countMoved = 0;
    while (hus.hasNext()) {
        final I_M_HU hu = hus.next();
        generateMovement(hu);
        countMoved++;
    }
    // Stop here if nothing moved
    if (countMoved <= 0) {
        if (isFailIfNoHUs()) {
            throw new AdempiereException("@NoSelection@");
        }
        return;
    }
    // Invalidate given view, if any
    if (huView != null) {
        huView.invalidateAll();
    }
}
Also used : I_M_HU(de.metas.handlingunits.model.I_M_HU) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 19 with I_M_HU

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

the class WEBUI_Add_Batch_SerialNo_To_CUs method removeHUsIfDestroyed.

/**
 * @return true if at least one HU was removed
 */
private boolean removeHUsIfDestroyed(final Collection<Integer> huIds) {
    final ImmutableSet<Integer> 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).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) Autowired(org.springframework.beans.factory.annotation.Autowired) HUEditorRowFilter(de.metas.ui.web.handlingunits.HUEditorRowFilter) DocumentCollection(de.metas.ui.web.window.model.DocumentCollection) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Select(de.metas.ui.web.handlingunits.HUEditorRowFilter.Select) ImmutableList(com.google.common.collect.ImmutableList) I_M_HU(de.metas.handlingunits.model.I_M_HU) Splitter(com.google.common.base.Splitter) IProcessPrecondition(de.metas.process.IProcessPrecondition) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) HUEditorRow(de.metas.ui.web.handlingunits.HUEditorRow) ImmutableSet(com.google.common.collect.ImmutableSet) Collection(java.util.Collection) Set(java.util.Set) HUEditorProcessTemplate(de.metas.ui.web.handlingunits.HUEditorProcessTemplate) ProcessPreconditionsResolution(de.metas.process.ProcessPreconditionsResolution) Services(org.adempiere.util.Services) List(java.util.List) Param(de.metas.process.Param) IUOMDAO(org.adempiere.uom.api.IUOMDAO) InterfaceWrapperHelper.load(org.adempiere.model.InterfaceWrapperHelper.load) HUEditorView(de.metas.ui.web.handlingunits.HUEditorView) Comparator(java.util.Comparator) WEBUI_HU_Constants(de.metas.ui.web.handlingunits.WEBUI_HU_Constants) HUEditorView(de.metas.ui.web.handlingunits.HUEditorView)

Example 20 with I_M_HU

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

the class WEBUIHUCreationWithSerialNumberService method createCUsBatch.

private Set<Integer> createCUsBatch(final HUEditorRow.HUEditorRowHierarchy huEditorRowHierarchy, final int maxCUsAllowedPerBatch) {
    final Set<Integer> splitCUIDs = new HashSet<>();
    final IHandlingUnitsDAO handlingUnitsDAO = Services.get(IHandlingUnitsDAO.class);
    final HUEditorRow cuRow = huEditorRowHierarchy.getCuRow();
    final HUEditorRow parentRow = huEditorRowHierarchy.getParentRow();
    final int initialQtyCU = cuRow.getQtyCU().intValueExact();
    I_M_HU huToSplit = cuRow.getM_HU();
    int numberOfCUsToCreate;
    if (parentRow == null) {
        // The CU will not be split when its qty gets to 1. So make sure the selected CU gets in the list of split CUs
        final int selectedCUID = huToSplit.getM_HU_ID();
        splitCUIDs.add(selectedCUID);
        numberOfCUsToCreate = maxCUsAllowedPerBatch < initialQtyCU ? maxCUsAllowedPerBatch : initialQtyCU;
        for (int i = 0; i < numberOfCUsToCreate; i++) {
            final List<I_M_HU> createdCUs = newHUTransformation().cuToNewCU(huToSplit, BigDecimal.ONE);
            splitCUIDs.addAll(createdCUs.stream().map(I_M_HU::getM_HU_ID).collect(ImmutableSet.toImmutableSet()));
        }
    } else {
        Check.assume(parentRow.isTU(), " Parent row must be TU: " + parentRow);
        I_M_HU parentHU = parentRow.getM_HU();
        if (isAggregateHU(parentRow)) {
            final HUEditorRow luRow = huEditorRowHierarchy.getTopLevelRow();
            parentHU = createNonAggregatedTU(parentRow, luRow);
            huToSplit = handlingUnitsDAO.retrieveIncludedHUs(parentHU).get(0);
        }
        final int tuCapacity = calculateTUCapacity(parentHU);
        numberOfCUsToCreate = Util.getMinimumOfThree(tuCapacity, maxCUsAllowedPerBatch, initialQtyCU);
        for (int i = 0; i < numberOfCUsToCreate; i++) {
            final List<I_M_HU> createdCUs = newHUTransformation().cuToExistingTU(huToSplit, BigDecimal.ONE, parentHU);
            splitCUIDs.addAll(createdCUs.stream().map(I_M_HU::getM_HU_ID).collect(ImmutableSet.toImmutableSet()));
        }
    }
    return splitCUIDs;
}
Also used : IHandlingUnitsDAO(de.metas.handlingunits.IHandlingUnitsDAO) I_M_HU(de.metas.handlingunits.model.I_M_HU) HUEditorRow(de.metas.ui.web.handlingunits.HUEditorRow) HashSet(java.util.HashSet)

Aggregations

I_M_HU (de.metas.handlingunits.model.I_M_HU)43 AdempiereException (org.adempiere.exceptions.AdempiereException)12 HUEditorRow (de.metas.ui.web.handlingunits.HUEditorRow)11 PickingSlotRow (de.metas.ui.web.picking.pickingslot.PickingSlotRow)7 List (java.util.List)7 Services (org.adempiere.util.Services)6 IHandlingUnitsBL (de.metas.handlingunits.IHandlingUnitsBL)5 IProcessPrecondition (de.metas.process.IProcessPrecondition)5 ProcessPreconditionsResolution (de.metas.process.ProcessPreconditionsResolution)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 ImmutableList (com.google.common.collect.ImmutableList)4 IAllocationSource (de.metas.handlingunits.allocation.IAllocationSource)4 IProcessDefaultParametersProvider (de.metas.process.IProcessDefaultParametersProvider)4 Param (de.metas.process.Param)4 HUEditorView (de.metas.ui.web.handlingunits.HUEditorView)4 BigDecimal (java.math.BigDecimal)4 Collection (java.util.Collection)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 IHandlingUnitsDAO (de.metas.handlingunits.IHandlingUnitsDAO)3 I_M_HU_PI_Item (de.metas.handlingunits.model.I_M_HU_PI_Item)3