Search in sources :

Example 1 with HUsToNewTUsRequest

use of de.metas.handlingunits.allocation.transfer.HUTransformService.HUsToNewTUsRequest in project metasfresh-webui-api by metasfresh.

the class WEBUI_PP_Order_HUEditor_IssueTUs method doIt.

@Override
protected String doIt() throws Exception {
    final HUEditorRow row = getSingleSelectedRow();
    final I_M_HU sourceLUorTU = row.getM_HU();
    final HUsToNewTUsRequest request = HUsToNewTUsRequest.forSourceHuAndQty(sourceLUorTU, qtyTUs);
    final List<I_M_HU> extractedTUs = HUTransformService.newInstance().husToNewTUs(request);
    if (extractedTUs.isEmpty()) {
        throw new AdempiereException("@NoSelection@");
    }
    final PPOrderLinesView ppOrderView = getPPOrderView().get();
    final int ppOrderId = ppOrderView.getPP_Order_ID();
    Services.get(IHUPPOrderBL.class).createIssueProducer().setTargetOrderBOMLinesByPPOrderId(ppOrderId).createDraftIssues(extractedTUs);
    getView().invalidateAll();
    ppOrderView.invalidateAll();
    return MSG_OK;
}
Also used : IHUPPOrderBL(de.metas.handlingunits.pporder.api.IHUPPOrderBL) PPOrderLinesView(de.metas.ui.web.pporder.PPOrderLinesView) I_M_HU(de.metas.handlingunits.model.I_M_HU) AdempiereException(org.adempiere.exceptions.AdempiereException) HUsToNewTUsRequest(de.metas.handlingunits.allocation.transfer.HUTransformService.HUsToNewTUsRequest) HUEditorRow(de.metas.ui.web.handlingunits.HUEditorRow)

Example 2 with HUsToNewTUsRequest

use of de.metas.handlingunits.allocation.transfer.HUTransformService.HUsToNewTUsRequest in project metasfresh-webui-api by metasfresh.

the class WEBUI_PP_Order_M_Source_HU_IssueTuQty method doIt.

@Override
protected String doIt() throws Exception {
    final PPOrderLineRow row = getSingleSelectedRow();
    final List<I_M_Source_HU> sourceHus = retrieveActiveSourceHus(row);
    if (sourceHus.isEmpty()) {
        throw new AdempiereException("@NoSelection@");
    }
    final Map<Integer, I_M_Source_HU> huId2SourceHu = new HashMap<>();
    final ImmutableList<I_M_HU> husThatAreFlaggedAsSource = sourceHus.stream().peek(sourceHu -> huId2SourceHu.put(sourceHu.getM_HU_ID(), sourceHu)).map(I_M_Source_HU::getM_HU).collect(ImmutableList.toImmutableList());
    final HUsToNewTUsRequest request = HUsToNewTUsRequest.builder().sourceHUs(husThatAreFlaggedAsSource).qtyTU(qtyTU.intValue()).build();
    EmptyHUListener emptyHUListener = EmptyHUListener.doBeforeDestroyed(hu -> {
        if (huId2SourceHu.containsKey(hu.getM_HU_ID())) {
            SourceHUsService.get().snapshotSourceHU(huId2SourceHu.get(hu.getM_HU_ID()));
        }
    }, "Create snapshot of source-HU before it is destroyed");
    final List<I_M_HU> extractedTUs = HUTransformService.builder().emptyHUListener(emptyHUListener).build().husToNewTUs(request);
    final PPOrderLinesView ppOrderView = getView();
    final int ppOrderId = ppOrderView.getPP_Order_ID();
    Services.get(IHUPPOrderBL.class).createIssueProducer().setTargetOrderBOMLinesByPPOrderId(ppOrderId).createDraftIssues(extractedTUs);
    getView().invalidateAll();
    ppOrderView.invalidateAll();
    return MSG_OK;
}
Also used : IHUPPOrderBL(de.metas.handlingunits.pporder.api.IHUPPOrderBL) PPOrderLinesView(de.metas.ui.web.pporder.PPOrderLinesView) I_M_Source_HU(de.metas.handlingunits.model.I_M_Source_HU) HashMap(java.util.HashMap) I_M_HU(de.metas.handlingunits.model.I_M_HU) HUsToNewTUsRequest(de.metas.handlingunits.allocation.transfer.HUTransformService.HUsToNewTUsRequest) AdempiereException(org.adempiere.exceptions.AdempiereException) EmptyHUListener(de.metas.handlingunits.storage.EmptyHUListener) PPOrderLineRow(de.metas.ui.web.pporder.PPOrderLineRow)

Example 3 with HUsToNewTUsRequest

use of de.metas.handlingunits.allocation.transfer.HUTransformService.HUsToNewTUsRequest in project metasfresh-webui-api by metasfresh.

the class WEBUI_M_HU_MoveTUsToDirectWarehouse method doIt.

@Override
protected // @RunOutOfTrx // run in transaction!
String doIt() {
    if (p_QtyTU <= 0) {
        throw new FillMandatoryException("QtyTU");
    }
    final I_M_HU topLevelHU = getRecord(I_M_HU.class);
    final HUsToNewTUsRequest request = HUsToNewTUsRequest.forSourceHuAndQty(topLevelHU, p_QtyTU);
    final List<I_M_HU> tus = HUTransformService.newInstance().husToNewTUs(request);
    if (tus.size() != p_QtyTU) {
        throw new AdempiereException(WEBUI_HU_Constants.MSG_NotEnoughTUsFound, new Object[] { p_QtyTU, tus.size() });
    }
    HUMoveToDirectWarehouseService.newInstance().setDocumentsCollection(documentsCollection).setHUView(getView()).setFailOnFirstError(true).setLoggable(this).move(tus.iterator());
    return MSG_OK;
}
Also used : I_M_HU(de.metas.handlingunits.model.I_M_HU) AdempiereException(org.adempiere.exceptions.AdempiereException) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException) HUsToNewTUsRequest(de.metas.handlingunits.allocation.transfer.HUTransformService.HUsToNewTUsRequest)

Example 4 with HUsToNewTUsRequest

use of de.metas.handlingunits.allocation.transfer.HUTransformService.HUsToNewTUsRequest in project metasfresh-webui-api by metasfresh.

the class WEBUI_M_HU_ReturnTUsToVendor method doIt.

@Override
protected String doIt() throws Exception {
    if (p_QtyTU <= 0) {
        throw new FillMandatoryException("QtyTU");
    }
    topLevelHU = getRecord(I_M_HU.class);
    // 
    // Get the original receipt line
    final List<I_M_InOutLine> receiptLines = huAssignmentDAO.retrieveModelsForHU(topLevelHU, I_M_InOutLine.class).stream().filter(// material receipt
    inoutLine -> !inoutLine.getM_InOut().isSOTrx()).collect(ImmutableList.toImmutableList());
    final I_M_InOutLine receiptLine = ListUtils.singleElement(receiptLines);
    // 
    // Split out the TUs we need to return
    final HUsToNewTUsRequest request = HUsToNewTUsRequest.forSourceHuAndQty(topLevelHU, p_QtyTU);
    tusToReturn = HUTransformService.newInstance().husToNewTUs(request);
    if (tusToReturn.size() != p_QtyTU) {
        throw new AdempiereException(WEBUI_HU_Constants.MSG_NotEnoughTUsFound, new Object[] { p_QtyTU, tusToReturn.size() });
    }
    // 
    // Assign the split TUs to the receipt line
    // FIXME: this is a workaround until https://github.com/metasfresh/metasfresh/issues/2392 is implemented
    tusToReturn.forEach(tu -> huAssignmentBL.createHUAssignmentBuilder().initializeAssignment(getCtx(), ITrx.TRXNAME_ThreadInherited).setM_LU_HU(null).setM_TU_HU(tu).setTopLevelHU(tu).setModel(receiptLine).build());
    // 
    // Actually create the vendor return
    final Timestamp movementDate = Env.getDate(getCtx());
    huInOutBL.createVendorReturnInOutForHUs(tusToReturn, movementDate);
    // 
    return MSG_OK;
}
Also used : FillMandatoryException(org.adempiere.exceptions.FillMandatoryException) IHUInOutBL(de.metas.handlingunits.inout.IHUInOutBL) HUEditorRow(de.metas.ui.web.handlingunits.HUEditorRow) IHUAssignmentDAO(de.metas.handlingunits.IHUAssignmentDAO) HUsToNewTUsRequest(de.metas.handlingunits.allocation.transfer.HUTransformService.HUsToNewTUsRequest) Timestamp(java.sql.Timestamp) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) ITrx(org.adempiere.ad.trx.api.ITrx) Env(org.compiere.util.Env) HUEditorProcessTemplate(de.metas.ui.web.handlingunits.HUEditorProcessTemplate) I_M_InOutLine(de.metas.edi.model.I_M_InOutLine) HUTransformService(de.metas.handlingunits.allocation.transfer.HUTransformService) ProcessPreconditionsResolution(de.metas.process.ProcessPreconditionsResolution) Services(org.adempiere.util.Services) List(java.util.List) Param(de.metas.process.Param) ImmutableList(com.google.common.collect.ImmutableList) AdempiereException(org.adempiere.exceptions.AdempiereException) ListUtils(org.adempiere.util.collections.ListUtils) IHUAssignmentBL(de.metas.handlingunits.IHUAssignmentBL) I_M_HU(de.metas.handlingunits.model.I_M_HU) IProcessPrecondition(de.metas.process.IProcessPrecondition) WEBUI_HU_Constants(de.metas.ui.web.handlingunits.WEBUI_HU_Constants) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) I_M_HU(de.metas.handlingunits.model.I_M_HU) AdempiereException(org.adempiere.exceptions.AdempiereException) I_M_InOutLine(de.metas.edi.model.I_M_InOutLine) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException) HUsToNewTUsRequest(de.metas.handlingunits.allocation.transfer.HUTransformService.HUsToNewTUsRequest) Timestamp(java.sql.Timestamp)

Aggregations

HUsToNewTUsRequest (de.metas.handlingunits.allocation.transfer.HUTransformService.HUsToNewTUsRequest)4 I_M_HU (de.metas.handlingunits.model.I_M_HU)4 AdempiereException (org.adempiere.exceptions.AdempiereException)4 IHUPPOrderBL (de.metas.handlingunits.pporder.api.IHUPPOrderBL)2 HUEditorRow (de.metas.ui.web.handlingunits.HUEditorRow)2 PPOrderLinesView (de.metas.ui.web.pporder.PPOrderLinesView)2 FillMandatoryException (org.adempiere.exceptions.FillMandatoryException)2 ImmutableList (com.google.common.collect.ImmutableList)1 I_M_InOutLine (de.metas.edi.model.I_M_InOutLine)1 IHUAssignmentBL (de.metas.handlingunits.IHUAssignmentBL)1 IHUAssignmentDAO (de.metas.handlingunits.IHUAssignmentDAO)1 HUTransformService (de.metas.handlingunits.allocation.transfer.HUTransformService)1 IHUInOutBL (de.metas.handlingunits.inout.IHUInOutBL)1 I_M_Source_HU (de.metas.handlingunits.model.I_M_Source_HU)1 EmptyHUListener (de.metas.handlingunits.storage.EmptyHUListener)1 IProcessPrecondition (de.metas.process.IProcessPrecondition)1 Param (de.metas.process.Param)1 ProcessPreconditionsResolution (de.metas.process.ProcessPreconditionsResolution)1 HUEditorProcessTemplate (de.metas.ui.web.handlingunits.HUEditorProcessTemplate)1 WEBUI_HU_Constants (de.metas.ui.web.handlingunits.WEBUI_HU_Constants)1