Search in sources :

Example 1 with SalesOrderLineRepository

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

the class PurchaseRowsLoaderTest method init.

@BeforeEach
public void init() {
    AdempiereTestHelper.get().init();
    availabilityCheckService = Mockito.mock(AvailabilityCheckService.class);
    org = newInstance(I_AD_Org.class);
    saveRecord(org);
    final I_C_UOM uom = newInstance(I_C_UOM.class);
    uom.setUOMSymbol("testUOMSympol");
    saveRecord(uom);
    this.TEN = Quantity.of(BigDecimal.TEN, uom);
    warehouse = newInstance(I_M_Warehouse.class);
    saveRecord(warehouse);
    final I_M_Product_Category productCategory = newInstance(I_M_Product_Category.class);
    saveRecord(productCategory);
    product = newInstance(I_M_Product.class);
    product.setM_Product_Category_ID(productCategory.getM_Product_Category_ID());
    product.setC_UOM_ID(uom.getC_UOM_ID());
    saveRecord(product);
    final I_C_BPartner bPartnerCustomer = newInstance(I_C_BPartner.class);
    bPartnerCustomer.setName("bPartnerCustomer.Name");
    saveRecord(bPartnerCustomer);
    salesOrderRecord = newInstance(I_C_Order.class);
    salesOrderRecord.setC_BPartner_ID(bPartnerCustomer.getC_BPartner_ID());
    salesOrderRecord.setPreparationDate(SystemTime.asTimestamp());
    salesOrderRecord.setC_PaymentTerm_ID(30);
    saveRecord(salesOrderRecord);
    bPartnerVendor = newInstance(I_C_BPartner.class);
    bPartnerVendor.setName("bPartnerVendor.Name");
    saveRecord(bPartnerVendor);
    currencyId = PlainCurrencyDAO.createCurrencyId(CurrencyCode.EUR);
    // wire together a SalesOrder2PurchaseViewFactory
    final PurchaseCandidateRepository purchaseCandidateRepository = new PurchaseCandidateRepository(new PurchaseItemRepository(), new ReferenceGenerator(), new BPPurchaseScheduleService(new BPPurchaseScheduleRepository()));
    final DoNothingPurchaseProfitInfoServiceImpl purchaseProfitInfoService = new DoNothingPurchaseProfitInfoServiceImpl();
    final PurchaseDemandWithCandidatesService purchaseDemandWithCandidatesService = new PurchaseDemandWithCandidatesService(purchaseCandidateRepository, new BPPurchaseScheduleService(new BPPurchaseScheduleRepository()), new VendorProductInfoService(new BPartnerBL(new UserRepository())), purchaseProfitInfoService);
    final PurchaseRowFactory purchaseRowFactory = new PurchaseRowFactory(new AvailableToPromiseRepository(), purchaseProfitInfoService);
    salesOrder2PurchaseViewFactory = new SalesOrder2PurchaseViewFactory(purchaseDemandWithCandidatesService, // mocked
    availabilityCheckService, purchaseCandidateRepository, purchaseRowFactory, new SalesOrderLineRepository(new OrderLineRepository()));
}
Also used : BPPurchaseScheduleService(de.metas.purchasecandidate.BPPurchaseScheduleService) AvailabilityCheckService(de.metas.purchasecandidate.availability.AvailabilityCheckService) I_C_Order(org.compiere.model.I_C_Order) AvailableToPromiseRepository(de.metas.material.dispo.commons.repository.atp.AvailableToPromiseRepository) I_M_Product(org.compiere.model.I_M_Product) I_AD_Org(org.compiere.model.I_AD_Org) SalesOrderLineRepository(de.metas.purchasecandidate.SalesOrderLineRepository) OrderLineRepository(de.metas.order.OrderLineRepository) SalesOrderLineRepository(de.metas.purchasecandidate.SalesOrderLineRepository) BPartnerBL(de.metas.bpartner.service.impl.BPartnerBL) I_M_Warehouse(org.compiere.model.I_M_Warehouse) PurchaseDemandWithCandidatesService(de.metas.purchasecandidate.PurchaseDemandWithCandidatesService) I_M_Product_Category(org.compiere.model.I_M_Product_Category) PurchaseItemRepository(de.metas.purchasecandidate.purchaseordercreation.remotepurchaseitem.PurchaseItemRepository) UserRepository(de.metas.user.UserRepository) BPPurchaseScheduleRepository(de.metas.purchasecandidate.BPPurchaseScheduleRepository) ReferenceGenerator(de.metas.purchasecandidate.ReferenceGenerator) PurchaseCandidateRepository(de.metas.purchasecandidate.PurchaseCandidateRepository) VendorProductInfoService(de.metas.purchasecandidate.VendorProductInfoService) I_C_UOM(org.compiere.model.I_C_UOM) I_C_BPartner(org.compiere.model.I_C_BPartner) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with SalesOrderLineRepository

use of de.metas.purchasecandidate.SalesOrderLineRepository 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());
}
Also used : PurchaseRowsList(de.metas.ui.web.order.sales.purchasePlanning.view.PurchaseRowsLoader.PurchaseRowsList) AvailableToPromiseRepository(de.metas.material.dispo.commons.repository.atp.AvailableToPromiseRepository) PurchaseDemand(de.metas.purchasecandidate.PurchaseDemand) SalesOrderLineRepository(de.metas.purchasecandidate.SalesOrderLineRepository) OrderLineRepository(de.metas.order.OrderLineRepository) SalesOrderLineRepository(de.metas.purchasecandidate.SalesOrderLineRepository) I_C_OrderLine(org.compiere.model.I_C_OrderLine) PurchaseDemandWithCandidates(de.metas.purchasecandidate.PurchaseDemandWithCandidates) SalesOrderLine(de.metas.purchasecandidate.SalesOrderLine) VendorProductInfo(de.metas.purchasecandidate.VendorProductInfo) PurchaseCandidatesAvailabilityRequest(de.metas.purchasecandidate.availability.PurchaseCandidatesAvailabilityRequest) PurchaseCandidate(de.metas.purchasecandidate.PurchaseCandidate) Test(org.junit.jupiter.api.Test)

Aggregations

AvailableToPromiseRepository (de.metas.material.dispo.commons.repository.atp.AvailableToPromiseRepository)2 OrderLineRepository (de.metas.order.OrderLineRepository)2 SalesOrderLineRepository (de.metas.purchasecandidate.SalesOrderLineRepository)2 BPartnerBL (de.metas.bpartner.service.impl.BPartnerBL)1 BPPurchaseScheduleRepository (de.metas.purchasecandidate.BPPurchaseScheduleRepository)1 BPPurchaseScheduleService (de.metas.purchasecandidate.BPPurchaseScheduleService)1 PurchaseCandidate (de.metas.purchasecandidate.PurchaseCandidate)1 PurchaseCandidateRepository (de.metas.purchasecandidate.PurchaseCandidateRepository)1 PurchaseDemand (de.metas.purchasecandidate.PurchaseDemand)1 PurchaseDemandWithCandidates (de.metas.purchasecandidate.PurchaseDemandWithCandidates)1 PurchaseDemandWithCandidatesService (de.metas.purchasecandidate.PurchaseDemandWithCandidatesService)1 ReferenceGenerator (de.metas.purchasecandidate.ReferenceGenerator)1 SalesOrderLine (de.metas.purchasecandidate.SalesOrderLine)1 VendorProductInfo (de.metas.purchasecandidate.VendorProductInfo)1 VendorProductInfoService (de.metas.purchasecandidate.VendorProductInfoService)1 AvailabilityCheckService (de.metas.purchasecandidate.availability.AvailabilityCheckService)1 PurchaseCandidatesAvailabilityRequest (de.metas.purchasecandidate.availability.PurchaseCandidatesAvailabilityRequest)1 PurchaseItemRepository (de.metas.purchasecandidate.purchaseordercreation.remotepurchaseitem.PurchaseItemRepository)1 PurchaseRowsList (de.metas.ui.web.order.sales.purchasePlanning.view.PurchaseRowsLoader.PurchaseRowsList)1 UserRepository (de.metas.user.UserRepository)1