Search in sources :

Example 1 with OrderLineId

use of de.metas.order.OrderLineId 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 2 with OrderLineId

use of de.metas.order.OrderLineId 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 3 with OrderLineId

use of de.metas.order.OrderLineId in project metasfresh-webui-api by metasfresh.

the class ProductsToPickRowsDataFactory method getHuIdsReservedForSalesOrderLine.

private Set<HuId> getHuIdsReservedForSalesOrderLine(final AllocablePackageable packageable) {
    final OrderLineId salesOrderLineId = packageable.getSalesOrderLineIdOrNull();
    if (salesOrderLineId == null) {
        return ImmutableSet.of();
    }
    final HUReservation huReservation = huReservationService.getBySalesOrderLineId(salesOrderLineId).orElse(null);
    if (huReservation == null) {
        return ImmutableSet.of();
    }
    return huReservation.getVhuIds();
}
Also used : OrderLineId(de.metas.order.OrderLineId) HUReservation(de.metas.handlingunits.reservation.HUReservation)

Example 4 with OrderLineId

use of de.metas.order.OrderLineId in project metasfresh-webui-api by metasfresh.

the class ProductsToPickRowsDataFactory method getHuIdsAvailableToAllocate.

private Set<HuId> getHuIdsAvailableToAllocate(final AllocablePackageable packageable) {
    final OrderLineId salesOrderLine = packageable.getSalesOrderLineIdOrNull();
    final Set<HuId> huIds = huReservationService.prepareHUQuery().warehouseId(packageable.getWarehouseId()).productId(packageable.getProductId()).asiId(considerAttributes ? packageable.getAsiId() : null).reservedToSalesOrderLineIdOrNotReservedAtAll(salesOrderLine).build().listIds();
    warmUpCacheForHuIds(huIds);
    return huIds;
}
Also used : OrderLineId(de.metas.order.OrderLineId) HuId(de.metas.handlingunits.HuId)

Example 5 with OrderLineId

use of de.metas.order.OrderLineId in project metasfresh-webui-api by metasfresh.

the class PackageableRowsRepository method createPackageableRow.

private PackageableRow createPackageableRow(final ViewId viewId, final Packageable packageable) {
    final Quantity qtyPickedOrDelivered = packageable.getQtyPickedOrDelivered();
    final Optional<OrderLineId> orderLineId = Optional.ofNullable(packageable.getSalesOrderLineIdOrNull());
    return PackageableRow.builder().shipmentScheduleId(packageable.getShipmentScheduleId()).salesOrderLineId(orderLineId).viewId(viewId).order(orderLookup.get().findById(packageable.getSalesOrderId())).product(productLookup.get().findById(packageable.getProductId())).bpartner(bpartnerLookup.get().findById(packageable.getCustomerId())).preparationDate(packageable.getPreparationDate()).qtyOrdered(packageable.getQtyOrdered()).qtyPicked(qtyPickedOrDelivered).build();
}
Also used : OrderLineId(de.metas.order.OrderLineId) Quantity(de.metas.quantity.Quantity)

Aggregations

OrderLineId (de.metas.order.OrderLineId)9 HuId (de.metas.handlingunits.HuId)3 I_M_HU (de.metas.handlingunits.model.I_M_HU)2 ProductId (de.metas.product.ProductId)2 Quantity (de.metas.quantity.Quantity)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 BPartnerId (de.metas.bpartner.BPartnerId)1 IHUQueryBuilder (de.metas.handlingunits.IHUQueryBuilder)1 IHUStatusBL (de.metas.handlingunits.IHUStatusBL)1 IHandlingUnitsBL (de.metas.handlingunits.IHandlingUnitsBL)1 IHandlingUnitsDAO (de.metas.handlingunits.IHandlingUnitsDAO)1 HUException (de.metas.handlingunits.exceptions.HUException)1 I_M_Locator (de.metas.handlingunits.model.I_M_Locator)1 I_M_Warehouse (de.metas.handlingunits.model.I_M_Warehouse)1 X_M_HU (de.metas.handlingunits.model.X_M_HU)1 X_M_HU_PI_Version (de.metas.handlingunits.model.X_M_HU_PI_Version)1 HUReservation (de.metas.handlingunits.reservation.HUReservation)1 HUReservationService (de.metas.handlingunits.reservation.HUReservationService)1