use of de.metas.bpartner.BPartnerId in project metasfresh-webui-api by metasfresh.
the class PricingConditionsView_CopyRowToEditable method createChangeRequest.
private PricingConditionsRowChangeRequest createChangeRequest(@NonNull final PricingConditionsRow templateRow) {
final PricingConditionsBreak templatePricingConditionsBreak = templateRow.getPricingConditionsBreak();
PriceSpecification price = templatePricingConditionsBreak.getPriceSpecification();
if (price.isNoPrice()) {
// In case row does not have a price then use BPartner's pricing system
final BPartnerId bpartnerId = templateRow.getBpartnerId();
final SOTrx soTrx = SOTrx.ofBoolean(templateRow.isCustomer());
price = createBasePricingSystemPrice(bpartnerId, soTrx);
}
final Percent discount = templatePricingConditionsBreak.getDiscount();
final PaymentTermId paymentTermIdOrNull = templatePricingConditionsBreak.getPaymentTermIdOrNull();
final Percent paymentDiscountOverrideOrNull = templatePricingConditionsBreak.getPaymentDiscountOverrideOrNull();
return PricingConditionsRowChangeRequest.builder().priceChange(CompletePriceChange.of(price)).discount(discount).paymentTermId(Optional.ofNullable(paymentTermIdOrNull)).paymentDiscount(Optional.ofNullable(paymentDiscountOverrideOrNull)).sourcePricingConditionsBreakId(templatePricingConditionsBreak.getId()).build();
}
use of de.metas.bpartner.BPartnerId 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.bpartner.BPartnerId in project metasfresh-webui-api by metasfresh.
the class PricingConditionsRowsLoader method getPricingConditionsIdByBPartner.
private static final PricingConditionsId getPricingConditionsIdByBPartner(final LookupValue bpartner, final Map<BPartnerId, Integer> discountSchemaIdsByBPartnerId) {
final BPartnerId bpartnerId = BPartnerId.ofRepoId(bpartner.getIdAsInt());
final Integer discountSchemaId = discountSchemaIdsByBPartnerId.get(bpartnerId);
if (discountSchemaId == null) {
return null;
}
return PricingConditionsId.ofRepoId(discountSchemaId);
}
use of de.metas.bpartner.BPartnerId in project metasfresh-webui-api by metasfresh.
the class WebuiHUTransformParametersFiller method retrieveHUPItemProductsForNewTU.
private static LookupValuesList retrieveHUPItemProductsForNewTU(final HUEditorRow cuRow) {
final ProductId productId = cuRow.getProductId();
final BPartnerId bpartnerId = IHandlingUnitsBL.extractBPartnerIdOrNull(cuRow.getM_HU());
return WEBUI_ProcessHelper.retrieveHUPIItemProducts(Env.getCtx(), productId, bpartnerId, // includeVirtualItem = false..moving a cu onto a "virtual" TU makes no sense. Instead, the user can just leave the CU as it is, or take it out of a physical TU
false);
}
use of de.metas.bpartner.BPartnerId in project metasfresh-webui-api by metasfresh.
the class WebuiHUTransformParametersFiller method getDefaultM_HU_PI_Item_Product.
public Optional<I_M_HU_PI_Item_Product> getDefaultM_HU_PI_Item_Product() {
final HUEditorRow cuRow = getSelectedRow();
final ProductId productId = cuRow.getProductId();
final BPartnerId bpartnerId = IHandlingUnitsBL.extractBPartnerIdOrNull(cuRow.getM_HU());
final List<I_M_HU_PI_Item_Product> allPIs = WEBUI_ProcessHelper.retrieveHUPIItemProductRecords(Env.getCtx(), productId, bpartnerId, false);
return allPIs.stream().filter(hu -> hu.isActive() && hu.isDefaultForProduct()).min(Comparator.comparingInt(I_M_HU_PI_Item_Product::getM_HU_PI_Item_Product_ID));
}
Aggregations