[ledger] Household: profile.named, household.sharing_set, member.named, subscriptions.shared; shared_names sends only service keys; v0.3.0

This commit is contained in:
2026-11-04 16:17:14 +01:00
parent 11a4070151
commit 235f290412
8 changed files with 212 additions and 5 deletions
+15
View File
@@ -1,7 +1,9 @@
//! Household duplicates: two or more members paying for the same service ("You both pay Spotify"). Runs only
//! on the subscription names members chose to share into the household budget.
use crate::subscriptions::{analyse, Status};
use fiscus_ledger::merchant::merchant_key;
use fiscus_ledger::{Date, State};
use serde::Serialize;
use std::collections::{BTreeMap, BTreeSet};
@@ -34,3 +36,16 @@ pub fn household_duplicates(shared: &[(String, Vec<String>)]) -> Vec<Duplicate>
.map(|(key, m)| Duplicate { key, members: m.into_iter().collect() })
.collect()
}
/// What a member who opted in shares: the service key of every subscription they still pay (active, or charged
/// after a cancel), sorted, at most 100. Only the key leaves, never the merchant text with its references.
pub fn shared_names(state: &State, today: Date) -> Vec<String> {
let keys: BTreeSet<String> = analyse(state, today)
.subscriptions
.iter()
.filter(|s| matches!(s.status, Status::Active | Status::ChargedAfterCancel))
.filter_map(|s| service_key(&s.merchant))
.filter(|k| k.chars().count() <= 40)
.collect();
keys.into_iter().take(100).collect()
}