mirror of
https://github.com/0xrsydn/idx-cli.git
synced 2026-11-07 09:45:36 +00:00
fix(cli): no totals line for one investor side
A foreign- or domestic-only summary has no totals now, so the table says why instead of printing "Total - IDR". The CLI test checks the nulls and the table. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V3syn2fN2LNo5pvTSqc6eh
This commit is contained in:
parent
860d4daf77
commit
ae7a1e2b5c
2 changed files with 36 additions and 12 deletions
|
|
@ -978,18 +978,22 @@ pub fn print_broker_summary(summary: &BrokerSummary) -> Result<(), IdxError> {
|
||||||
}
|
}
|
||||||
println!("{table}");
|
println!("{table}");
|
||||||
|
|
||||||
let mut totals = format!(
|
if summary.total_value.is_some() {
|
||||||
"Total {} IDR, {} lots",
|
let mut totals = format!(
|
||||||
format_compact_option(summary.total_value),
|
"Total {} IDR, {} lots",
|
||||||
format_compact_option(summary.total_lots)
|
format_compact_option(summary.total_value),
|
||||||
);
|
format_compact_option(summary.total_lots)
|
||||||
if let Some(average) = summary.average_price {
|
);
|
||||||
totals.push_str(&format!(", average {}", format_idr(average)));
|
if let Some(average) = summary.average_price {
|
||||||
|
totals.push_str(&format!(", average {}", format_idr(average)));
|
||||||
|
}
|
||||||
|
if let Some(net) = summary.foreign_net_value {
|
||||||
|
totals.push_str(&format!("; foreign net {:+}", format_compact(net)));
|
||||||
|
}
|
||||||
|
println!("{totals}.");
|
||||||
|
} else if summary.investor != BrokerInvestor::All {
|
||||||
|
println!("No totals: for one investor side the source totals only that side's buying.");
|
||||||
}
|
}
|
||||||
if let Some(net) = summary.foreign_net_value {
|
|
||||||
totals.push_str(&format!("; foreign net {:+}", format_compact(net)));
|
|
||||||
}
|
|
||||||
println!("{totals}.");
|
|
||||||
for (kind, label) in [
|
for (kind, label) in [
|
||||||
(BrokerKind::Foreign, "Foreign brokers"),
|
(BrokerKind::Foreign, "Foreign brokers"),
|
||||||
(BrokerKind::StateOwned, "State-owned brokers"),
|
(BrokerKind::StateOwned, "State-owned brokers"),
|
||||||
|
|
|
||||||
|
|
@ -2495,7 +2495,27 @@ fn broker_summary_json_names_brokers_and_keeps_source_totals() {
|
||||||
assert_eq!(filtered["investor"], "foreign");
|
assert_eq!(filtered["investor"], "foreign");
|
||||||
assert_eq!(filtered["board"], "regular");
|
assert_eq!(filtered["board"], "regular");
|
||||||
assert_eq!(filtered["buyers"][0]["code"], "KZ");
|
assert_eq!(filtered["buyers"][0]["code"], "KZ");
|
||||||
assert!(filtered["foreign_net_value"].is_null());
|
for field in [
|
||||||
|
"total_value",
|
||||||
|
"total_lots",
|
||||||
|
"average_price",
|
||||||
|
"foreign_net_value",
|
||||||
|
] {
|
||||||
|
assert!(filtered[field].is_null(), "{field}: {filtered}");
|
||||||
|
}
|
||||||
|
let table = run_success_stdout(mock_bin("broker-filtered-table").args([
|
||||||
|
"stocks",
|
||||||
|
"broker",
|
||||||
|
"BBCA",
|
||||||
|
"--date",
|
||||||
|
"2026-10-16",
|
||||||
|
"--investor",
|
||||||
|
"foreign",
|
||||||
|
"--board",
|
||||||
|
"regular",
|
||||||
|
]));
|
||||||
|
assert!(!table.contains("Total "), "{table}");
|
||||||
|
assert!(table.contains("No totals"), "{table}");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue