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