diff --git a/crates/idx-cli/src/output/table.rs b/crates/idx-cli/src/output/table.rs index d24bbe2..641d434 100644 --- a/crates/idx-cli/src/output/table.rs +++ b/crates/idx-cli/src/output/table.rs @@ -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"), diff --git a/crates/idx-cli/tests/cli.rs b/crates/idx-cli/tests/cli.rs index 98c4962..453830c 100644 --- a/crates/idx-cli/tests/cli.rs +++ b/crates/idx-cli/tests/cli.rs @@ -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]