Search in sources :

Example 1 with PurchaseRow

use of de.metas.ui.web.order.sales.purchasePlanning.view.PurchaseRow in project metasfresh-webui-api by metasfresh.

the class WEBUI_SalesOrder_Apply_Availability_Row method extractLineRow2availabilityRows.

private Multimap<PurchaseRow, PurchaseRow> extractLineRow2availabilityRows() {
    final PurchaseView view = getView();
    final ListMultimap<PurchaseRow, PurchaseRow> lineRow2AvailabilityRows = getSelectedRowIds().stream().map(// map to PurchaseRowIds
    PurchaseRowId::fromDocumentId).filter(PurchaseRowId::isAvailabilityRowId).filter(availabilityRowId -> availabilityRowId.getAvailabilityType().equals(Type.AVAILABLE)).map(availabilityRowId -> // map to pair (availabilityRowId, availabilityRow)
    ImmutablePair.of(availabilityRowId, view.getById(availabilityRowId.toDocumentId()))).filter(availabilityRowId2row -> Util.coalesce(availabilityRowId2row.getRight().getQtyToPurchase(), BigDecimal.ZERO).signum() > 0).map(availabilityRowId2row -> // map to pair (lineRow, availabilityRow)
    ImmutablePair.of(view.getById(availabilityRowId2row.getLeft().toLineRowId().toDocumentId()), availabilityRowId2row.getRight())).filter(lineRow2availabilityRow -> !lineRow2availabilityRow.getLeft().isProcessed()).collect(Multimaps.toMultimap(IPair::getLeft, IPair::getRight, MultimapBuilder.hashKeys().arrayListValues()::build));
    return ImmutableMultimap.copyOf(lineRow2AvailabilityRows);
}
Also used : ViewBasedProcessTemplate(de.metas.ui.web.process.adprocess.ViewBasedProcessTemplate) IPair(org.adempiere.util.lang.IPair) Util(org.compiere.util.Util) Type(de.metas.purchasecandidate.availability.AvailabilityResult.Type) ListMultimap(com.google.common.collect.ListMultimap) PurchaseRowId(de.metas.ui.web.order.sales.purchasePlanning.view.PurchaseRowId) MultimapBuilder(com.google.common.collect.MultimapBuilder) NonNull(lombok.NonNull) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) Set(java.util.Set) Multimap(com.google.common.collect.Multimap) Multimaps(com.google.common.collect.Multimaps) HashSet(java.util.HashSet) ProcessPreconditionsResolution(de.metas.process.ProcessPreconditionsResolution) BigDecimal(java.math.BigDecimal) ImmutablePair(org.adempiere.util.lang.ImmutablePair) Check(org.adempiere.util.Check) PurchaseView(de.metas.ui.web.order.sales.purchasePlanning.view.PurchaseView) Entry(java.util.Map.Entry) ViewChangesCollector(de.metas.ui.web.view.event.ViewChangesCollector) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) PurchaseRow(de.metas.ui.web.order.sales.purchasePlanning.view.PurchaseRow) IProcessPrecondition(de.metas.process.IProcessPrecondition) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) PurchaseRow(de.metas.ui.web.order.sales.purchasePlanning.view.PurchaseRow) PurchaseView(de.metas.ui.web.order.sales.purchasePlanning.view.PurchaseView) PurchaseRowId(de.metas.ui.web.order.sales.purchasePlanning.view.PurchaseRowId)

Example 2 with PurchaseRow

use of de.metas.ui.web.order.sales.purchasePlanning.view.PurchaseRow in project metasfresh-webui-api by metasfresh.

the class WEBUI_SalesOrder_Apply_Availability_Row method doIt.

@Override
protected String doIt() throws Exception {
    final // 
    Multimap<PurchaseRow, PurchaseRow> lineRows2availabilityRows = extractLineRow2availabilityRows();
    Check.errorIf(hasMultipleAvailabilityRowsPerLineRow(lineRows2availabilityRows), "The selected rows contain > 1 availability row for one line row; lineRows2availabilityRows={}", lineRows2availabilityRows);
    final Set<DocumentId> documentIdsToUpdate = new HashSet<>();
    for (final Entry<PurchaseRow, PurchaseRow> lineRow2availabilityRow : lineRows2availabilityRows.entries()) {
        final DocumentId groupRowDocumentId = updateLineAndGroupRow(lineRow2availabilityRow);
        documentIdsToUpdate.add(groupRowDocumentId);
    }
    ViewChangesCollector.getCurrentOrAutoflush().collectRowsChanged(getView(), DocumentIdsSelection.of(documentIdsToUpdate));
    return MSG_OK;
}
Also used : PurchaseRow(de.metas.ui.web.order.sales.purchasePlanning.view.PurchaseRow) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) HashSet(java.util.HashSet)

Example 3 with PurchaseRow

use of de.metas.ui.web.order.sales.purchasePlanning.view.PurchaseRow in project metasfresh-webui-api by metasfresh.

the class WEBUI_SalesOrder_Apply_Availability_Row method updateLineAndGroupRow.

public DocumentId updateLineAndGroupRow(@NonNull final Entry<PurchaseRow, PurchaseRow> lineRow2availabilityRow) {
    final PurchaseRow lineRow = lineRow2availabilityRow.getKey();
    final PurchaseRowId lineRowId = PurchaseRowId.fromDocumentId(lineRow.getId());
    final DocumentId groupRowDocumentId = lineRowId.toGroupRowId().toDocumentId();
    final PurchaseRow groupRow = getView().getById(groupRowDocumentId);
    final PurchaseRow availabilityRow = lineRow2availabilityRow.getValue();
    if (availabilityRow.getDatePromised() != null) {
        groupRow.changeDatePromised(lineRowId, availabilityRow.getDatePromised());
    }
    groupRow.changeQtyToPurchase(lineRowId, availabilityRow.getQtyToPurchase());
    return groupRowDocumentId;
}
Also used : PurchaseRow(de.metas.ui.web.order.sales.purchasePlanning.view.PurchaseRow) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) PurchaseRowId(de.metas.ui.web.order.sales.purchasePlanning.view.PurchaseRowId)

Aggregations

PurchaseRow (de.metas.ui.web.order.sales.purchasePlanning.view.PurchaseRow)3 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)3 PurchaseRowId (de.metas.ui.web.order.sales.purchasePlanning.view.PurchaseRowId)2 HashSet (java.util.HashSet)2 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 ListMultimap (com.google.common.collect.ListMultimap)1 Multimap (com.google.common.collect.Multimap)1 MultimapBuilder (com.google.common.collect.MultimapBuilder)1 Multimaps (com.google.common.collect.Multimaps)1 IProcessPrecondition (de.metas.process.IProcessPrecondition)1 ProcessPreconditionsResolution (de.metas.process.ProcessPreconditionsResolution)1 Type (de.metas.purchasecandidate.availability.AvailabilityResult.Type)1 PurchaseView (de.metas.ui.web.order.sales.purchasePlanning.view.PurchaseView)1 ViewBasedProcessTemplate (de.metas.ui.web.process.adprocess.ViewBasedProcessTemplate)1 ViewChangesCollector (de.metas.ui.web.view.event.ViewChangesCollector)1 DocumentIdsSelection (de.metas.ui.web.window.datatypes.DocumentIdsSelection)1 BigDecimal (java.math.BigDecimal)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 NonNull (lombok.NonNull)1