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:
hermes 2026-10-18 05:34:29 +00:00
commit ae7a1e2b5c
2 changed files with 36 additions and 12 deletions

View file

@ -978,18 +978,22 @@ pub fn print_broker_summary(summary: &BrokerSummary) -> Result<(), IdxError> {
}
println!("{table}");
let mut totals = format!(
"Total {} IDR, {} 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 summary.total_value.is_some() {
let mut totals = format!(
"Total {} IDR, {} 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(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 [
(BrokerKind::Foreign, "Foreign brokers"),
(BrokerKind::StateOwned, "State-owned brokers"),

View file

@ -2495,7 +2495,27 @@ fn broker_summary_json_names_brokers_and_keeps_source_totals() {
assert_eq!(filtered["investor"], "foreign");
assert_eq!(filtered["board"], "regular");
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]