Search in sources :

Example 1 with SalesOrderLine

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

the class WEBUI_C_OrderLineSO_Delete_HUReservation method checkPreconditionsApplicable.

@Override
public ProcessPreconditionsResolution checkPreconditionsApplicable() {
    final SalesOrderLine salesOrderLine = WEBUI_C_OrderLineSO_Util.retrieveSalesOrderLine(getView(), salesOrderLineRepository).orElse(null);
    if (salesOrderLine == null) {
        return ProcessPreconditionsResolution.rejectWithInternalReason("No sales order was set");
    }
    final ProductId productId = salesOrderLine.getProductId();
    final Quantity unreservableQty = retrieveUnreservableQuantity(productId);
    if (unreservableQty.signum() <= 0) {
        return ProcessPreconditionsResolution.rejectWithInternalReason("No unreservableQty quantity for productId=" + productId);
    }
    return ProcessPreconditionsResolution.accept();
}
Also used : SalesOrderLine(de.metas.purchasecandidate.SalesOrderLine) Quantity(de.metas.quantity.Quantity) ProductId(de.metas.product.ProductId)

Example 2 with SalesOrderLine

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

the class WEBUI_C_OrderLineSO_Make_HUReservation method getParameterDefaultValue.

@Override
public Object getParameterDefaultValue(@NonNull final IProcessDefaultParameter parameter) {
    if (PARAMNAME_QTY_TO_RESERVE.equals(parameter.getColumnName())) {
        final SalesOrderLine salesOrderLine = WEBUI_C_OrderLineSO_Util.retrieveSalesOrderLine(getView(), salesOrderLineRepository).get();
        final ProductId productId = salesOrderLine.getProductId();
        final Quantity orderedQty = salesOrderLine.getOrderedQty();
        final Quantity reservedQty = huReservationService.retrieveReservedQty(salesOrderLine.getId().getOrderLineId()).orElse(orderedQty.toZero());
        final Quantity reservedQtyInSalesOrderUOM = uomConversionBL.convertQuantityTo(reservedQty, UOMConversionContext.of(productId), orderedQty.getUomId());
        final Quantity requiredQty = orderedQty.subtract(salesOrderLine.getDeliveredQty()).subtract(reservedQtyInSalesOrderUOM);
        final Quantity reservableQty = retrieveReservableQuantity(productId);
        final Quantity reservableQtyInSalesOrderUOM = uomConversionBL.convertQuantityTo(reservableQty, UOMConversionContext.of(productId), orderedQty.getUomId());
        return requiredQty.min(reservableQtyInSalesOrderUOM).toBigDecimal();
    }
    return null;
}
Also used : SalesOrderLine(de.metas.purchasecandidate.SalesOrderLine) Quantity(de.metas.quantity.Quantity) ProductId(de.metas.product.ProductId)

Example 3 with SalesOrderLine

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

the class WEBUI_C_OrderLineSO_Make_HUReservation method doIt.

@Override
protected String doIt() {
    final SalesOrderLine salesOrderLine = WEBUI_C_OrderLineSO_Util.retrieveSalesOrderLine(getView(), salesOrderLineRepository).get();
    final ImmutableList<HuId> selectedHuIds = streamSelectedHUIds(Select.ALL).collect(ImmutableList.toImmutableList());
    if (selectedHuIds.isEmpty()) {
        throw new AdempiereException("@NoSelection@");
    }
    final Quantity qtyToReserve = Quantity.of(qtyToReserveBD, salesOrderLine.getOrderedQty().getUOM());
    final ReserveHUsRequest reservationRequest = ReserveHUsRequest.builder().huIds(selectedHuIds).productId(salesOrderLine.getProductId()).qtyToReserve(qtyToReserve).salesOrderLineId(salesOrderLine.getId().getOrderLineId()).build();
    huReservationService.makeReservation(reservationRequest);
    return MSG_OK;
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) SalesOrderLine(de.metas.purchasecandidate.SalesOrderLine) Quantity(de.metas.quantity.Quantity) HuId(de.metas.handlingunits.HuId) ReserveHUsRequest(de.metas.handlingunits.reservation.ReserveHUsRequest)

Example 4 with SalesOrderLine

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

Example 5 with SalesOrderLine

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

the class WEBUI_C_OrderLineSO_Make_HUReservation method checkPreconditionsApplicable.

@Override
public ProcessPreconditionsResolution checkPreconditionsApplicable() {
    final SalesOrderLine salesOrderLine = WEBUI_C_OrderLineSO_Util.retrieveSalesOrderLine(getView(), salesOrderLineRepository).orElse(null);
    if (salesOrderLine == null) {
        return ProcessPreconditionsResolution.rejectWithInternalReason("No sales order was set");
    }
    final ProductId productId = salesOrderLine.getProductId();
    final Quantity reservableQty = retrieveReservableQuantity(productId);
    if (reservableQty.signum() <= 0) {
        return ProcessPreconditionsResolution.rejectWithInternalReason("No reservable quantity for productId=" + productId);
    }
    return ProcessPreconditionsResolution.accept();
}
Also used : SalesOrderLine(de.metas.purchasecandidate.SalesOrderLine) Quantity(de.metas.quantity.Quantity) ProductId(de.metas.product.ProductId)

Aggregations

SalesOrderLine (de.metas.purchasecandidate.SalesOrderLine)5 Quantity (de.metas.quantity.Quantity)4 ProductId (de.metas.product.ProductId)3 HuId (de.metas.handlingunits.HuId)1 ReserveHUsRequest (de.metas.handlingunits.reservation.ReserveHUsRequest)1 AvailableToPromiseRepository (de.metas.material.dispo.commons.repository.atp.AvailableToPromiseRepository)1 OrderLineRepository (de.metas.order.OrderLineRepository)1 PurchaseCandidate (de.metas.purchasecandidate.PurchaseCandidate)1 PurchaseDemand (de.metas.purchasecandidate.PurchaseDemand)1 PurchaseDemandWithCandidates (de.metas.purchasecandidate.PurchaseDemandWithCandidates)1 SalesOrderLineRepository (de.metas.purchasecandidate.SalesOrderLineRepository)1 VendorProductInfo (de.metas.purchasecandidate.VendorProductInfo)1 PurchaseCandidatesAvailabilityRequest (de.metas.purchasecandidate.availability.PurchaseCandidatesAvailabilityRequest)1 PurchaseRowsList (de.metas.ui.web.order.sales.purchasePlanning.view.PurchaseRowsLoader.PurchaseRowsList)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 I_C_OrderLine (org.compiere.model.I_C_OrderLine)1 Test (org.junit.jupiter.api.Test)1