Search in sources :

Example 1 with HUProducerDestination

use of de.metas.handlingunits.allocation.impl.HUProducerDestination 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)

Aggregations

IAllocationRequest (de.metas.handlingunits.allocation.IAllocationRequest)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