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;
}
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;
}
Aggregations