Search in sources :

Example 1 with IMutableHUContext

use of de.metas.handlingunits.IMutableHUContext 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 IMutableHUContext

use of de.metas.handlingunits.IMutableHUContext in project metasfresh-webui-api by metasfresh.

the class WEBUI_M_ReceiptSchedule_ReceiveCUs method createAllocationRequest.

private final IAllocationRequest createAllocationRequest(final I_M_ReceiptSchedule rs) {
    // Get Qty
    final BigDecimal qty = getEffectiveQtyToReceive(rs);
    if (qty.signum() <= 0) {
        // nothing to do
        return null;
    }
    final IMutableHUContext huContextInitial = Services.get(IHUContextFactory.class).createMutableHUContextForProcessing(getCtx());
    final IAllocationRequest allocationRequest = AllocationUtils.createAllocationRequestBuilder().setHUContext(huContextInitial).setDateAsToday().setProduct(rs.getM_Product()).setQuantity(new Quantity(qty, rs.getC_UOM())).setFromReferencedModel(rs).setForceQtyAllocation(true).create();
    return allocationRequest;
}
Also used : IMutableHUContext(de.metas.handlingunits.IMutableHUContext) IAllocationRequest(de.metas.handlingunits.allocation.IAllocationRequest) Quantity(de.metas.quantity.Quantity) IHUContextFactory(de.metas.handlingunits.IHUContextFactory) BigDecimal(java.math.BigDecimal)

Aggregations

IHUContextFactory (de.metas.handlingunits.IHUContextFactory)2 IMutableHUContext (de.metas.handlingunits.IMutableHUContext)2 BigDecimal (java.math.BigDecimal)2 ImmutableList (com.google.common.collect.ImmutableList)1 IAllocationDestination (de.metas.handlingunits.allocation.IAllocationDestination)1 IAllocationRequest (de.metas.handlingunits.allocation.IAllocationRequest)1 IAllocationSource (de.metas.handlingunits.allocation.IAllocationSource)1 HUListAllocationSourceDestination (de.metas.handlingunits.allocation.impl.HUListAllocationSourceDestination)1 HULoader (de.metas.handlingunits.allocation.impl.HULoader)1 I_M_HU (de.metas.handlingunits.model.I_M_HU)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 Quantity (de.metas.quantity.Quantity)1 HUEditorRow (de.metas.ui.web.handlingunits.HUEditorRow)1 PickingSlotRow (de.metas.ui.web.picking.pickingslot.PickingSlotRow)1