generated from coulomb/repo-seed
Fix cumulative platform cost Stripe double-counting
Split infrastructure vs payment-processing costs. Liquidity burn now uses infrastructure cash out only (€1,155.20 cumulative) because Stripe fees are already deducted from net member payments. Total platform cost (€1,158.24) remains visible for gross-margin economics.
This commit is contained in:
@@ -112,22 +112,29 @@ def build_liquidity_summary(
|
||||
cost_by_period = {item.period: item for item in monthly_costs}
|
||||
|
||||
cumulative_payments = Decimal("0")
|
||||
cumulative_cost = Decimal("0")
|
||||
cumulative_infrastructure = Decimal("0")
|
||||
cumulative_processing = Decimal("0")
|
||||
for period in tracked:
|
||||
month = cost_by_period[period]
|
||||
cumulative_cost += month.platform_cost
|
||||
cumulative_infrastructure += month.infrastructure_cost
|
||||
cumulative_processing += month.payment_processing_cost
|
||||
payment = revenue_for_period(period, revenue_entries)
|
||||
cumulative_payments += payment.net_amount if payment else Decimal("0")
|
||||
|
||||
cumulative_net = _quantize(cumulative_payments - cumulative_cost)
|
||||
# Liquidity uses net member payments vs infrastructure cash out only.
|
||||
# Payment-processing fees are already deducted from net payments.
|
||||
cumulative_net = _quantize(cumulative_payments - cumulative_infrastructure)
|
||||
remaining = _quantize(budget.initial_budget + cumulative_net)
|
||||
cumulative_total = _quantize(cumulative_infrastructure + cumulative_processing)
|
||||
|
||||
return LiquiditySummary(
|
||||
currency=budget.currency,
|
||||
through_period=through_period,
|
||||
initial_budget=budget.initial_budget,
|
||||
cumulative_member_payments=_quantize(cumulative_payments),
|
||||
cumulative_platform_cost=_quantize(cumulative_cost),
|
||||
cumulative_infrastructure_cost=_quantize(cumulative_infrastructure),
|
||||
cumulative_payment_processing_cost=_quantize(cumulative_processing),
|
||||
cumulative_total_platform_cost=cumulative_total,
|
||||
cumulative_net_liquidity=cumulative_net,
|
||||
remaining_budget=remaining,
|
||||
liquidity_status=liquidity_status_for(cumulative_net),
|
||||
@@ -148,22 +155,26 @@ def build_snapshot(
|
||||
gross_revenue, net_revenue, revenue_source = estimate_monthly_revenue(
|
||||
period, product, models, members, revenue_entries, monthly_costs
|
||||
)
|
||||
platform_cost = month.platform_cost
|
||||
cost_per_member = _quantize(platform_cost / count) if count else Decimal("0.00")
|
||||
gross_margin = _quantize(gross_revenue - platform_cost)
|
||||
infrastructure = month.infrastructure_cost
|
||||
processing = month.payment_processing_cost
|
||||
total_platform = month.total_platform_cost
|
||||
cost_per_member = _quantize(total_platform / count) if count else Decimal("0.00")
|
||||
gross_margin = _quantize(gross_revenue - total_platform)
|
||||
margin_pct = (
|
||||
_quantize((gross_margin / gross_revenue) * Decimal("100"), PCTPLACES)
|
||||
if gross_revenue
|
||||
else Decimal("-100.0") if platform_cost else Decimal("0.0")
|
||||
else Decimal("-100.0") if total_platform else Decimal("0.0")
|
||||
)
|
||||
period_net = _quantize(net_revenue - platform_cost)
|
||||
period_net = _quantize(net_revenue - infrastructure)
|
||||
|
||||
return EconomicsSnapshot(
|
||||
period=period,
|
||||
currency=product.currency,
|
||||
active_members=count,
|
||||
monthly_revenue=_quantize(gross_revenue),
|
||||
monthly_platform_cost=platform_cost,
|
||||
monthly_infrastructure_cost=infrastructure,
|
||||
monthly_payment_processing_cost=processing,
|
||||
monthly_total_platform_cost=total_platform,
|
||||
cost_per_member=cost_per_member,
|
||||
gross_margin=gross_margin,
|
||||
gross_margin_pct=margin_pct,
|
||||
|
||||
Reference in New Issue
Block a user