dynamic prices with dicounts

This commit is contained in:
Priec
2026-06-22 08:47:22 +02:00
parent e98c70aa63
commit 262ec1bfdb
3 changed files with 56 additions and 4 deletions

View File

@@ -338,6 +338,38 @@ pub async fn detail_many(
Ok(list.iter().map(|p| detail_for(p, &pc)).collect())
}
/// Effective prices for a whole audience using only the global layers (the
/// per-product sale + audience-assigned profiles + the business baseline), with
/// no specific company's per-company deals. Used by the discounts admin page to
/// preview what each tab's discounts produce. `audience` is "personal" or
/// "business".
pub async fn audience_price_many(
ctx: &AppContext,
list: &[products::Model],
audience: &str,
) -> Result<Vec<PricedProduct>> {
let personal = load_audience(ctx, AUDIENCE_PERSONAL).await?;
let (business, b2b) = if audience == AUDIENCE_BUSINESS {
(
load_audience(ctx, AUDIENCE_BUSINESS).await?,
// A generic company with no per-company profiles/negotiated prices.
Some(B2bContext {
manual: HashMap::new(),
profiles: LoadedProfiles::empty(),
resolutions: HashMap::new(),
}),
)
} else {
(LoadedProfiles::empty(), None)
};
let pc = PricingCtx {
personal,
business,
b2b,
};
Ok(list.iter().map(|p| detail_for(p, &pc).priced()).collect())
}
/// Price one product for `user` (`None` = anonymous/public).
pub async fn price_for(
ctx: &AppContext,