use of de.metas.purchasecandidate.availability.AvailabilityResult 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());
}
use of de.metas.purchasecandidate.availability.AvailabilityResult 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);
}
Aggregations