Search in sources :

Example 1 with ProductsProposalRowsLoader

use of de.metas.ui.web.order.products_proposal.model.ProductsProposalRowsLoader in project metasfresh-webui-api by metasfresh.

the class BPartnerProductsProposalViewFactory method createRowsLoaderFromRecord.

@Override
protected ProductsProposalRowsLoader createRowsLoaderFromRecord(TableRecordReference recordRef) {
    final IBPartnerDAO bpartnersRepo = Services.get(IBPartnerDAO.class);
    final IPriceListDAO priceListsRepo = Services.get(IPriceListDAO.class);
    recordRef.assertTableName(I_C_BPartner.Table_Name);
    final BPartnerId bpartnerId = BPartnerId.ofRepoId(recordRef.getRecord_ID());
    final Set<CountryId> countryIds = bpartnersRepo.retrieveBPartnerLocationCountryIds(bpartnerId);
    if (countryIds.isEmpty()) {
        throw new AdempiereException("@NotFound@ @C_BPartner_Location_ID@");
    }
    final I_C_BPartner bpartnerRecord = bpartnersRepo.getById(bpartnerId);
    PricingSystemId pricingSystemId = null;
    SOTrx soTrx = null;
    if (bpartnerRecord.isCustomer()) {
        pricingSystemId = PricingSystemId.ofRepoIdOrNull(bpartnerRecord.getM_PricingSystem_ID());
        soTrx = SOTrx.SALES;
    }
    if (pricingSystemId == null && bpartnerRecord.isVendor()) {
        pricingSystemId = PricingSystemId.ofRepoIdOrNull(bpartnerRecord.getPO_PricingSystem_ID());
        soTrx = SOTrx.PURCHASE;
    }
    if (pricingSystemId == null) {
        throw new AdempiereException("@NotFound@ @M_PricingSystem_ID@");
    }
    final ZonedDateTime today = SystemTime.asZonedDateTime();
    final Set<PriceListVersionId> priceListVersionIds = priceListsRepo.retrievePriceListsCollectionByPricingSystemId(pricingSystemId).filterAndStreamIds(countryIds).map(priceListId -> priceListsRepo.retrievePriceListVersionId(priceListId, today)).collect(ImmutableSet.toImmutableSet());
    return ProductsProposalRowsLoader.builder().bpartnerProductStatsService(bpartnerProductStatsService).priceListVersionIds(priceListVersionIds).bpartnerId(bpartnerId).soTrx(soTrx).build();
}
Also used : CountryId(de.metas.location.CountryId) IBPartnerDAO(de.metas.bpartner.service.IBPartnerDAO) ViewFactory(de.metas.ui.web.view.ViewFactory) ZonedDateTime(java.time.ZonedDateTime) PriceListVersionId(de.metas.pricing.PriceListVersionId) ImmutableList(com.google.common.collect.ImmutableList) BPartnerProductStatsService(de.metas.bpartner.product.stats.BPartnerProductStatsService) ViewLayout(de.metas.ui.web.view.descriptor.ViewLayout) ViewCloseAction(de.metas.ui.web.view.ViewCloseAction) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) I_C_BPartner(org.compiere.model.I_C_BPartner) CountryId(de.metas.location.CountryId) ImmutableSet(com.google.common.collect.ImmutableSet) WEBUI_BPartner_ProductsProposal_Launcher(de.metas.ui.web.order.products_proposal.process.WEBUI_BPartner_ProductsProposal_Launcher) ITranslatableString(de.metas.i18n.ITranslatableString) NonNull(lombok.NonNull) RelatedProcessDescriptor(de.metas.process.RelatedProcessDescriptor) Set(java.util.Set) WindowId(de.metas.ui.web.window.datatypes.WindowId) ProductsProposalRowsLoader(de.metas.ui.web.order.products_proposal.model.ProductsProposalRowsLoader) Services(de.metas.util.Services) SOTrx(de.metas.lang.SOTrx) List(java.util.List) AdempiereException(org.adempiere.exceptions.AdempiereException) WEBUI_ProductsProposal_ShowProductsToAddFromBasePriceList(de.metas.ui.web.order.products_proposal.process.WEBUI_ProductsProposal_ShowProductsToAddFromBasePriceList) BPartnerId(de.metas.bpartner.BPartnerId) ProductsProposalRow(de.metas.ui.web.order.products_proposal.model.ProductsProposalRow) PricingSystemId(de.metas.pricing.PricingSystemId) IPriceListDAO(de.metas.pricing.service.IPriceListDAO) WEBUI_ProductsProposal_SaveProductPriceToCurrentPriceListVersion(de.metas.ui.web.order.products_proposal.process.WEBUI_ProductsProposal_SaveProductPriceToCurrentPriceListVersion) SystemTime(de.metas.util.time.SystemTime) IPriceListDAO(de.metas.pricing.service.IPriceListDAO) SOTrx(de.metas.lang.SOTrx) PriceListVersionId(de.metas.pricing.PriceListVersionId) IBPartnerDAO(de.metas.bpartner.service.IBPartnerDAO) ZonedDateTime(java.time.ZonedDateTime) AdempiereException(org.adempiere.exceptions.AdempiereException) BPartnerId(de.metas.bpartner.BPartnerId) PricingSystemId(de.metas.pricing.PricingSystemId) I_C_BPartner(org.compiere.model.I_C_BPartner)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 BPartnerId (de.metas.bpartner.BPartnerId)1 BPartnerProductStatsService (de.metas.bpartner.product.stats.BPartnerProductStatsService)1 IBPartnerDAO (de.metas.bpartner.service.IBPartnerDAO)1 ITranslatableString (de.metas.i18n.ITranslatableString)1 SOTrx (de.metas.lang.SOTrx)1 CountryId (de.metas.location.CountryId)1 PriceListVersionId (de.metas.pricing.PriceListVersionId)1 PricingSystemId (de.metas.pricing.PricingSystemId)1 IPriceListDAO (de.metas.pricing.service.IPriceListDAO)1 RelatedProcessDescriptor (de.metas.process.RelatedProcessDescriptor)1 ProductsProposalRow (de.metas.ui.web.order.products_proposal.model.ProductsProposalRow)1 ProductsProposalRowsLoader (de.metas.ui.web.order.products_proposal.model.ProductsProposalRowsLoader)1 WEBUI_BPartner_ProductsProposal_Launcher (de.metas.ui.web.order.products_proposal.process.WEBUI_BPartner_ProductsProposal_Launcher)1 WEBUI_ProductsProposal_SaveProductPriceToCurrentPriceListVersion (de.metas.ui.web.order.products_proposal.process.WEBUI_ProductsProposal_SaveProductPriceToCurrentPriceListVersion)1 WEBUI_ProductsProposal_ShowProductsToAddFromBasePriceList (de.metas.ui.web.order.products_proposal.process.WEBUI_ProductsProposal_ShowProductsToAddFromBasePriceList)1 ViewCloseAction (de.metas.ui.web.view.ViewCloseAction)1 ViewFactory (de.metas.ui.web.view.ViewFactory)1 ViewLayout (de.metas.ui.web.view.descriptor.ViewLayout)1