Search in sources :

Example 1 with ReceiptCorrectHUsProcessor

use of de.metas.handlingunits.inout.ReceiptCorrectHUsProcessor in project metasfresh-webui-api by metasfresh.

the class WEBUI_M_HU_ReverseReceipt method doIt.

@Override
@RunOutOfTrx
protected String doIt() throws Exception {
    final List<I_M_ReceiptSchedule> receiptSchedules = getM_ReceiptSchedules();
    final List<Integer> huIdsToReverse = retrieveHUsToReverse();
    boolean hasChanges = false;
    try {
        for (final I_M_ReceiptSchedule receiptSchedule : receiptSchedules) {
            final ReceiptCorrectHUsProcessor processor = ReceiptCorrectHUsProcessor.builder().setM_ReceiptSchedule(receiptSchedule).tolerateNoHUsFound().build();
            if (processor.isNoHUsFound()) {
                continue;
            }
            final List<I_M_InOut> receiptsToReverse = processor.getReceiptsToReverseFromHUIds(huIdsToReverse);
            if (receiptsToReverse.isEmpty()) {
                continue;
            }
            processor.reverseReceipts(receiptsToReverse);
            hasChanges = true;
        }
    } finally {
        if (hasChanges) {
            // Reset the view's affected HUs
            getView().removeHUIdsAndInvalidate(huIdsToReverse);
            // Notify all active views that given receipt schedules were changed
            viewsRepo.notifyRecordsChanged(TableRecordReference.ofSet(receiptSchedules));
        }
    }
    if (!hasChanges) {
        throw new AdempiereException("@NotFound@ @M_InOut_ID@");
    }
    return MSG_OK;
}
Also used : ReceiptCorrectHUsProcessor(de.metas.handlingunits.inout.ReceiptCorrectHUsProcessor) I_M_InOut(org.compiere.model.I_M_InOut) AdempiereException(org.adempiere.exceptions.AdempiereException) I_M_ReceiptSchedule(de.metas.handlingunits.model.I_M_ReceiptSchedule) RunOutOfTrx(de.metas.process.RunOutOfTrx)

Aggregations

ReceiptCorrectHUsProcessor (de.metas.handlingunits.inout.ReceiptCorrectHUsProcessor)1 I_M_ReceiptSchedule (de.metas.handlingunits.model.I_M_ReceiptSchedule)1 RunOutOfTrx (de.metas.process.RunOutOfTrx)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 I_M_InOut (org.compiere.model.I_M_InOut)1