use of de.metas.handlingunits.IHUContext in project metasfresh-webui-api by metasfresh.
the class PickingSlotsClearingViewBasedProcess method retrieveQtyCU.
protected final BigDecimal retrieveQtyCU(@NonNull final I_M_HU hu) {
final IHUContext huContext = huContextFactory.createMutableHUContext();
final IHUStorage fromHUStorage = huContext.getHUStorageFactory().getStorage(hu);
final I_M_Product product = fromHUStorage.getSingleProductOrNull();
if (product == null) {
return BigDecimal.ZERO;
}
final IHUProductStorage productStorage = fromHUStorage.getProductStorage(product);
return productStorage.getQty();
}
use of de.metas.handlingunits.IHUContext in project metasfresh-webui-api by metasfresh.
the class WEBUI_PickingSlotsClearingView_TakeOutHU method doIt.
@Override
protected String doIt() {
//
// Get the HU
final PickingSlotRow huRow = getSingleSelectedPickingSlotRow();
Check.assume(huRow.isTopLevelHU(), "row {} shall be a top level HU", huRow);
final I_M_HU hu = InterfaceWrapperHelper.load(huRow.getHuId(), I_M_HU.class);
final String huStatus = hu.getHUStatus();
//
// Remove the HU from it's picking slot
huPickingSlotBL.removeFromPickingSlotQueueRecursivelly(hu);
//
// Make sure the HU has the BPartner/Location of the picking slot
final PickingSlotRow pickingSlotRow = getRootRowForSelectedPickingSlotRows();
if (pickingSlotRow.getBPartnerId() > 0) {
hu.setC_BPartner_ID(pickingSlotRow.getBPartnerId());
hu.setC_BPartner_Location_ID(pickingSlotRow.getBPartnerLocationId());
InterfaceWrapperHelper.save(hu);
}
//
// Move the HU to an after picking locator
final I_M_Locator afterPickingLocator = huWarehouseDAO.suggestAfterPickingLocator(hu.getM_Locator());
if (afterPickingLocator == null) {
throw new AdempiereException("No after picking locator found for " + hu.getM_Locator());
}
if (afterPickingLocator.getM_Locator_ID() != hu.getM_Locator_ID()) {
huMovementBL.moveHUsToLocator(ImmutableList.of(hu), afterPickingLocator);
//
// FIXME: workaround to restore HU's HUStatus (i.e. which was changed from Picked to Active by the moveHUsToLocator() method, indirectly).
// See https://github.com/metasfresh/metasfresh-webui-api/issues/678#issuecomment-344876035, that's the stacktrace where the HU status was set to Active.
InterfaceWrapperHelper.refresh(hu, ITrx.TRXNAME_ThreadInherited);
if (!Objects.equal(huStatus, hu.getHUStatus())) {
final IHUContext huContext = huContextFactory.createMutableHUContext();
handlingUnitsBL.setHUStatus(huContext, hu, huStatus);
save(hu);
}
}
//
// Inactive all those picking candidates
pickingCandidateService.inactivateForHUId(hu.getM_HU_ID());
husExtractedEvents.add(HUExtractedFromPickingSlotEvent.builder().huId(hu.getM_HU_ID()).bpartnerId(hu.getC_BPartner_ID()).bpartnerLocationId(hu.getC_BPartner_Location_ID()).build());
return MSG_OK;
}
use of de.metas.handlingunits.IHUContext in project metasfresh-webui-api by metasfresh.
the class WEBUIHUCreationWithSerialNumberService method assignSerialNumberToCU.
private void assignSerialNumberToCU(final int huId, final String serialNo) {
final I_M_HU hu = create(Env.getCtx(), huId, I_M_HU.class, ITrx.TRXNAME_ThreadInherited);
final IContextAware ctxAware = getContextAware(hu);
final IHUContext huContext = handlingUnitsBL.createMutableHUContext(ctxAware);
final IAttributeStorage attributeStorage = getAttributeStorage(huContext, hu);
final I_M_Attribute serialNoAttribute = serialNoDAO.getSerialNoAttribute(ctxAware.getCtx());
Check.errorUnless(attributeStorage.hasAttribute(serialNoAttribute), "There is no SerialNo attribute {} defined for the handling unit {}", serialNoAttribute, hu);
attributeStorage.setValue(serialNoAttribute, serialNo.trim());
attributeStorage.saveChangesIfNeeded();
}
use of de.metas.handlingunits.IHUContext in project metasfresh-webui-api by metasfresh.
the class PickingSlotsClearingViewBasedProcess method prepareUnloadRequest.
protected IAllocationRequestBuilder prepareUnloadRequest(@NonNull final I_M_HU fromHU, @NonNull final BigDecimal qtyCU) {
Check.assume(qtyCU.signum() > 0, "qtyCU > 0");
final IHUContext huContext = huContextFactory.createMutableHUContext();
final IHUStorage fromHUStorage = huContext.getHUStorageFactory().getStorage(fromHU);
final I_M_Product product = fromHUStorage.getSingleProductOrNull();
if (product == null) {
throw new AdempiereException("Cannot determine the product to transfer from " + fromHU);
}
final IHUProductStorage productStorage = fromHUStorage.getProductStorage(product);
return AllocationUtils.createAllocationRequestBuilder().setHUContext(huContext).setProduct(product).setQuantity(qtyCU, productStorage.getC_UOM()).setDateAsToday().setFromReferencedModel(null).setForceQtyAllocation(false);
}
Aggregations