Search in sources :

Example 1 with HuId

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

the class WEBUI_C_OrderLineSO_Make_HUReservation method doIt.

@Override
protected String doIt() {
    final SalesOrderLine salesOrderLine = WEBUI_C_OrderLineSO_Util.retrieveSalesOrderLine(getView(), salesOrderLineRepository).get();
    final ImmutableList<HuId> selectedHuIds = streamSelectedHUIds(Select.ALL).collect(ImmutableList.toImmutableList());
    if (selectedHuIds.isEmpty()) {
        throw new AdempiereException("@NoSelection@");
    }
    final Quantity qtyToReserve = Quantity.of(qtyToReserveBD, salesOrderLine.getOrderedQty().getUOM());
    final ReserveHUsRequest reservationRequest = ReserveHUsRequest.builder().huIds(selectedHuIds).productId(salesOrderLine.getProductId()).qtyToReserve(qtyToReserve).salesOrderLineId(salesOrderLine.getId().getOrderLineId()).build();
    huReservationService.makeReservation(reservationRequest);
    return MSG_OK;
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) SalesOrderLine(de.metas.purchasecandidate.SalesOrderLine) Quantity(de.metas.quantity.Quantity) HuId(de.metas.handlingunits.HuId) ReserveHUsRequest(de.metas.handlingunits.reservation.ReserveHUsRequest)

Example 2 with HuId

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

the class SqlHUEditorViewRepository method retrieveForHUId.

@Override
public HUEditorRow retrieveForHUId(@Nullable final HuId huId) {
    if (huId == null) {
        return null;
    }
    // TODO: check if the huId is part of our collection
    final I_M_HU hu = Services.get(IHandlingUnitsDAO.class).getByIdOutOfTrx(huId);
    // assume given huId is a top level HU
    final HuId topLevelHUId = null;
    return createHUEditorRow(hu, topLevelHUId);
}
Also used : IHandlingUnitsDAO(de.metas.handlingunits.IHandlingUnitsDAO) I_M_HU(de.metas.handlingunits.model.I_M_HU) HuId(de.metas.handlingunits.HuId)

Example 3 with HuId

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

the class SqlHUEditorViewRepository method createHUEditorRow.

private HUEditorRow createHUEditorRow(@NonNull final I_M_HU hu, final HuId 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 Optional<OrderLineId> orderLineIdWithReservation = huReservationService.getOrderLineIdByReservedVhuId(HuId.ofRepoId(hu.getM_HU_ID()));
    final String huUnitTypeDisplayName = huRecordType.getName();
    final JSONLookupValue huUnitTypeLookupValue = JSONLookupValue.of(huUnitTypeCode, huUnitTypeDisplayName);
    final JSONLookupValue huStatusDisplay = createHUStatusDisplayLookupValue(hu);
    final boolean processed = rowProcessedPredicate.isProcessed(hu);
    final HuId huId = HuId.ofRepoId(hu.getM_HU_ID());
    final HUEditorRowId rowId = HUEditorRowId.ofHU(huId, topLevelHUId);
    final HUEditorRow.Builder huEditorRow = HUEditorRow.builder(windowId).setRowId(rowId).setType(huRecordType).setTopLevel(topLevelHUId == null).setProcessed(processed).setBPartnerId(BPartnerId.ofRepoIdOrNull(hu.getC_BPartner_ID())).setAttributesProvider(attributesProvider).setCode(hu.getValue()).setIsOwnPalette(huRecordType == HUEditorRowType.LU ? hu.isHUPlanningReceiptOwnerPM() : null).setHUUnitType(huUnitTypeLookupValue).setHUStatusDisplay(huStatusDisplay).setHUStatus(hu.getHUStatus()).setReservedForOrderLine(orderLineIdWithReservation.orElse(null)).setPackingInfo(extractPackingInfo(hu, huRecordType));
    // Acquire Best Before Date if required
    if (showBestBeforeDate) {
        huEditorRow.setBestBeforeDate(extractBestBeforeDate(attributesProvider, rowId));
    }
    // 
    // Locator
    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.getProductId())).setUOM(createUOMLookupValue(singleProductStorage.getC_UOM())).setQtyCU(singleProductStorage.getQty().toBigDecimal());
    }
    // 
    // Included HUs
    final HuId topLevelHUIdEffective = topLevelHUId != null ? 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) ViewEvaluationCtx(de.metas.ui.web.view.ViewEvaluationCtx) ITrx(org.adempiere.ad.trx.api.ITrx) Env(org.compiere.util.Env) OrderLineId(de.metas.order.OrderLineId) ProductId(de.metas.product.ProductId) SqlDocumentFilterConverters(de.metas.ui.web.document.filter.sql.SqlDocumentFilterConverters) Page(de.metas.util.collections.PagedIterator.Page) InterfaceWrapperHelper(org.adempiere.model.InterfaceWrapperHelper) DocumentFilterList(de.metas.ui.web.document.filter.DocumentFilterList) ResultSet(java.sql.ResultSet) IHUQueryBuilder(de.metas.handlingunits.IHUQueryBuilder) GuavaCollectors(de.metas.util.GuavaCollectors) HUPackingInfos(de.metas.ui.web.handlingunits.util.HUPackingInfos) IADReferenceDAO(org.adempiere.ad.service.IADReferenceDAO) ImmutableSet(com.google.common.collect.ImmutableSet) DocumentQueryOrderByList(de.metas.ui.web.window.model.DocumentQueryOrderByList) NonNull(lombok.NonNull) Collection(java.util.Collection) Set(java.util.Set) SqlViewBinding(de.metas.ui.web.view.descriptor.SqlViewBinding) IQueryBuilder(org.adempiere.ad.dao.IQueryBuilder) PreparedStatement(java.sql.PreparedStatement) Collectors(java.util.stream.Collectors) I_M_Locator(de.metas.handlingunits.model.I_M_Locator) DBException(org.adempiere.exceptions.DBException) SqlViewRowIdsOrderedSelectionFactory(de.metas.ui.web.view.SqlViewRowIdsOrderedSelectionFactory) List(java.util.List) X_M_HU(de.metas.handlingunits.model.X_M_HU) Stream(java.util.stream.Stream) Builder(lombok.Builder) LocalDate(java.time.LocalDate) BPartnerId(de.metas.bpartner.BPartnerId) IMsgBL(de.metas.i18n.IMsgBL) Optional(java.util.Optional) 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) 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) HUIdsFilterData(de.metas.ui.web.handlingunits.HUIdsFilterHelper.HUIdsFilterData) SqlViewSelectData(de.metas.ui.web.view.descriptor.SqlViewSelectData) PlainContextAware(org.adempiere.model.PlainContextAware) IProductBL(de.metas.product.IProductBL) SQLException(java.sql.SQLException) DB(org.compiere.util.DB) ImmutableList(com.google.common.collect.ImmutableList) X_M_HU_PI_Version(de.metas.handlingunits.model.X_M_HU_PI_Version) I_M_HU(de.metas.handlingunits.model.I_M_HU) Nullable(javax.annotation.Nullable) LinkedHashSet(java.util.LinkedHashSet) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) JSONLookupValue(de.metas.ui.web.window.datatypes.json.JSONLookupValue) IHUStatusBL(de.metas.handlingunits.IHUStatusBL) Check(de.metas.util.Check) SqlDocumentFilterConverterContext(de.metas.ui.web.document.filter.sql.SqlDocumentFilterConverterContext) Logger(org.slf4j.Logger) SqlViewKeyColumnNamesMap(de.metas.ui.web.view.descriptor.SqlViewKeyColumnNamesMap) HUPackingInfoFormatter(de.metas.ui.web.handlingunits.util.HUPackingInfoFormatter) I_C_UOM(org.compiere.model.I_C_UOM) 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) Services(de.metas.util.Services) SqlDocumentFilterConverter(de.metas.ui.web.document.filter.sql.SqlDocumentFilterConverter) HuId(de.metas.handlingunits.HuId) HUReservationService(de.metas.handlingunits.reservation.HUReservationService) 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) HuId(de.metas.handlingunits.HuId) IHUProductStorage(de.metas.handlingunits.storage.IHUProductStorage) IHandlingUnitsDAO(de.metas.handlingunits.IHandlingUnitsDAO) HUException(de.metas.handlingunits.exceptions.HUException) OrderLineId(de.metas.order.OrderLineId)

Example 4 with HuId

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

the class SqlHUEditorViewRepository method createHUEditorRow.

private HUEditorRow createHUEditorRow(final HuId parentHUId, final HuId topLevelHUId, @NonNull final IHUProductStorage huStorage, final boolean processed) {
    // final Stopwatch stopwatch = Stopwatch.createStarted();
    final I_M_HU hu = huStorage.getM_HU();
    final HuId huId = HuId.ofRepoId(hu.getM_HU_ID());
    final ProductId productId = huStorage.getProductId();
    final HUEditorRowAttributesProvider attributesProviderEffective = !huId.equals(parentHUId) ? attributesProvider : null;
    final Optional<OrderLineId> reservedForOrderLineId = huReservationService.getOrderLineIdByReservedVhuId(huId);
    final HUEditorRow huEditorRow = HUEditorRow.builder(windowId).setRowId(HUEditorRowId.ofHUStorage(huId, topLevelHUId, productId)).setType(HUEditorRowType.HUStorage).setTopLevel(false).setProcessed(processed).setAttributesProvider(attributesProviderEffective).setHUUnitType(JSONLookupValue.of(X_M_HU_PI_Version.HU_UNITTYPE_VirtualPI, "CU")).setHUStatus(hu.getHUStatus()).setReservedForOrderLine(reservedForOrderLineId.orElse(null)).setHUStatusDisplay(createHUStatusDisplayLookupValue(hu)).setProduct(createProductLookupValue(productId)).setUOM(createUOMLookupValue(huStorage.getC_UOM())).setQtyCU(huStorage.getQty().toBigDecimal()).build();
    // System.out.println("createHUEditorRow: created " + huEditorRow + " (storage) in " + stopwatch);
    return huEditorRow;
}
Also used : I_M_HU(de.metas.handlingunits.model.I_M_HU) OrderLineId(de.metas.order.OrderLineId) HuId(de.metas.handlingunits.HuId) ProductId(de.metas.product.ProductId)

Example 5 with HuId

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

the class WEBUI_M_HU_SecurPharmScan method checkPreconditionsApplicable.

@Override
public ProcessPreconditionsResolution checkPreconditionsApplicable() {
    final DocumentIdsSelection selectedRowIds = getSelectedRowIds();
    if (selectedRowIds.isEmpty()) {
        return ProcessPreconditionsResolution.rejectBecauseNoSelection();
    }
    if (!securPharmService.hasConfig()) {
        return ProcessPreconditionsResolution.rejectWithInternalReason("no SecurPharm config");
    }
    if (!selectedRowIds.isSingleDocumentId()) {
        return ProcessPreconditionsResolution.rejectBecauseNotSingleSelection().toInternal();
    }
    final HUEditorRow row = getSingleSelectedRow();
    final HuId huId = row.getHuId();
    final SecurPharmHUAttributesScanner scanner = securPharmService.newHUScanner();
    if (!scanner.isEligible(huId)) {
        return ProcessPreconditionsResolution.rejectWithInternalReason("HU not eligible");
    }
    return ProcessPreconditionsResolution.accept();
}
Also used : DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) HuId(de.metas.handlingunits.HuId) SecurPharmHUAttributesScanner(de.metas.vertical.pharma.securpharm.service.SecurPharmHUAttributesScanner) HUEditorRow(de.metas.ui.web.handlingunits.HUEditorRow)

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