use of de.metas.edi.model.I_M_InOutLine 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;
}
Aggregations