Search in sources :

Example 1 with IHUContext

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();
}
Also used : I_M_Product(org.compiere.model.I_M_Product) IHUStorage(de.metas.handlingunits.storage.IHUStorage) IHUProductStorage(de.metas.handlingunits.storage.IHUProductStorage) IHUContext(de.metas.handlingunits.IHUContext)

Example 2 with IHUContext

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;
}
Also used : PickingSlotRow(de.metas.ui.web.picking.pickingslot.PickingSlotRow) I_M_HU(de.metas.handlingunits.model.I_M_HU) AdempiereException(org.adempiere.exceptions.AdempiereException) IHUContext(de.metas.handlingunits.IHUContext) I_M_Locator(de.metas.handlingunits.model.I_M_Locator)

Example 3 with IHUContext

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();
}
Also used : IAttributeStorage(de.metas.handlingunits.attribute.storage.IAttributeStorage) I_M_HU(de.metas.handlingunits.model.I_M_HU) I_M_Attribute(org.compiere.model.I_M_Attribute) IContextAware(org.adempiere.model.IContextAware) IHUContext(de.metas.handlingunits.IHUContext)

Example 4 with IHUContext

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);
}
Also used : I_M_Product(org.compiere.model.I_M_Product) AdempiereException(org.adempiere.exceptions.AdempiereException) IHUStorage(de.metas.handlingunits.storage.IHUStorage) IHUProductStorage(de.metas.handlingunits.storage.IHUProductStorage) IHUContext(de.metas.handlingunits.IHUContext)

Aggregations

IHUContext (de.metas.handlingunits.IHUContext)4 I_M_HU (de.metas.handlingunits.model.I_M_HU)2 IHUProductStorage (de.metas.handlingunits.storage.IHUProductStorage)2 IHUStorage (de.metas.handlingunits.storage.IHUStorage)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2 I_M_Product (org.compiere.model.I_M_Product)2 IAttributeStorage (de.metas.handlingunits.attribute.storage.IAttributeStorage)1 I_M_Locator (de.metas.handlingunits.model.I_M_Locator)1 PickingSlotRow (de.metas.ui.web.picking.pickingslot.PickingSlotRow)1 IContextAware (org.adempiere.model.IContextAware)1 I_M_Attribute (org.compiere.model.I_M_Attribute)1