use of de.metas.handlingunits.allocation.IAllocationSource in project metasfresh-webui-api by metasfresh.
the class WEBUI_PickingSlotsClearingView_TakeOutCUsAndAddToTU method doIt.
@Override
protected String doIt() {
final List<I_M_HU> fromCUs = getSourceCUs();
final IAllocationSource source = HUListAllocationSourceDestination.of(fromCUs).setDestroyEmptyHUs(true);
final IAllocationDestination destination = HUListAllocationSourceDestination.of(getTargetTU());
final HULoader huLoader = HULoader.of(source, destination).setAllowPartialUnloads(false).setAllowPartialLoads(false);
//
// Unload CU/CUs and Load to selected TU
final List<Integer> huIdsDestroyedCollector = new ArrayList<>();
if (fromCUs.size() == 1) {
huLoader.load(prepareUnloadRequest(fromCUs.get(0), getQtyCU()).setForceQtyAllocation(true).addEmptyHUListener(EmptyHUListener.doBeforeDestroyed(hu -> huIdsDestroyedCollector.add(hu.getM_HU_ID()))).create());
} else {
final IHUContextFactory huContextFactory = Services.get(IHUContextFactory.class);
final IMutableHUContext huContext = huContextFactory.createMutableHUContext();
huContext.addEmptyHUListener(EmptyHUListener.doBeforeDestroyed(hu -> huIdsDestroyedCollector.add(hu.getM_HU_ID())));
huLoader.unloadAllFromSource(huContext);
}
// Remove from picking slots all destroyed HUs
pickingCandidateService.inactivateForHUIds(huIdsDestroyedCollector);
return MSG_OK;
}
use of de.metas.handlingunits.allocation.IAllocationSource in project metasfresh-webui-api by metasfresh.
the class WEBUI_M_ReceiptSchedule_ReceiveCUs method createPlanningVHU.
private I_M_HU createPlanningVHU(final I_M_ReceiptSchedule receiptSchedule) {
//
// Create allocation request for the quantity user entered
final IAllocationRequest allocationRequest = createAllocationRequest(receiptSchedule);
if (allocationRequest == null || allocationRequest.isZeroQty()) {
return null;
}
// task 09717
// make sure the attributes are initialized in case of multiple row selection, also
huReceiptScheduleBL.setInitialAttributeValueDefaults(allocationRequest, ImmutableList.of(receiptSchedule));
//
// Allocation Source: our receipt schedule
final IAllocationSource allocationSource = huReceiptScheduleBL.createAllocationSource(receiptSchedule);
//
// Allocation Destination: HU producer which will create 1 VHU
final HUProducerDestination huProducer = HUProducerDestination.of(handlingUnitsDAO.retrieveVirtualPI(getCtx())).setMaxHUsToCreate(// we want one VHU
1);
//
// Transfer Qty
HULoader.of(allocationSource, huProducer).setAllowPartialUnloads(false).setAllowPartialLoads(false).load(allocationRequest);
//
// Get created VHU and return it
final List<I_M_HU> hus = huProducer.getCreatedHUs();
if (hus == null || hus.size() != 1) {
throw new HUException("One and only one VHU was expected but we got: " + hus);
}
final I_M_HU vhu = hus.get(0);
InterfaceWrapperHelper.setTrxName(vhu, ITrx.TRXNAME_None);
return vhu;
}
use of de.metas.handlingunits.allocation.IAllocationSource in project metasfresh-webui-api by metasfresh.
the class WEBUI_PickingSlotsClearingView_TakeOutHUAndAddToNewHU method doIt.
@Override
protected String doIt() throws Exception {
if (qtyCU == null || qtyCU.signum() <= 0) {
throw new FillMandatoryException(PARAM_QtyCU);
}
final I_M_HU fromHU = getSingleSelectedPickingSlotTopLevelHU();
final IAllocationSource source = HUListAllocationSourceDestination.of(fromHU).setDestroyEmptyHUs(true);
final IHUProducerAllocationDestination destination = createHUProducer(fromHU);
HULoader.of(source, destination).setAllowPartialUnloads(false).setAllowPartialLoads(false).load(prepareUnloadRequest(fromHU, qtyCU).setForceQtyAllocation(true).create());
// If the source HU was destroyed, then "remove" it from picking slots
if (handlingUnitsBL.isDestroyedRefreshFirst(fromHU)) {
pickingCandidateService.inactivateForHUId(fromHU.getM_HU_ID());
}
return MSG_OK;
}
use of de.metas.handlingunits.allocation.IAllocationSource in project metasfresh-webui-api by metasfresh.
the class WEBUI_PickingSlotsClearingView_TakeOutMultiHUsAndAddToNewHU method doIt.
@Override
protected String doIt() throws Exception {
final List<I_M_HU> fromHUs = getSelectedPickingSlotTopLevelHUs();
final IAllocationSource source = HUListAllocationSourceDestination.of(fromHUs).setDestroyEmptyHUs(true);
final IHUProducerAllocationDestination destination = createHUProducer();
HULoader.of(source, destination).setAllowPartialUnloads(false).setAllowPartialLoads(false).unloadAllFromSource();
// If the source HU was destroyed, then "remove" it from picking slots
final ImmutableSet<Integer> destroyedHUIds = fromHUs.stream().filter(handlingUnitsBL::isDestroyedRefreshFirst).map(I_M_HU::getM_HU_ID).collect(ImmutableSet.toImmutableSet());
if (!destroyedHUIds.isEmpty()) {
pickingCandidateService.inactivateForHUIds(destroyedHUIds);
}
return MSG_OK;
}
Aggregations