Search in sources :

Example 1 with IAllocationSource

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;
}
Also used : IAllocationSource(de.metas.handlingunits.allocation.IAllocationSource) HULoader(de.metas.handlingunits.allocation.impl.HULoader) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException) EmptyHUListener(de.metas.handlingunits.storage.EmptyHUListener) HULoader(de.metas.handlingunits.allocation.impl.HULoader) Autowired(org.springframework.beans.factory.annotation.Autowired) PickingCandidateService(de.metas.handlingunits.picking.PickingCandidateService) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) ImmutableList(com.google.common.collect.ImmutableList) I_M_HU(de.metas.handlingunits.model.I_M_HU) IProcessDefaultParameter(de.metas.process.IProcessDefaultParameter) IProcessPrecondition(de.metas.process.IProcessPrecondition) HUEditorRow(de.metas.ui.web.handlingunits.HUEditorRow) IAllocationSource(de.metas.handlingunits.allocation.IAllocationSource) PickingSlotRow(de.metas.ui.web.picking.pickingslot.PickingSlotRow) IMutableHUContext(de.metas.handlingunits.IMutableHUContext) IHUContextFactory(de.metas.handlingunits.IHUContextFactory) ProcessPreconditionsResolution(de.metas.process.ProcessPreconditionsResolution) Services(org.adempiere.util.Services) List(java.util.List) Param(de.metas.process.Param) Check(org.adempiere.util.Check) IProcessDefaultParametersProvider(de.metas.process.IProcessDefaultParametersProvider) HUListAllocationSourceDestination(de.metas.handlingunits.allocation.impl.HUListAllocationSourceDestination) InterfaceWrapperHelper.load(org.adempiere.model.InterfaceWrapperHelper.load) IAllocationDestination(de.metas.handlingunits.allocation.IAllocationDestination) IMutableHUContext(de.metas.handlingunits.IMutableHUContext) I_M_HU(de.metas.handlingunits.model.I_M_HU) ArrayList(java.util.ArrayList) IAllocationDestination(de.metas.handlingunits.allocation.IAllocationDestination) IHUContextFactory(de.metas.handlingunits.IHUContextFactory)

Example 2 with IAllocationSource

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;
}
Also used : IAllocationSource(de.metas.handlingunits.allocation.IAllocationSource) HUException(de.metas.handlingunits.exceptions.HUException) I_M_HU(de.metas.handlingunits.model.I_M_HU) IAllocationRequest(de.metas.handlingunits.allocation.IAllocationRequest) HUProducerDestination(de.metas.handlingunits.allocation.impl.HUProducerDestination)

Example 3 with IAllocationSource

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;
}
Also used : IAllocationSource(de.metas.handlingunits.allocation.IAllocationSource) I_M_HU(de.metas.handlingunits.model.I_M_HU) IHUProducerAllocationDestination(de.metas.handlingunits.allocation.IHUProducerAllocationDestination) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException)

Example 4 with IAllocationSource

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;
}
Also used : IAllocationSource(de.metas.handlingunits.allocation.IAllocationSource) I_M_HU(de.metas.handlingunits.model.I_M_HU) IHUProducerAllocationDestination(de.metas.handlingunits.allocation.IHUProducerAllocationDestination)

Aggregations

IAllocationSource (de.metas.handlingunits.allocation.IAllocationSource)4 I_M_HU (de.metas.handlingunits.model.I_M_HU)4 IHUProducerAllocationDestination (de.metas.handlingunits.allocation.IHUProducerAllocationDestination)2 FillMandatoryException (org.adempiere.exceptions.FillMandatoryException)2 ImmutableList (com.google.common.collect.ImmutableList)1 IHUContextFactory (de.metas.handlingunits.IHUContextFactory)1 IMutableHUContext (de.metas.handlingunits.IMutableHUContext)1 IAllocationDestination (de.metas.handlingunits.allocation.IAllocationDestination)1 IAllocationRequest (de.metas.handlingunits.allocation.IAllocationRequest)1 HUListAllocationSourceDestination (de.metas.handlingunits.allocation.impl.HUListAllocationSourceDestination)1 HULoader (de.metas.handlingunits.allocation.impl.HULoader)1 HUProducerDestination (de.metas.handlingunits.allocation.impl.HUProducerDestination)1 HUException (de.metas.handlingunits.exceptions.HUException)1 PickingCandidateService (de.metas.handlingunits.picking.PickingCandidateService)1 EmptyHUListener (de.metas.handlingunits.storage.EmptyHUListener)1 IProcessDefaultParameter (de.metas.process.IProcessDefaultParameter)1 IProcessDefaultParametersProvider (de.metas.process.IProcessDefaultParametersProvider)1 IProcessPrecondition (de.metas.process.IProcessPrecondition)1 Param (de.metas.process.Param)1 ProcessPreconditionsResolution (de.metas.process.ProcessPreconditionsResolution)1