Search in sources :

Example 1 with IAllocationRequest

use of de.metas.handlingunits.allocation.IAllocationRequest 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 2 with IAllocationRequest

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

IAllocationRequest (de.metas.handlingunits.allocation.IAllocationRequest)2 IHUContextFactory (de.metas.handlingunits.IHUContextFactory)1 IMutableHUContext (de.metas.handlingunits.IMutableHUContext)1 IAllocationSource (de.metas.handlingunits.allocation.IAllocationSource)1 HUProducerDestination (de.metas.handlingunits.allocation.impl.HUProducerDestination)1 HUException (de.metas.handlingunits.exceptions.HUException)1 I_M_HU (de.metas.handlingunits.model.I_M_HU)1 Quantity (de.metas.quantity.Quantity)1 BigDecimal (java.math.BigDecimal)1