console: payments list shows settled amounts beside euro net and fee
A row settled in another currency carries its recorded net and fee in that currency under the euro figure, set in opMoney's format function on both the figure and its inventory copy; eur rows show none. Tests cover a usd row's natives and a taxed refund and its reversal.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+58
−4
internal/console/opbilling.go+20 −4internal/console/opbilling_test.go+38 −0
CI passed — run details
diff --git a/internal/console/opbilling.go b/internal/console/opbilling.go| index 693b00b0c..8989e950e 100644 |
| --- a/internal/console/opbilling.go |
| +++ b/internal/console/opbilling.go |
| @@ -415,10 +415,8 @@ func buildOpBillingPayments(rows []paymentRow, facts []billingFact, total int, i |
| row := opBillingPaymentRowOf(p, byID) |
| row.Charged = opMoney(&v.Figures, name+".charged", in, moneyUse{Inputs: inPayments}, nil, |
| func() string { return minorText(p.Amount, p.Currency) }) |
| - row.Net = opMoney(&v.Figures, name+".net", in, euros, nil, |
| - func() string { return eurText(settledEUR(r, p.Settled-p.SettledTax-p.Fee, cur)) }) |
| - row.Fee = opMoney(&v.Figures, name+".fee", in, euros, nil, |
| - func() string { return eurText(settledEUR(r, p.Fee, cur)) }) |
| + row.Net = opBillingPaymentEUR(&v.Figures, name+".net", in, euros, r, p.Settled-p.SettledTax-p.Fee, cur) |
| + row.Fee = opBillingPaymentEUR(&v.Figures, name+".fee", in, euros, r, p.Fee, cur) |
| converted = converted || cur != "eur" |
| v.Rows = append(v.Rows, row) |
| } |
| @@ -429,6 +427,24 @@ func buildOpBillingPayments(rows []paymentRow, facts []billingFact, total int, i |
| return v |
| } |
| +// opBillingPaymentEUR is one payment's settled amount (minor units of |
| +// currency, lower case) in euros through opMoney. A currency other than |
| +// eur carries the amount as recorded in Native, built in the same format |
| +// function and set on both the returned figure and its copy in *figs; an |
| +// eur amount converted nothing and has none. |
| +func opBillingPaymentEUR(figs *[]opMoneyFigure, name string, in moneyInputs, u moneyUse, r eurRates, minor int64, currency string) opMoneyFigure { |
| + var nat string |
| + f := opMoney(figs, name, in, u, nil, func() string { |
| + if currency != "eur" { |
| + nat = minorText(minor, currency) |
| + } |
| + return eurText(settledEUR(r, minor, currency)) |
| + }) |
| + f.Native = nat |
| + (*figs)[len(*figs)-1].Native = nat |
| + return f |
| +} |
| + |
| // billingPageGate admits an operator's GET on a console with billing on. |
| // The order is operatorOnly first, then the method and the billing switch, |
| // each a plain http.NotFound, so nobody can tell a billing page from a |
diff --git a/internal/console/opbilling_test.go b/internal/console/opbilling_test.go| index 52b0f1606..d9c1e0c59 100644 |
| --- a/internal/console/opbilling_test.go |
| +++ b/internal/console/opbilling_test.go |
| @@ -1319,6 +1319,44 @@ func TestBillingPaymentsGateInvariant(t *testing.T) { |
| if want := [][3]string{{"€29.04", "€23.00", "€1.00"}, {"$11.20", "€9.00", "€1.00"}}; !reflect.DeepEqual(got, want) { |
| t.Errorf("cells = %q, want %q", got, want) |
| } |
| + // The usd row's euro cells carry what settled, in dollars; the eur |
| + // row's converted nothing. The inventory copies agree. |
| + gotNative := [][2]string{} |
| + for _, r := range v.Rows { |
| + gotNative = append(gotNative, [2]string{r.Net.Native, r.Fee.Native}) |
| + } |
| + if want := [][2]string{{"", ""}, {"$10.08", "$1.12"}}; !reflect.DeepEqual(gotNative, want) { |
| + t.Errorf("natives = %q, want %q", gotNative, want) |
| + } |
| + for i, want := range []string{"", "", "", "", "$10.08", "$1.12"} { |
| + if v.Figures[i].Native != want { |
| + t.Errorf("%s inventory native %q, want %q", v.Figures[i].Name, v.Figures[i].Native, want) |
| + } |
| + } |
| + body := renderPayments(t, v) |
| + for _, s := range []string{"<span co-num>€9.00<small co-sub>$10.08</small></span>", "<span co-num>€1.00<small co-sub>$1.12</small></span>", |
| + "<span co-num>€23.00</span>", "<span co-num>$11.20</span>"} { |
| + if !strings.Contains(body, s) { |
| + t.Errorf("page lacks %q", s) |
| + } |
| + } |
| + if strings.Count(body, "<small co-sub>") != 2 { |
| + t.Errorf("%d native lines, want the usd row's two", strings.Count(body, "<small co-sub>")) |
| + } |
| + // A taxed refund and its reversal: net and fee signed as they settled. |
| + refund := pay(billing.PaymentRefund, billing.ReasonOther, time.Date(2026, 11, 4, 0, 0, 0, 0, time.UTC), -2904, -504, 0, "eur") |
| + reversal := pay(billing.PaymentRefund, billing.ReasonReversed, time.Date(2026, 11, 5, 0, 0, 0, 0, time.UTC), 2904, 504, 15, "eur") |
| + rv := paymentsBuild([]paymentRow{reversal, refund}, 2, overviewGood(), "", "", 1) |
| + gotRF := [][4]string{} |
| + for _, r := range rv.Rows { |
| + gotRF = append(gotRF, [4]string{r.What, r.Charged.Text, r.Net.Text, r.Fee.Text}) |
| + } |
| + if want := [][4]string{{billCopyWhatReversed, "€29.04", "€23.85", "€0.15"}, {billCopyWhatRefund, "−€29.04", "−€24.00", "€0.00"}}; !reflect.DeepEqual(gotRF, want) { |
| + t.Errorf("refund and reversal = %q, want %q", gotRF, want) |
| + } |
| + if rv.Rows[0].Status.Label != billCopyStatusPaid || rv.Rows[1].Status.Label != billCopyStatusRefunded { |
| + t.Errorf("statuses %q, %q", rv.Rows[0].Status.Label, rv.Rows[1].Status.Label) |
| + } |
| if want := fmt.Sprintf(billCopyRateNoteLine, "6 Nov 2026"); v.RateNote != want { |
| t.Errorf("rate note %q, want %q", v.RateNote, want) |
| } |