use of de.metas.purchasecandidate.PurchaseDemandWithCandidates in project metasfresh-webui-api by metasfresh.
the class PurchaseRowsLoaderTest method load_and_createAndAddAvailabilityResultRows.
@Test
public void load_and_createAndAddAvailabilityResultRows() {
//
// set up salesOrderLineRecord
final I_C_OrderLine salesOrderLineRecord = newInstance(I_C_OrderLine.class);
salesOrderLineRecord.setAD_Org_ID(org.getAD_Org_ID());
salesOrderLineRecord.setM_Product_ID(product.getM_Product_ID());
salesOrderLineRecord.setM_Warehouse_ID(warehouse.getM_Warehouse_ID());
salesOrderLineRecord.setC_Order_ID(salesOrderRecord.getC_Order_ID());
salesOrderLineRecord.setC_Currency_ID(currencyId.getRepoId());
salesOrderLineRecord.setC_UOM_ID(TEN.getUomId().getRepoId());
salesOrderLineRecord.setQtyEntered(TEN.toBigDecimal());
salesOrderLineRecord.setQtyOrdered(TEN.toBigDecimal());
salesOrderLineRecord.setDatePromised(SystemTime.asTimestamp());
save(salesOrderLineRecord);
final SalesOrderLineRepository salesOrderLineRepository = new SalesOrderLineRepository(new OrderLineRepository());
final SalesOrderLine salesOrderLine = salesOrderLineRepository.ofRecord(salesOrderLineRecord);
//
// set up vendorProductInfo
final VendorProductInfo vendorProductInfo = VendorProductInfo.builder().vendorId(BPartnerId.ofRepoId(bPartnerVendor.getC_BPartner_ID())).defaultVendor(false).product(ProductAndCategoryAndManufacturerId.of(product.getM_Product_ID(), product.getM_Product_Category_ID(), product.getManufacturer_ID())).attributeSetInstanceId(AttributeSetInstanceId.NONE).vendorProductNo("bPartnerProduct.VendorProductNo").vendorProductName("bPartnerProduct.ProductName").pricingConditions(PricingConditions.builder().build()).build();
//
// create purchaseCandidate from salesOrderLineRecord and vendorProductInfo
final PurchaseDemand demand = salesOrder2PurchaseViewFactory.createDemand(salesOrderLine);
final PurchaseCandidate purchaseCandidate = createPurchaseCandidate(salesOrderLineRecord, vendorProductInfo);
final ImmutableList<PurchaseDemandWithCandidates> demandWithCandidates = createPurchaseDemandWithCandidates(demand, purchaseCandidate, vendorProductInfo);
final PurchaseRowsLoader loader = PurchaseRowsLoader.builder().purchaseDemandWithCandidatesList(demandWithCandidates).viewSupplier(() -> null).purchaseRowFactory(new PurchaseRowFactory(new AvailableToPromiseRepository(), new DoNothingPurchaseProfitInfoServiceImpl())).availabilityCheckService(availabilityCheckService).build();
//
// invoke the method under test FIRST PART
final PurchaseRowsList rowsList = loader.load();
//
// Check result
final List<PurchaseRow> topLevelRows = rowsList.getTopLevelRows();
assertThat(topLevelRows).hasSize(1);
final PurchaseRow groupRow = topLevelRows.get(0);
assertThat(groupRow.getType()).isEqualTo(PurchaseRowType.GROUP);
assertThat(groupRow.getQtyToPurchase().toBigDecimal()).isEqualByComparingTo(TEN.toBigDecimal());
assertThat(groupRow.getIncludedRows()).hasSize(1);
final PurchaseRow purchaseRow = groupRow.getIncludedRows().iterator().next();
assertThat(purchaseRow.getType()).isEqualTo(PurchaseRowType.LINE);
assertThat(purchaseRow.getIncludedRows()).isEmpty();
//
// set up availabilityCheckService
{
final PurchaseCandidatesAvailabilityRequest request = loader.createAvailabilityRequest(rowsList);
Mockito.doReturn(AvailabilityMultiResult.of(AvailabilityResult.builder().trackingId(request.getTrackingIds().iterator().next()).qty(TEN).type(Type.AVAILABLE).build())).when(availabilityCheckService).checkAvailability(request);
}
//
// invoke the method under test SECOND PART
loader.createAndAddAvailabilityResultRows(rowsList);
assertThat(purchaseRow.getIncludedRows()).hasSize(1);
final PurchaseRow availabilityRow = purchaseRow.getIncludedRows().iterator().next();
assertThat(availabilityRow.getType()).isEqualTo(PurchaseRowType.AVAILABILITY_DETAIL);
assertThat(availabilityRow.getRowId().toDocumentId()).isNotEqualTo(purchaseRow.getRowId().toDocumentId());
}
use of de.metas.purchasecandidate.PurchaseDemandWithCandidates in project metasfresh-webui-api by metasfresh.
the class PurchaseViewFactoryTemplate method createView.
@Override
public final PurchaseView createView(@NonNull final CreateViewRequest request) {
final ViewId viewId = newViewId();
final List<PurchaseDemand> demands = getDemands(request);
final List<PurchaseDemandWithCandidates> purchaseDemandWithCandidatesList = purchaseDemandWithCandidatesService.getOrCreatePurchaseCandidatesGroups(demands);
final PurchaseRowsSupplier rowsSupplier = createRowsSupplier(viewId, purchaseDemandWithCandidatesList);
final PurchaseView view = PurchaseView.builder().viewId(viewId).rowsSupplier(rowsSupplier).additionalRelatedProcessDescriptors(getAdditionalProcessDescriptors()).build();
return view;
}
use of de.metas.purchasecandidate.PurchaseDemandWithCandidates in project metasfresh-webui-api by metasfresh.
the class PurchaseRowsLoader method load.
@VisibleForTesting
PurchaseRowsList load() {
final PurchaseRowsList.PurchaseRowsListBuilder resultBuilder = PurchaseRowsList.builder();
for (final PurchaseDemandWithCandidates demandWithCandidates : purchaseDemandWithCandidatesList) {
final PurchaseDemand demand = demandWithCandidates.getPurchaseDemand();
final List<PurchaseRow> purchaseCandidateRows = new ArrayList<>();
final List<TrackingId> trackingIds = new ArrayList<>();
for (final PurchaseCandidatesGroup purchaseCandidatesGroup : demandWithCandidates.getPurchaseCandidatesGroups()) {
final PurchaseRow purchaseCandidateRow = purchaseRowFactory.lineRowBuilder().purchaseCandidatesGroup(purchaseCandidatesGroup).convertAmountsToCurrencyId(demand.getCurrencyIdOrNull()).build();
purchaseCandidateRows.add(purchaseCandidateRow);
final TrackingId trackingId = TrackingId.random();
trackingIds.add(trackingId);
resultBuilder.purchaseCandidatesGroup(trackingId, purchaseCandidatesGroup);
resultBuilder.purchaseCandidateRow(trackingId, purchaseCandidateRow);
}
final PurchaseRow groupRow = purchaseRowFactory.createGroupRow(demand, purchaseCandidateRows);
resultBuilder.topLevelRow(groupRow);
final PurchaseRowId groupRowId = groupRow.getRowId();
trackingIds.forEach(trackingId -> resultBuilder.trackingIdsByTopLevelRowId(trackingId, groupRowId));
}
return resultBuilder.build();
}
Aggregations