Search in sources :

Example 1 with PricingSystemId

use of de.metas.pricing.PricingSystemId 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)

Example 2 with PricingSystemId

use of de.metas.pricing.PricingSystemId in project metasfresh-webui-api by metasfresh.

the class DefaultPackingItemCriteria method of.

public static Optional<DefaultPackingItemCriteria> of(final I_C_Order order, final ProductId productId) {
    final BPartnerLocationId bpartnerLocationId = BPartnerLocationId.ofRepoIdOrNull(order.getC_BPartner_ID(), order.getC_BPartner_Location_ID());
    final PricingSystemId pricingSystemId = PricingSystemId.ofRepoIdOrNull(order.getM_PricingSystem_ID());
    final ZonedDateTime date = TimeUtil.asZonedDateTime(order.getDatePromised());
    final SOTrx soTrx = SOTrx.ofBoolean(order.isSOTrx());
    final boolean anyNull = Stream.of(bpartnerLocationId, pricingSystemId, date, productId).anyMatch(Objects::isNull);
    if (anyNull) {
        return Optional.empty();
    }
    return Optional.of(builder().bPartnerLocationId(bpartnerLocationId).productId(productId).pricingSystemId(pricingSystemId).date(date).soTrx(soTrx).build());
}
Also used : ZonedDateTime(java.time.ZonedDateTime) BPartnerLocationId(de.metas.bpartner.BPartnerLocationId) SOTrx(de.metas.lang.SOTrx) Objects(java.util.Objects) PricingSystemId(de.metas.pricing.PricingSystemId)

Example 3 with PricingSystemId

use of de.metas.pricing.PricingSystemId in project metasfresh-webui-api by metasfresh.

the class PricingConditionsRowActions method toPartialPriceChange.

private static PartialPriceChange toPartialPriceChange(final List<JSONDocumentChangedEvent> fieldChangeRequests, final CurrencyId defaultCurrencyId) {
    final PartialPriceChangeBuilder builder = PartialPriceChange.builder().defaultCurrencyId(defaultCurrencyId);
    for (final JSONDocumentChangedEvent fieldChangeRequest : fieldChangeRequests) {
        final String fieldName = fieldChangeRequest.getPath();
        builder.changedFieldName(fieldName);
        if (PricingConditionsRow.FIELDNAME_BasePriceType.equals(fieldName)) {
            final LookupValue priceTypeLookupValue = fieldChangeRequest.getValueAsStringLookupValue();
            final PriceSpecificationType priceType = priceTypeLookupValue != null ? PriceSpecificationType.ofCode(priceTypeLookupValue.getIdAsString()) : null;
            builder.priceType(priceType);
        } else if (PricingConditionsRow.FIELDNAME_BasePricingSystem.equals(fieldName)) {
            final LookupValue pricingSystem = fieldChangeRequest.getValueAsIntegerLookupValue();
            final PricingSystemId pricingSystemId = pricingSystem != null ? PricingSystemId.ofRepoIdOrNull(pricingSystem.getIdAsInt()) : null;
            builder.basePricingSystemId(Optional.ofNullable(pricingSystemId));
        } else if (PricingConditionsRow.FIELDNAME_PricingSystemSurcharge.equals(fieldName)) {
            builder.pricingSystemSurchargeAmt(fieldChangeRequest.getValueAsBigDecimal(BigDecimal.ZERO));
        } else if (PricingConditionsRow.FIELDNAME_BasePrice.equals(fieldName)) {
            builder.fixedPriceAmt(fieldChangeRequest.getValueAsBigDecimal(BigDecimal.ZERO));
        } else if (PricingConditionsRow.FIELDNAME_C_Currency_ID.equals(fieldName)) {
            final LookupValue currency = fieldChangeRequest.getValueAsIntegerLookupValue();
            final CurrencyId currencyId = currency != null ? CurrencyId.ofRepoIdOrNull(currency.getIdAsInt()) : null;
            builder.currencyId(currencyId);
            if (currencyId != null) {
                builder.defaultCurrencyId(currencyId);
            }
        }
    }
    return builder.build();
}
Also used : PartialPriceChangeBuilder(de.metas.ui.web.order.pricingconditions.view.PricingConditionsRowChangeRequest.PartialPriceChange.PartialPriceChangeBuilder) PriceSpecificationType(de.metas.pricing.conditions.PriceSpecificationType) JSONDocumentChangedEvent(de.metas.ui.web.window.datatypes.json.JSONDocumentChangedEvent) PricingSystemId(de.metas.pricing.PricingSystemId) CurrencyId(de.metas.money.CurrencyId) LookupValue(de.metas.ui.web.window.datatypes.LookupValue)

Aggregations

PricingSystemId (de.metas.pricing.PricingSystemId)3 SOTrx (de.metas.lang.SOTrx)2 ZonedDateTime (java.time.ZonedDateTime)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 BPartnerId (de.metas.bpartner.BPartnerId)1 BPartnerLocationId (de.metas.bpartner.BPartnerLocationId)1 BPartnerProductStatsService (de.metas.bpartner.product.stats.BPartnerProductStatsService)1 IBPartnerDAO (de.metas.bpartner.service.IBPartnerDAO)1 ITranslatableString (de.metas.i18n.ITranslatableString)1 CountryId (de.metas.location.CountryId)1 CurrencyId (de.metas.money.CurrencyId)1 PriceListVersionId (de.metas.pricing.PriceListVersionId)1 PriceSpecificationType (de.metas.pricing.conditions.PriceSpecificationType)1 IPriceListDAO (de.metas.pricing.service.IPriceListDAO)1 RelatedProcessDescriptor (de.metas.process.RelatedProcessDescriptor)1 PartialPriceChangeBuilder (de.metas.ui.web.order.pricingconditions.view.PricingConditionsRowChangeRequest.PartialPriceChange.PartialPriceChangeBuilder)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