Search in sources :

Example 1 with SalesOrderLineWithCandidates

use of de.metas.purchasecandidate.SalesOrderLineWithCandidates 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 2 with SalesOrderLineWithCandidates

use of de.metas.purchasecandidate.SalesOrderLineWithCandidates 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)

Aggregations

PurchaseCandidate (de.metas.purchasecandidate.PurchaseCandidate)2 SalesOrderLineWithCandidates (de.metas.purchasecandidate.SalesOrderLineWithCandidates)2 I_C_OrderLine (org.compiere.model.I_C_OrderLine)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 I_C_BPartner_Product (de.metas.interfaces.I_C_BPartner_Product)1 AvailabilityResult (de.metas.purchasecandidate.availability.AvailabilityResult)1 Expectations (mockit.Expectations)1 Test (org.junit.Test)1