pub fn interpolate(
transaction: &Transaction,
) -> Result<InterpolationResult, InterpolationError>Expand description
Interpolate missing amounts in a transaction.
This function:
- Identifies postings with missing amounts
- For each currency, calculates the residual
- Fills in the missing amount to balance
§Rules
- At most one posting per currency can have a missing amount
- If a posting has a cost spec with a currency, that currency is used
- Otherwise, the posting gets the residual that makes the transaction balance
§TLA+ Specification
Implements invariants from Interpolation.tla:
AtMostOneNull: At most one posting per currency can have a missing amount (returnsMultipleMissingerror if violated)CompleteImpliesBalanced: After interpolation,sum(postings) = 0for each currencyHasNullAccurate:filled_indicescontains exactly the indices of postings that were originally missing amounts
See: spec/tla/Interpolation.tla
§Example
ⓘ
let txn = Transaction::new(date, "Test")
.with_posting(Posting::new("Expenses:Food", Amount::new(dec!(50.00), "USD")))
.with_posting(Posting::auto("Assets:Cash"));
let result = interpolate(&txn)?;
// Assets:Cash now has -50.00 USD