[ledger] Sharing: budget.shared (never the default budget); shared_payment needs an explicit payment.assigned
This commit is contained in:
@@ -157,7 +157,7 @@ pub struct State {
|
||||
pub payments: BTreeMap<PaymentId, PaymentRecord>,
|
||||
pub line_keys: BTreeMap<String, PaymentId>,
|
||||
pub budgets: BTreeMap<BudgetId, Budget>,
|
||||
/// The first budget created: where a payment goes when nobody assigned it.
|
||||
/// The first budget created (never a shared one): where a payment goes when nobody assigned it.
|
||||
pub default_budget: Option<BudgetId>,
|
||||
/// Merchant key → the latest rule for it.
|
||||
pub rules: BTreeMap<String, Rule>,
|
||||
@@ -397,7 +397,7 @@ impl State {
|
||||
EventBody::PaymentTrialMarked { payment, ends } => {
|
||||
self.payment_mut(payment)?.trial_ends = Some(Stamped { seq, value: *ends });
|
||||
}
|
||||
EventBody::BudgetCreated { budget, name, limit } => {
|
||||
EventBody::BudgetCreated { budget, name, limit } | EventBody::BudgetShared { budget, name, limit } => {
|
||||
if budget.is_empty() || self.budgets.contains_key(budget) {
|
||||
return Err("a budget with this id exists");
|
||||
}
|
||||
@@ -409,7 +409,7 @@ impl State {
|
||||
return Err("a limit cannot be negative");
|
||||
}
|
||||
self.budgets.insert(budget.clone(), Budget { id: budget.clone(), name: name.into(), limit: *limit, seq });
|
||||
if self.default_budget.is_none() {
|
||||
if self.default_budget.is_none() && matches!(body, EventBody::BudgetCreated { .. }) {
|
||||
self.default_budget = Some(budget.clone());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user