按顺序结算多笔现金应收

This commit is contained in:
boris
2026-08-25 15:25:18 +08:00
parent e368bad7e4
commit 2574b9375d
3 changed files with 35 additions and 19 deletions
+21 -5
View File
@@ -49,14 +49,30 @@ fn portfolio_settles_cash_receivable_on_payable_date() {
amount: 500.0,
reason: "cash_dividend 0.5".to_string(),
});
portfolio.add_cash_receivable(CashReceivable {
symbol: "000002.SZ".to_string(),
ex_date: d(2025, 1, 2),
payable_date: d(2025, 1, 5),
amount: 250.0,
reason: "cash_dividend 0.25".to_string(),
});
let settled_early = portfolio.settle_cash_receivables(d(2025, 1, 4));
assert!(settled_early.is_empty());
let due_early = portfolio.take_due_cash_receivables(d(2025, 1, 4));
assert!(due_early.is_empty());
assert!((portfolio.cash() - 1_000_000.0).abs() < 1e-9);
let settled = portfolio.settle_cash_receivables(d(2025, 1, 5));
assert_eq!(settled.len(), 1);
assert!((portfolio.cash() - 1_000_500.0).abs() < 1e-9);
let due = portfolio.take_due_cash_receivables(d(2025, 1, 5));
assert_eq!(due.len(), 2);
let mut cash_chain = Vec::new();
for receivable in &due {
let cash_before = portfolio.cash();
portfolio.settle_cash_receivable(receivable).unwrap();
cash_chain.push((cash_before, portfolio.cash()));
}
assert_eq!(
cash_chain,
vec![(1_000_000.0, 1_000_500.0), (1_000_500.0, 1_000_750.0)]
);
assert!(portfolio.cash_receivables().is_empty());
}