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;
}
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;
}
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();
}
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;
}
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();
}
Aggregations