Search in sources :

Example 1 with PurchaseCandidate

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

the class PurchaseRowsLoader method handleThrowableForAsyncAvailabilityCheck.

private void handleThrowableForAsyncAvailabilityCheck(@Nullable final Throwable throwable) {
    if (throwable == null) {
        return;
    }
    if (throwable instanceof AvailabilityException) {
        final AvailabilityException availabilityException = (AvailabilityException) throwable;
        final List<DocumentId> changedRowIds = new ArrayList<>();
        final Set<Entry<PurchaseCandidate, Throwable>> entrySet = availabilityException.getPurchaseCandidate2Throwable().entrySet();
        for (final Entry<PurchaseCandidate, Throwable> purchaseCandidate2throwable : entrySet) {
            final PurchaseRow purchaseRowToAugment = purchaseCandidate2purchaseRow.get(purchaseCandidate2throwable.getKey());
            final PurchaseRow availabilityResultRow = purchaseRowFactory.rowFromThrowableBuilder().parentRow(purchaseRowToAugment).throwable(purchaseCandidate2throwable.getValue()).build();
            purchaseRowToAugment.setAvailabilityInfoRows(ImmutableList.of(availabilityResultRow));
            changedRowIds.add(purchaseRowToAugment.getId());
        }
        notifyViewOfChanges(changedRowIds);
    } else {
    // TODO: display an error-message in the webui
    }
}
Also used : AvailabilityException(de.metas.purchasecandidate.availability.AvailabilityException) Entry(java.util.Map.Entry) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) ArrayList(java.util.ArrayList) PurchaseCandidate(de.metas.purchasecandidate.PurchaseCandidate)

Example 2 with PurchaseCandidate

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

the class SalesOrder2PurchaseViewFactory method saveRowsAndEnqueueIfOrderCompleted.

private void saveRowsAndEnqueueIfOrderCompleted(final PurchaseView purchaseView) {
    final List<PurchaseCandidate> purchaseCandidates = saveRows(purchaseView);
    if (purchaseCandidates.isEmpty()) {
        return;
    }
    // 
    // If the sales order was already completed, enqueue the purchase candidates
    final I_C_Order salesOrder = getSingleSalesOrder(purchaseCandidates);
    if (IDocument.STATUS_Completed.equals(salesOrder.getDocStatus())) {
        final Set<Integer> purchaseCandidateIds = purchaseCandidates.stream().filter(purchaseCandidate -> !purchaseCandidate.isProcessedOrLocked()).filter(purchaseCandidate -> purchaseCandidate.getQtyToPurchase().signum() > 0).map(PurchaseCandidate::getPurchaseCandidateId).collect(ImmutableSet.toImmutableSet());
        if (purchaseCandidateIds.size() > 0) {
            C_PurchaseCandidates_GeneratePurchaseOrders.enqueue(purchaseCandidateIds);
        }
    }
}
Also used : ArrayKey(org.compiere.util.Util.ArrayKey) IDocument(de.metas.document.engine.IDocument) CCache(org.compiere.util.CCache) GuavaCollectors(org.adempiere.util.GuavaCollectors) ViewFactory(de.metas.ui.web.view.ViewFactory) Env(org.compiere.util.Env) WEBUI_SalesOrder_Apply_Availability_Row(de.metas.ui.web.order.sales.purchasePlanning.process.WEBUI_SalesOrder_Apply_Availability_Row) JSONViewDataType(de.metas.ui.web.view.json.JSONViewDataType) IViewsIndexStorage(de.metas.ui.web.view.IViewsIndexStorage) I_C_Order(org.compiere.model.I_C_Order) PurchaseCandidateRepository(de.metas.purchasecandidate.PurchaseCandidateRepository) IView(de.metas.ui.web.view.IView) ISysConfigBL(org.adempiere.service.ISysConfigBL) ViewLayout(de.metas.ui.web.view.descriptor.ViewLayout) IViewFactory(de.metas.ui.web.view.IViewFactory) Nullable(javax.annotation.Nullable) IADProcessDAO(de.metas.process.IADProcessDAO) RemovalNotification(com.google.common.cache.RemovalNotification) SalesOrderLines(de.metas.purchasecandidate.SalesOrderLines) Properties(java.util.Properties) ImmutableSet(com.google.common.collect.ImmutableSet) C_PurchaseCandidates_GeneratePurchaseOrders(de.metas.purchasecandidate.async.C_PurchaseCandidates_GeneratePurchaseOrders) ViewCloseReason(de.metas.ui.web.view.ViewCloseReason) ITranslatableString(de.metas.i18n.ITranslatableString) NonNull(lombok.NonNull) RelatedProcessDescriptor(de.metas.process.RelatedProcessDescriptor) PurchaseCandidate(de.metas.purchasecandidate.PurchaseCandidate) ViewProfileId(de.metas.ui.web.view.ViewProfileId) Set(java.util.Set) WindowId(de.metas.ui.web.window.datatypes.WindowId) WEBUI_SalesOrder_PurchaseView_Launcher(de.metas.ui.web.order.sales.purchasePlanning.process.WEBUI_SalesOrder_PurchaseView_Launcher) TimeUnit(java.util.concurrent.TimeUnit) Services(org.adempiere.util.Services) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException) List(java.util.List) Stream(java.util.stream.Stream) AdempiereException(org.adempiere.exceptions.AdempiereException) Check(org.adempiere.util.Check) InterfaceWrapperHelper.load(org.adempiere.model.InterfaceWrapperHelper.load) Preconditions(com.google.common.base.Preconditions) CacheBuilder(com.google.common.cache.CacheBuilder) CreateViewRequest(de.metas.ui.web.view.CreateViewRequest) Cache(com.google.common.cache.Cache) ViewId(de.metas.ui.web.view.ViewId) I_C_Order(org.compiere.model.I_C_Order) PurchaseCandidate(de.metas.purchasecandidate.PurchaseCandidate)

Example 3 with PurchaseCandidate

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

the class PurchaseRowsLoaderTest method test.

@Test
public void test() {
    final I_C_OrderLine orderLine = newInstance(I_C_OrderLine.class);
    orderLine.setM_Product(product);
    orderLine.setC_Order(order);
    orderLine.setDatePromised(SystemTime.asTimestamp());
    save(orderLine);
    final I_C_BPartner_Product bPartnerProduct = newInstance(I_C_BPartner_Product.class);
    bPartnerProduct.setC_BPartner_Vendor(bPartnerVendor);
    bPartnerProduct.setM_Product(product);
    bPartnerProduct.setVendorProductNo("bPartnerProduct.VendorProductNo");
    bPartnerProduct.setProductName("bPartnerProduct.ProductName");
    save(bPartnerProduct);
    final PurchaseCandidate purchaseCandidate = createPurchaseCandidate(orderLine, bPartnerProduct);
    final // 
    ImmutableList<SalesOrderLineWithCandidates> salesOrderLinesWithPurchaseCandidates = createSalesOrderLinesWithPurchaseCandidates(orderLine, purchaseCandidate);
    // @formatter:off
    new Expectations() {

        {
            salesOrderLines.getSalesOrderLinesWithCandidates();
            result = salesOrderLinesWithPurchaseCandidates;
        }
    };
    // @formatter:on
    final Multimap<PurchaseCandidate, AvailabilityResult> checkAvailabilityResult = ArrayListMultimap.create();
    checkAvailabilityResult.put(purchaseCandidate, AvailabilityResult.builder().purchaseCandidate(purchaseCandidate).qty(BigDecimal.TEN).type(Type.AVAILABLE).build());
    // @formatter:off
    new Expectations() {

        {
            salesOrderLines.checkAvailability();
            result = checkAvailabilityResult;
        }
    };
    // @formatter:on
    final PurchaseRowsLoader loader = PurchaseRowsLoader.builder().salesOrderLines(salesOrderLines).purchaseRowFactory(new PurchaseRowFactory()).viewSupplier(() -> null).build();
    final List<PurchaseRow> groupRows = loader.load();
    assertThat(groupRows).hasSize(1);
    final PurchaseRow groupRow = groupRows.get(0);
    assertThat(groupRow.getRowType()).isEqualTo(PurchaseRowType.GROUP);
    assertThat(groupRow.getIncludedRows()).hasSize(1);
    final PurchaseRow purchaseRow = groupRow.getIncludedRows().get(0);
    assertThat(purchaseRow.getRowType()).isEqualTo(PurchaseRowType.LINE);
    assertThat(purchaseRow.getIncludedRows()).isEmpty();
    loader.createAndAddAvailabilityResultRows();
    assertThat(purchaseRow.getIncludedRows()).hasSize(1);
    final PurchaseRow availabilityRow = purchaseRow.getIncludedRows().get(0);
    assertThat(availabilityRow.getRowType()).isEqualTo(PurchaseRowType.AVAILABILITY_DETAIL);
    assertThat(availabilityRow.getRowId().toDocumentId()).isNotEqualTo(purchaseRow.getRowId().toDocumentId());
}
Also used : Expectations(mockit.Expectations) AvailabilityResult(de.metas.purchasecandidate.availability.AvailabilityResult) I_C_BPartner_Product(de.metas.interfaces.I_C_BPartner_Product) I_C_OrderLine(org.compiere.model.I_C_OrderLine) PurchaseCandidate(de.metas.purchasecandidate.PurchaseCandidate) SalesOrderLineWithCandidates(de.metas.purchasecandidate.SalesOrderLineWithCandidates) Test(org.junit.Test)

Example 4 with PurchaseCandidate

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

the class PurchaseRowsLoaderTest method createPurchaseCandidate.

private static PurchaseCandidate createPurchaseCandidate(final I_C_OrderLine orderLine, final I_C_BPartner_Product bPartnerProduct) {
    final VendorProductInfo vendorProductInfo = VendorProductInfo.fromDataRecord(bPartnerProduct);
    final PurchaseCandidate purchaseCandidate = PurchaseCandidate.builder().orgId(20).dateRequired(orderLine.getDatePromised()).productId(orderLine.getM_Product_ID()).qtyToPurchase(orderLine.getQtyOrdered()).salesOrderId(orderLine.getC_Order_ID()).salesOrderLineId(orderLine.getC_OrderLine_ID()).uomId(orderLine.getM_Product().getC_UOM_ID()).vendorBPartnerId(vendorProductInfo.getVendorBPartnerId()).vendorProductInfo(vendorProductInfo).warehouseId(30).build();
    return purchaseCandidate;
}
Also used : VendorProductInfo(de.metas.purchasecandidate.VendorProductInfo) PurchaseCandidate(de.metas.purchasecandidate.PurchaseCandidate)

Example 5 with PurchaseCandidate

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

the class PurchaseRowFactoryTest method test.

@Test
public void test() {
    final PurchaseCandidate purchaseCandidate = createPurchaseCandidate(30);
    final PurchaseRowFactory purchaseRowFactory = new PurchaseRowFactory();
    final PurchaseRow candidateRow = purchaseRowFactory.rowFromPurchaseCandidateBuilder().purchaseCandidate(purchaseCandidate).vendorProductInfo(purchaseCandidate.getVendorProductInfo()).datePromised(SystemTime.asTimestamp()).build();
    final DocumentId id = candidateRow.getId();
    final PurchaseRowId purchaseRowId = PurchaseRowId.fromDocumentId(id);
    assertThat(purchaseRowId.getVendorBPartnerId()).isEqualTo(purchaseCandidate.getVendorBPartnerId());
    assertThat(purchaseRowId.getSalesOrderLineId()).isEqualTo(purchaseCandidate.getSalesOrderLineId());
    assertThat(purchaseRowId.getProcessedPurchaseCandidateId()).isEqualTo(30);
}
Also used : DocumentId(de.metas.ui.web.window.datatypes.DocumentId) PurchaseCandidate(de.metas.purchasecandidate.PurchaseCandidate) Test(org.junit.Test)

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