Search in sources :

Example 6 with PurchaseCandidate

use of de.metas.purchasecandidate.PurchaseCandidate in project metasfresh-webui-api by metasfresh.

the class PurchaseRowsLoader method handleResultForAsyncAvailabilityCheck.

private void handleResultForAsyncAvailabilityCheck(@Nullable final Multimap<PurchaseCandidate, AvailabilityResult> availabilityCheckResult) {
    if (availabilityCheckResult == null) {
        return;
    }
    final // 
    Set<Entry<PurchaseCandidate, Collection<AvailabilityResult>>> entrySet = availabilityCheckResult.asMap().entrySet();
    final List<DocumentId> changedRowIds = new ArrayList<>();
    for (final Entry<PurchaseCandidate, Collection<AvailabilityResult>> entry : entrySet) {
        final PurchaseRow purchaseRowToAugment = purchaseCandidate2purchaseRow.get(entry.getKey());
        final ImmutableList.Builder<PurchaseRow> availabilityResultRows = ImmutableList.builder();
        for (final AvailabilityResult availabilityResult : entry.getValue()) {
            final PurchaseRow availabilityResultRow = purchaseRowFactory.rowFromAvailabilityResultBuilder().parentRow(purchaseRowToAugment).availabilityResult(availabilityResult).build();
            availabilityResultRows.add(availabilityResultRow);
        }
        purchaseRowToAugment.setAvailabilityInfoRows(availabilityResultRows.build());
        changedRowIds.add(purchaseRowToAugment.getId());
    }
    notifyViewOfChanges(changedRowIds);
}
Also used : AvailabilityResult(de.metas.purchasecandidate.availability.AvailabilityResult) Entry(java.util.Map.Entry) ImmutableList(com.google.common.collect.ImmutableList) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) ArrayList(java.util.ArrayList) Collection(java.util.Collection) PurchaseCandidate(de.metas.purchasecandidate.PurchaseCandidate)

Example 7 with PurchaseCandidate

use of de.metas.purchasecandidate.PurchaseCandidate in project metasfresh-webui-api by metasfresh.

the class PurchaseRowsLoader method load.

public List<PurchaseRow> load() {
    final ImmutableList.Builder<PurchaseRow> result = ImmutableList.builder();
    final ImmutableMap.Builder<PurchaseCandidate, PurchaseRow> purchaseCandidate2purchaseRowBuilder = ImmutableMap.builder();
    for (final SalesOrderLineWithCandidates salesOrderLineWithCandidates : salesOrderLines.getSalesOrderLinesWithCandidates()) {
        final I_C_OrderLine salesOrderLine = salesOrderLineWithCandidates.getSalesOrderLine();
        final ImmutableList.Builder<PurchaseRow> rows = ImmutableList.builder();
        for (final PurchaseCandidate purchaseCandidate : salesOrderLineWithCandidates.getPurchaseCandidates()) {
            final PurchaseRow candidateRow = purchaseRowFactory.rowFromPurchaseCandidateBuilder().purchaseCandidate(purchaseCandidate).vendorProductInfo(purchaseCandidate.getVendorProductInfo()).datePromised(salesOrderLine.getDatePromised()).build();
            purchaseCandidate2purchaseRowBuilder.put(purchaseCandidate, candidateRow);
            rows.add(candidateRow);
        }
        final // 
        PurchaseRow groupRow = purchaseRowFactory.createGroupRow(salesOrderLine, rows.build());
        result.add(groupRow);
    }
    purchaseCandidate2purchaseRow = purchaseCandidate2purchaseRowBuilder.build();
    return result.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) PurchaseCandidate(de.metas.purchasecandidate.PurchaseCandidate) I_C_OrderLine(org.compiere.model.I_C_OrderLine) ImmutableMap(com.google.common.collect.ImmutableMap) SalesOrderLineWithCandidates(de.metas.purchasecandidate.SalesOrderLineWithCandidates)

Example 8 with PurchaseCandidate

use of de.metas.purchasecandidate.PurchaseCandidate in project metasfresh-webui-api by metasfresh.

the class PurchaseRowsSaver method updatePurchaseCandidate.

private PurchaseCandidate updatePurchaseCandidate(@NonNull final PurchaseRow purchaseRow, @NonNull final Map<Integer, PurchaseCandidate> existingPurchaseCandidatesById) {
    Check.errorUnless(PurchaseRowType.LINE.equals(purchaseRow.getType()), "The given row's type needs to be {}, but is {}; purchaseRow={}", PurchaseRowType.LINE, purchaseRow.getType(), purchaseRow);
    final PurchaseCandidate purchaseCandidate = existingPurchaseCandidatesById.get(purchaseRow.getPurchaseCandidateId());
    Check.errorIf(purchaseCandidate == null, "Missing purchaseCandidate with C_PurchaseCandidate_ID={}; purchaseRow={}, existingPurchaseCandidatesById={}", purchaseRow.getPurchaseCandidateId(), purchaseRow, existingPurchaseCandidatesById);
    purchaseCandidate.setQtyToPurchase(purchaseRow.getQtyToPurchase());
    purchaseCandidate.setDateRequired(purchaseRow.getDatePromised());
    Check.errorIf(purchaseCandidate.isProcessedOrLocked() && purchaseCandidate.hasChanges(), "The given purchaseRow has changes, but its purchaseCandidate is not editable; purchaseRow={}; purchaseCandidate={}", purchaseRow, purchaseCandidate);
    return purchaseCandidate;
}
Also used : PurchaseCandidate(de.metas.purchasecandidate.PurchaseCandidate)

Example 9 with PurchaseCandidate

use of de.metas.purchasecandidate.PurchaseCandidate in project metasfresh-webui-api by metasfresh.

the class SalesOrder2PurchaseViewFactory method getSingleSalesOrder.

private final I_C_Order getSingleSalesOrder(@NonNull final List<PurchaseCandidate> purchaseCandidates) {
    Check.assumeNotEmpty(purchaseCandidates, "purchaseCandidates not empty");
    final int salesOrderId = purchaseCandidates.stream().map(PurchaseCandidate::getSalesOrderId).distinct().collect(GuavaCollectors.singleElementOrThrow(() -> new AdempiereException("More or less than one salesOrderId found in the given purchaseCandidates").appendParametersToMessage().setParameter("purchaseCandidates", purchaseCandidates)));
    final I_C_Order salesOrder = load(salesOrderId, I_C_Order.class);
    return salesOrder;
}
Also used : I_C_Order(org.compiere.model.I_C_Order) AdempiereException(org.adempiere.exceptions.AdempiereException) PurchaseCandidate(de.metas.purchasecandidate.PurchaseCandidate)

Aggregations

PurchaseCandidate (de.metas.purchasecandidate.PurchaseCandidate)9 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)3 ImmutableList (com.google.common.collect.ImmutableList)2 SalesOrderLineWithCandidates (de.metas.purchasecandidate.SalesOrderLineWithCandidates)2 AvailabilityResult (de.metas.purchasecandidate.availability.AvailabilityResult)2 ArrayList (java.util.ArrayList)2 Entry (java.util.Map.Entry)2 Preconditions (com.google.common.base.Preconditions)1 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 RemovalNotification (com.google.common.cache.RemovalNotification)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 IDocument (de.metas.document.engine.IDocument)1 ITranslatableString (de.metas.i18n.ITranslatableString)1 I_C_BPartner_Product (de.metas.interfaces.I_C_BPartner_Product)1 IADProcessDAO (de.metas.process.IADProcessDAO)1 RelatedProcessDescriptor (de.metas.process.RelatedProcessDescriptor)1 PurchaseCandidateRepository (de.metas.purchasecandidate.PurchaseCandidateRepository)1 SalesOrderLines (de.metas.purchasecandidate.SalesOrderLines)1