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();
}
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());
}
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();
}
Aggregations