portal: dues sum stacked subscriptions and record for manual members
ci/woodpecker/push/woodpecker Pipeline was canceled

_current_dues took only the newest live order, so evan-prodromou's $5 + $10 monthly
subscriptions displayed as $5. Sum per unit (monthly separate from yearly), never
mixing them. Also snapshot dues BEFORE the manual skip: manual members take no
membership decision, but the panel's Dues column is a read-model of OC truth and
was unreachable for them.
This commit is contained in:
inference-admin committed 2026-11-17 09:17:37 +00:00
1 parent 549a86a48c
commit 9023496e94
1 file changed
+33 -8
+33 -8
View File
@@ -7406,10 +7406,17 @@ def _current_dues(orders: list[dict]) -> tuple[float | None, str | None]:
`totalAmount` adds the buyer's optional Open Collective tip, which never `totalAmount` adds the buyer's optional Open Collective tip, which never
reaches us (the webhook path made this same mistake once — see the reaches us (the webhook path made this same mistake once — see the
comment at the top of this file); comment at the top of this file);
* stacked live subscriptions are summed in their own unit; a monthly and a
yearly subscription are never added together;
* no live recurrence, an unparseable amount, or a non-positive amount → * no live recurrence, an unparseable amount, or a non-positive amount →
(None, None). NEVER guess and NEVER fall back to the $15 allowance. (None, None). NEVER guess and NEVER fall back to the $15 allowance.
""" """
live: list[tuple[str, float, str]] = [] # A member can hold MORE THAN ONE live subscription (evan-prodromou:
# $5/mo + $10/mo, 2026-11-17). Taking the newest order alone understated
# that as $5. Sum per unit, and never mix units: monthly wins if present,
# yearly only when it is all there is.
monthly = 0.0
yearly = 0.0
for o in orders or []: for o in orders or []:
freq = (o.get("frequency") or "").upper() freq = (o.get("frequency") or "").upper()
status = (o.get("status") or "").upper() status = (o.get("status") or "").upper()
@@ -7421,14 +7428,15 @@ def _current_dues(orders: list[dict]) -> tuple[float | None, str | None]:
continue continue
if amt <= 0: if amt <= 0:
continue continue
when = str(o.get("lastChargedAt") or o.get("createdAt") or "") if freq == "MONTHLY":
live.append((when, amt, freq)) monthly += amt
if not live: else:
yearly += amt
if monthly > 0:
return round(monthly, 2), "MONTHLY"
if yearly > 0:
return round(yearly, 2), "YEARLY"
return None, None return None, None
# The most recently charged/created live recurrence is the one in force.
live.sort(key=lambda t: t[0])
_, amt, freq = live[-1]
return round(amt, 2), freq
def _payment_verdict(orders: list[dict], cycle_start: datetime, def _payment_verdict(orders: list[dict], cycle_start: datetime,
@@ -7799,6 +7807,23 @@ async def reconcile_allowances(send: bool = False) -> dict:
counts["skipped"] += 1 counts["skipped"] += 1
continue continue
if member_source(email, conn) == "manual": if member_source(email, conn) == "manual":
# Hand-provisioned: no membership DECISION is taken — but the panel's
# Dues column is a snapshot of OC's own truth, not a decision, so
# record it here before skipping. evan-prodromou pays $15/mo across
# two subscriptions while listed manual; the snapshot used to be
# unreachable for exactly these members.
try:
_dues_a, _dues_f = _current_dues(
by_slug.get((slug or "").strip().lower()) or [])
if "dues_amount" in cols:
conn.execute(
"UPDATE members SET dues_amount = ?, dues_frequency = ?, "
"dues_updated_at = datetime('now') WHERE email = ?",
(_dues_a, _dues_f, email),
)
conn.commit()
except Exception as exc: # noqa: BLE001
logger.warning("Dues snapshot failed for manual member %s: %s", email, exc)
# Hand-provisioned: no OC contribution is expected, so there is # Hand-provisioned: no OC contribution is expected, so there is
# nothing to reconcile. An 'oc-incognito' member is NOT skipped — # nothing to reconcile. An 'oc-incognito' member is NOT skipped —
# their contribution is matched by the slug in row[1] below, which is # their contribution is matched by the slug in row[1] below, which is