carlos / platform Public

economics bill: say what a hand-entered bill covers

The console form, POST /api/economics/bill and `carlos economics bill
--basis` take an optional basis, account or whole, stored as written. An
absent basis is account when the console declares the AWS account
CARLOS-only, otherwise unstated; anything else is refused with a 400 and
nothing is written. A manual bill marked whole stays out of the CARLOS
platform cost even on a CARLOS-only console. The CLI prints the stored
basis.

The Economics bill-entry form is rebuilt with Rastrillo field markup
(month and total on one row, the basis select, the services textarea),
its select starting on the option that matches the scope, capped at
34rem by one ops.css rule. The old no-bill note becomes the approved C8
line. Census: root envelope re-pinned, no unit changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 69a0a1d8a12474e51e2db333b500bdbf6c09b6e6 parent bdca8d8
11 files changed, +345 −24
  • docs/site/cli.md +1 −1
  • docs/superpowers/notes/census-claims-billing-dash-3-cost.tsv +4 −0
  • docs/superpowers/notes/census-proposal-billing-dash-3-cost.md +1 −1
  • economics.go +30 −4
  • economics_test.go +71 −4
  • internal/console/economicsbill_test.go +163 −0
  • internal/console/economicspass.go +37 −0
  • internal/console/economicsview.go +10 −0
  • internal/console/static/ops.css +6 −2
  • internal/console/templates/economics.html +20 −11
  • internal/provision/testdata/plan14-root-reads-billing-dash-3-cost.tsv +2 −1

CI cancelled — superseded by a newer push — run details

diff --git a/docs/site/cli.md b/docs/site/cli.md
index 47bb82809..0019cb102 100644
--- a/docs/site/cli.md
+++ b/docs/site/cli.md
@@ -2692,7 +2692,7 @@ Records one month's AWS bill so the console's economics dashboard has a real
number to divide by.
```sh
-carlos economics bill --month 2026-08 --total 412.55 --line AmazonEC2=55.00
+carlos economics bill --month 2026-08 --total 412.55 --line AmazonEC2=55.00 --basis account
```
Operator only, and the console answers everyone else with the same bare 404
diff --git a/docs/superpowers/notes/census-claims-billing-dash-3-cost.tsv b/docs/superpowers/notes/census-claims-billing-dash-3-cost.tsv
index 98be6003e..b285c778e 100644
--- a/docs/superpowers/notes/census-claims-billing-dash-3-cost.tsv
+++ b/docs/superpowers/notes/census-claims-billing-dash-3-cost.tsv
@@ -1,3 +1,7 @@
# Billing dashboard Plan 3 (branch billing-dash-3-cost). One line per changed root-read unit: <file>:<unit><TAB><what changed>.
# Task 1 changes no unit; it re-pins the internal/economics envelope only, which census-propose takes without a claim. The brief's claim, kept here for the reviewer:
# internal/economics/bill.go:Bill: one additive string field and two consts; no read added
+# Task 4 changes no unit; it re-pins the root (.) envelope only. The brief's claims, kept here for the reviewer:
+# economics.go:economicsBill: request gains optional basis; no read added
+# economics.go:runEconomicsBill: request gains optional basis; no read added
+# economics.go:economicsBillResult: request gains optional basis; no read added
diff --git a/docs/superpowers/notes/census-proposal-billing-dash-3-cost.md b/docs/superpowers/notes/census-proposal-billing-dash-3-cost.md
index ec1460c35..073ad7bd1 100644
--- a/docs/superpowers/notes/census-proposal-billing-dash-3-cost.md
+++ b/docs/superpowers/notes/census-proposal-billing-dash-3-cost.md
@@ -2,7 +2,7 @@
Ruling `census-ruling-billing-dash-3-cost`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
-Envelopes re-pinned: `internal/economics`.
+Envelopes re-pinned: `.`, `internal/economics`.
Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner.
diff --git a/economics.go b/economics.go
index 2129431bb..67facaa99 100644
--- a/economics.go
+++ b/economics.go
@@ -28,7 +28,7 @@ import (
"time"
)
-const economicsUsage = `usage: carlos economics bill --month <YYYY-MM> --total <usd> [--line Service=usd ...] [--console <origin>]
+const economicsUsage = `usage: carlos economics bill --month <YYYY-MM> --total <usd> [--line Service=usd ...] [--basis account|whole] [--console <origin>]
carlos economics backhaul [--period mtd|last|7d] [--console <origin>]
Records one month's AWS bill for the economics dashboard. Operator only: the
@@ -40,6 +40,18 @@ A manual entry always overwrites whatever the console already holds for that
month — a previous Cost Explorer pull or an earlier manual entry alike.
`
+// validBillBasis accepts what --basis may say: account, whole, or nothing
+// (the console then stamps the bill from its own CostScope). It is checked
+// here so a typo stops before any request is built; the console refuses
+// the same values with the same words.
+func validBillBasis(s string) error {
+ switch s {
+ case "", "account", "whole":
+ return nil
+ }
+ return errors.New("basis must be account or whole")
+}
+
// serviceLines is a repeatable -line Service=usd flag collector
// (flag.Value): every -line adds one entry to the map, the way a single
// map-typed flag cannot — flag.NewFlagSet has no MapVar, only Var, which
@@ -234,6 +246,9 @@ type economicsBillResult struct {
TotalUSD float64 `json:"total_usd"`
Services map[string]float64 `json:"services"`
Source string `json:"source"`
+ // Basis is what the stored bill covers: account, whole, or "" when it
+ // is unstated (or the console predates the field).
+ Basis string `json:"basis,omitempty"`
}
// economicsBill posts one month's manual bill entry to the console
@@ -247,12 +262,16 @@ type economicsBillResult struct {
// ("check --account and --app") does not fit here at all (this door has
// neither flag), so this is the one call in the package that writes its own
// 404 message rather than reusing it.
-func (s *apiSession) economicsBill(ctx context.Context, month string, total float64, services map[string]float64) (economicsBillResult, error) {
+//
+// basis "" sends no basis key at all, so an older console sees exactly the
+// body it always did.
+func (s *apiSession) economicsBill(ctx context.Context, month string, total float64, services map[string]float64, basis string) (economicsBillResult, error) {
in := struct {
Month string `json:"month"`
TotalUSD float64 `json:"total_usd"`
Services map[string]float64 `json:"services,omitempty"`
- }{month, total, services}
+ Basis string `json:"basis,omitempty"`
+ }{month, total, services, basis}
status, body, err := s.postJSON(ctx, "/api/economics/bill", in)
if err != nil {
return economicsBillResult{}, err
@@ -278,6 +297,7 @@ func runEconomicsBill(args []string) {
total := fs.Float64("total", 0, "invoice total in US dollars (required)")
lines := serviceLines{}
fs.Var(lines, "line", "one line item, repeatable: Service=usd")
+ basis := fs.String("basis", "", "what the total covers: account (the whole account, which runs only CARLOS) or whole (the whole account, CARLOS and other things)")
consoleFlag := consoleOption(fs, "console to record through (default: the only logged-in one)")
fs.Usage = flagUsage(fs, economicsUsage)
fs.Parse(args)
@@ -293,6 +313,9 @@ func runEconomicsBill(args []string) {
if err := validAmount(*total); err != nil {
log.Fatalf("economics bill: --total %v", err)
}
+ if err := validBillBasis(*basis); err != nil {
+ log.Fatalf("economics bill: --%v", err)
+ }
sess, err := resolveMode(*consoleFlag)
if err != nil {
@@ -305,7 +328,7 @@ func runEconomicsBill(args []string) {
}
printUsing(stdout, sess)
- res, err := sess.economicsBill(context.Background(), *month, *total, map[string]float64(lines))
+ res, err := sess.economicsBill(context.Background(), *month, *total, map[string]float64(lines), *basis)
if err != nil {
log.Fatalf("economics bill: %v", err)
}
@@ -324,4 +347,7 @@ func runEconomicsBill(args []string) {
w.Flush()
}
fmt.Fprintf(stdout, "%s %s: $%.2f\n", colorFor(stdout).ok("recorded bill for"), res.Month, res.TotalUSD)
+ if res.Basis != "" {
+ fmt.Fprintf(stdout, "basis: %s\n", res.Basis)
+ }
}
diff --git a/economics_test.go b/economics_test.go
index 1a087ea9f..ec095fcc9 100644
--- a/economics_test.go
+++ b/economics_test.go
@@ -8,6 +8,7 @@ package main
import (
"context"
"encoding/json"
+ "io"
"math"
"net/http"
"net/http/httptest"
@@ -94,7 +95,7 @@ func TestAPISessionEconomicsBillWireShape(t *testing.T) {
}))
defer ts.Close()
- res, err := newTestSession(ts.URL).economicsBill(context.Background(), "2026-08", 123.45, map[string]float64{"AmazonEC2": 55.0})
+ res, err := newTestSession(ts.URL).economicsBill(context.Background(), "2026-08", 123.45, map[string]float64{"AmazonEC2": 55.0}, "")
if err != nil {
t.Fatalf("economicsBill: %v", err)
}
@@ -115,6 +116,56 @@ func TestAPISessionEconomicsBillWireShape(t *testing.T) {
}
}
+// TestAPISessionEconomicsBillBasisWireShape: a basis rides as "basis" in
+// the request and comes back in the echoed bill; no basis sends no key at
+// all, so an older console sees exactly the body it always did.
+func TestAPISessionEconomicsBillBasisWireShape(t *testing.T) {
+ for _, tc := range []struct {
+ basis string
+ want string // substring the raw body must carry, "" for none
+ }{
+ {"account", `"basis":"account"`},
+ {"", ""},
+ } {
+ var raw []byte
+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ raw, _ = io.ReadAll(r.Body)
+ out := map[string]any{"month": "2026-08", "total_usd": 1, "source": "manual"}
+ if tc.basis != "" {
+ out["basis"] = tc.basis
+ }
+ json.NewEncoder(w).Encode(out)
+ }))
+ res, err := newTestSession(ts.URL).economicsBill(context.Background(), "2026-08", 1, nil, tc.basis)
+ ts.Close()
+ if err != nil {
+ t.Fatalf("economicsBill(basis %q): %v", tc.basis, err)
+ }
+ if tc.want != "" && !strings.Contains(string(raw), tc.want) {
+ t.Fatalf("basis %q: body %s, want %s", tc.basis, raw, tc.want)
+ }
+ if tc.want == "" && strings.Contains(string(raw), `"basis"`) {
+ t.Fatalf("no basis: body %s carries a basis key", raw)
+ }
+ if res.Basis != tc.basis {
+ t.Fatalf("result basis = %q, want %q", res.Basis, tc.basis)
+ }
+ }
+}
+
+func TestValidBillBasis(t *testing.T) {
+ for _, good := range []string{"", "account", "whole"} {
+ if err := validBillBasis(good); err != nil {
+ t.Errorf("validBillBasis(%q) = %v, want nil", good, err)
+ }
+ }
+ for _, bad := range []string{"tagged", "Account", "bogus", " whole"} {
+ if err := validBillBasis(bad); err == nil {
+ t.Errorf("validBillBasis(%q) = nil, want an error", bad)
+ }
+ }
+}
+
// TestAPISessionEconomicsBillNotFoundNamesOperatorBit: handleAPIEconomicsBill
// answers a non-operator's token with the same bare 404 an unknown route
// gets — notFoundErr's own "-account and -app" text does not fit this
@@ -125,7 +176,7 @@ func TestAPISessionEconomicsBillNotFoundNamesOperatorBit(t *testing.T) {
}))
defer ts.Close()
- _, err := newTestSession(ts.URL).economicsBill(context.Background(), "2026-08", 1, nil)
+ _, err := newTestSession(ts.URL).economicsBill(context.Background(), "2026-08", 1, nil, "")
if err == nil {
t.Fatal("a 404 must error")
}
@@ -147,7 +198,7 @@ func TestAPISessionEconomicsBillServerErrorSurfacesVerbatim(t *testing.T) {
}))
defer ts.Close()
- _, err := newTestSession(ts.URL).economicsBill(context.Background(), "2026-08", 1, nil)
+ _, err := newTestSession(ts.URL).economicsBill(context.Background(), "2026-08", 1, nil, "")
if err == nil || !strings.Contains(err.Error(), "try again") {
t.Fatalf("economicsBill 409 = %v, want the console's own text", err)
}
@@ -205,6 +256,14 @@ func TestEconomicsVerbRefusals(t *testing.T) {
t.Fatalf("bill with no -total = %q, want the usage string", out)
}
+ out, err = run(nil, "economics", "bill", "-month", "2026-08", "-total", "1", "-basis", "tagged")
+ if err == nil {
+ t.Fatalf("bill with --basis tagged exited 0:\n%s", out)
+ }
+ if !strings.Contains(out, "basis must be account or whole") {
+ t.Fatalf("bill with --basis tagged = %q, want the basis refusal", out)
+ }
+
out, err = run(nil, "economics", "bill", "-month", "2026-8", "-total", "1")
if err == nil {
t.Fatalf("bill with a malformed --month exited 0:\n%s", out)
@@ -248,10 +307,15 @@ func TestEconomicsBillCLIHappyPath(t *testing.T) {
http.NotFound(w, r)
return
}
+ var in struct {
+ Basis string `json:"basis"`
+ }
+ json.NewDecoder(r.Body).Decode(&in)
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]any{
"month": "2026-08", "total_usd": 123.45,
"services": map[string]float64{"AmazonEC2": 55.0}, "source": "manual",
+ "basis": in.Basis,
})
}))
defer ts.Close()
@@ -259,7 +323,7 @@ func TestEconomicsBillCLIHappyPath(t *testing.T) {
env := carlosTestEnv(t)
writeTestCredential(t, envSliceValue(env, "CARLOS_CREDENTIALS"), ts.URL)
- cmd := exec.Command(bin, "economics", "bill", "-month", "2026-08", "-total", "123.45", "-line", "AmazonEC2=55.00")
+ cmd := exec.Command(bin, "economics", "bill", "-month", "2026-08", "-total", "123.45", "-line", "AmazonEC2=55.00", "-basis", "whole")
cmd.Env = env
cmd.Dir = scratch
out, err := cmd.CombinedOutput()
@@ -273,6 +337,9 @@ func TestEconomicsBillCLIHappyPath(t *testing.T) {
if !strings.Contains(got, "123.45") {
t.Fatalf("stdout = %q, want the total", got)
}
+ if !strings.Contains(got, "basis: whole\n") {
+ t.Fatalf("stdout = %q, want the stored basis line", got)
+ }
}
// envSliceValue returns the value of the last occurrence of key=... in env,
diff --git a/internal/console/economicsbill_test.go b/internal/console/economicsbill_test.go
index bcfeea909..cfb3bca63 100644
--- a/internal/console/economicsbill_test.go
+++ b/internal/console/economicsbill_test.go
@@ -567,3 +567,166 @@ func TestBillPassRepullsOnBasisChange(t *testing.T) {
}
})
}
+
+// TestEconomicsBillBasisDoors: both manual-bill doors (the console form and
+// the CLI's API) store the basis the operator gave, default an absent one
+// from the console's CostScope, and refuse anything else without writing.
+func TestEconomicsBillBasisDoors(t *testing.T) {
+ ctx := context.Background()
+ carlosOnly := CostScope{AccountCarlosOnly: true}
+ for _, tc := range []struct {
+ name string
+ scope CostScope
+ basis string // "-" sends no basis at all
+ want string
+ bad bool
+ }{
+ {"account given", CostScope{}, "account", economics.BasisAccount, false},
+ {"absent, account scope", carlosOnly, "-", economics.BasisAccount, false},
+ {"absent, zero scope", CostScope{}, "-", economics.BasisUnstated, false},
+ {"whole, account scope", carlosOnly, "whole", economics.BasisWhole, false},
+ {"tagged refused", carlosOnly, "tagged", "", true},
+ {"bogus refused", CostScope{}, "bogus", "", true},
+ } {
+ for _, door := range []string{"form", "api"} {
+ t.Run(door+"/"+tc.name, func(t *testing.T) {
+ fx := newConsoleFixture(t)
+ fx.srv.cfg.CostScope = tc.scope
+ if err := fx.st.SetOperator("paul@keymail.dev", true); err != nil {
+ t.Fatal(err)
+ }
+ var status int
+ var body string
+ switch door {
+ case "form":
+ c := signInPaul(t, fx)
+ form := url.Values{"csrf": {sessionToken(t, fx, c)}, "month": {"2026-08"}, "total": {"12.5"}, "lines": {"AmazonEC2=12.5"}}
+ if tc.basis != "-" {
+ form.Set("basis", tc.basis)
+ }
+ status, _, body = postForm(t, c, fx.ts.URL+"/fleet/economics/bill", form)
+ case "api":
+ token := cliToken(t, fx, "paul@keymail.dev", "code-basis")
+ req := map[string]any{"month": "2026-08", "total_usd": 12.5, "services": map[string]float64{"AmazonEC2": 12.5}}
+ if tc.basis != "-" {
+ req["basis"] = tc.basis
+ }
+ raw, err := json.Marshal(req)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var out []byte
+ status, out = postBody(t, fx.ts.URL+"/api/economics/bill", token, string(raw))
+ body = string(out)
+ }
+ if tc.bad {
+ if status != http.StatusBadRequest {
+ t.Fatalf("basis %q = %d %s, want 400", tc.basis, status, body)
+ }
+ if door == "api" && !jsonErrorContains(t, body, "basis must be account or whole") {
+ t.Fatalf("api 400 body = %s, want %q", body, "basis must be account or whole")
+ }
+ if _, _, err := fx.rel.Get(ctx, economics.BillKey("2026-08")); !errors.Is(err, os.ErrNotExist) {
+ t.Fatalf("a refused basis still wrote a bill (err %v)", err)
+ }
+ return
+ }
+ if door == "form" && status != http.StatusSeeOther {
+ t.Fatalf("form save = %d %s, want 303", status, body)
+ }
+ if door == "api" && status != http.StatusOK {
+ t.Fatalf("api save = %d %s, want 200", status, body)
+ }
+ raw, b := readBillRaw(t, fx, "2026-08")
+ if b.Basis != tc.want {
+ t.Fatalf("stored basis = %q, want %q", b.Basis, tc.want)
+ }
+ if tc.want == economics.BasisUnstated && strings.Contains(string(raw), `"basis"`) {
+ t.Fatalf("unstated manual bill carries a basis key: %s", raw)
+ }
+ })
+ }
+ }
+}
+
+// TestManualWholeBillStaysExcluded: a hand-entered bill marked "whole" on a
+// console that declares the account CARLOS-only is never counted as CARLOS
+// platform cost; only an absent basis is promoted by the setting.
+func TestManualWholeBillStaysExcluded(t *testing.T) {
+ ctx := context.Background()
+ for _, door := range []string{"form", "api"} {
+ t.Run(door, func(t *testing.T) {
+ fx := newConsoleFixture(t)
+ fx.srv.cfg.CostScope = CostScope{AccountCarlosOnly: true}
+ if err := fx.st.SetOperator("paul@keymail.dev", true); err != nil {
+ t.Fatal(err)
+ }
+ switch door {
+ case "form":
+ c := signInPaul(t, fx)
+ form := url.Values{"csrf": {sessionToken(t, fx, c)}, "month": {"2026-10"}, "total": {"300"}, "lines": {"AmazonEC2=300"}, "basis": {"whole"}}
+ if status, _, body := postForm(t, c, fx.ts.URL+"/fleet/economics/bill", form); status != http.StatusSeeOther {
+ t.Fatalf("form save = %d %s", status, body)
+ }
+ case "api":
+ token := cliToken(t, fx, "paul@keymail.dev", "code-whole")
+ body := `{"month":"2026-10","total_usd":300,"services":{"AmazonEC2":300},"basis":"whole"}`
+ if status, out := postBody(t, fx.ts.URL+"/api/economics/bill", token, body); status != http.StatusOK {
+ t.Fatalf("api save = %d %s", status, out)
+ }
+ }
+ usd, basis, ok := fx.srv.carlosPlatformCostUSD(ctx, "2026-10")
+ if ok || basis != economics.BasisWhole {
+ t.Fatalf("carlosPlatformCostUSD = %v, %q, %v; want ok=false, basis whole", usd, basis, ok)
+ }
+ })
+ }
+}
+
+// TestEconomicsBillFormBasisDefault: with no bill on file the Economics page
+// offers the bill-entry form, whose "what this bill covers" select starts
+// on the option that matches the console's CostScope.
+func TestEconomicsBillFormBasisDefault(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ scope CostScope
+ selected string
+ }{
+ {"account scope", CostScope{AccountCarlosOnly: true}, "account"},
+ {"zero scope", CostScope{}, "whole"},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ fx := newConsoleFixture(t)
+ fx.srv.cfg.CostScope = tc.scope
+ c := signInPaul(t, fx)
+ if err := fx.st.SetOperator("paul@keymail.dev", true); err != nil {
+ t.Fatal(err)
+ }
+ status, _, body := get(t, c, fx.ts.URL+"/fleet/economics")
+ if status != http.StatusOK {
+ t.Fatalf("/fleet/economics = %d", status)
+ }
+ for _, want := range []string{
+ "No AWS bill on file for ",
+ " yet. Enter it below.",
+ `<form rst-card co-pad co-billform method="post" action="/fleet/economics/bill">`,
+ `<label rst-field-label for="bill-basis">What this bill covers</label>`,
+ `<option value="` + tc.selected + `" selected>`,
+ "The whole account, which runs only CARLOS",
+ "The whole account, CARLOS and other things",
+ } {
+ if !strings.Contains(body, want) {
+ t.Fatalf("/fleet/economics missing %q", want)
+ }
+ }
+ if strings.Contains(body, "enter one manually") {
+ t.Fatal("the old no-bill note is still on the page")
+ }
+ _, sel, _ := strings.Cut(body, `id="bill-basis"`)
+ sel, _, _ = strings.Cut(sel, "</select>")
+ if n := strings.Count(sel, " selected>"); n != 1 {
+ t.Fatalf("%d selected bill-basis options, want 1: %s", n, sel)
+ }
+ })
+ }
+}
diff --git a/internal/console/economicspass.go b/internal/console/economicspass.go
index 5f29fa84a..0108dd95c 100644
--- a/internal/console/economicspass.go
+++ b/internal/console/economicspass.go
@@ -1398,6 +1398,30 @@ func parseBillLines(text string) (map[string]float64, error) {
return services, nil
}
+// errManualBillBasis is both manual-bill doors' refusal of a basis other
+// than account or whole. "tagged" is refused too: it is a value a later
+// version may write, never one an operator types today.
+var errManualBillBasis = errors.New("basis must be account or whole")
+
+// manualBillBasis is the stored basis for a hand-entered bill. An explicit
+// account or whole is stored as written, whatever the console's CostScope
+// says. An absent basis (an older CLI, a form without the field) is
+// account when the account is declared CARLOS-only and otherwise left
+// unstated, the same stamp billBasisFor gives a pulled bill.
+func (s *Server) manualBillBasis(raw string) (string, error) {
+ switch raw {
+ case "":
+ if s.cfg.CostScope.AccountCarlosOnly {
+ return economics.BasisAccount, nil
+ }
+ return economics.BasisUnstated, nil
+ case economics.BasisAccount, economics.BasisWhole:
+ return raw, nil
+ default:
+ return "", errManualBillBasis
+ }
+}
+
// handleEconomicsBillSave writes a manually-entered bill for one month —
// SourceManual, always overwriting whatever is there (upsertBill's
// manualWins=false). Same gate shape as handleEconomicsScenarioSave,
@@ -1447,6 +1471,11 @@ func (s *Server) handleEconomicsBillSave(w http.ResponseWriter, r *http.Request)
s.renderMessage(w, r, http.StatusBadRequest, "Invalid bill", err.Error())
return
}
+ basis, err := s.manualBillBasis(r.FormValue("basis"))
+ if err != nil {
+ s.renderMessage(w, r, http.StatusBadRequest, "Invalid bill", err.Error())
+ return
+ }
bill := economics.Bill{
Schema: 1,
@@ -1454,6 +1483,7 @@ func (s *Server) handleEconomicsBillSave(w http.ResponseWriter, r *http.Request)
TotalUSD: total,
Services: services,
Source: economics.SourceManual,
+ Basis: basis,
}
if err := s.upsertBill(r.Context(), bill, false); err != nil {
if errors.Is(err, release.ErrCASConflict) {
@@ -1580,6 +1610,7 @@ func (s *Server) handleAPIEconomicsBill(w http.ResponseWriter, r *http.Request)
Month string `json:"month"`
TotalUSD float64 `json:"total_usd"`
Services map[string]float64 `json:"services"`
+ Basis string `json:"basis,omitempty"`
}
if !readJSON(w, r, &req) {
return
@@ -1588,6 +1619,11 @@ func (s *Server) handleAPIEconomicsBill(w http.ResponseWriter, r *http.Request)
jsonError(w, http.StatusBadRequest, "month must be formatted YYYY-MM")
return
}
+ basis, err := s.manualBillBasis(req.Basis)
+ if err != nil {
+ jsonError(w, http.StatusBadRequest, err.Error())
+ return
+ }
bill := economics.Bill{
Schema: 1,
@@ -1595,6 +1631,7 @@ func (s *Server) handleAPIEconomicsBill(w http.ResponseWriter, r *http.Request)
TotalUSD: req.TotalUSD,
Services: req.Services,
Source: economics.SourceManual,
+ Basis: basis,
}
if err := s.upsertBill(r.Context(), bill, false); err != nil {
if errors.Is(err, release.ErrCASConflict) {
diff --git a/internal/console/economicsview.go b/internal/console/economicsview.go
index cdcf18fdd..14a17fa22 100644
--- a/internal/console/economicsview.go
+++ b/internal/console/economicsview.go
@@ -106,6 +106,10 @@ type EconomicsView struct {
// read-only, like Bills; see copyEconomicsView.
BillBasisLabels map[string]string
BillBasisHints map[string]string
+ // BillFormBasis is the option the bill-entry form's "what this bill
+ // covers" select starts on: account when the console declares the AWS
+ // account CARLOS-only, otherwise whole.
+ BillFormBasis string
}
// PoolLedger is one period's fleet-pool revenue-sharing standing: how much
@@ -663,6 +667,11 @@ func (s *Server) buildEconomicsView(ctx context.Context, period string) (*Econom
}
}
+ billFormBasis := economics.BasisWhole
+ if s.cfg.CostScope.AccountCarlosOnly {
+ billFormBasis = economics.BasisAccount
+ }
+
payload := economicsPayload{
Scenario: sc,
Meters: meters,
@@ -701,6 +710,7 @@ func (s *Server) buildEconomicsView(ctx context.Context, period string) (*Econom
Pool: pool,
BillBasisLabels: billBasisLabels,
BillBasisHints: billBasisHints,
+ BillFormBasis: billFormBasis,
}, nil
}
diff --git a/internal/console/static/ops.css b/internal/console/static/ops.css
index 6ba6babb4..5c02b4144 100644
--- a/internal/console/static/ops.css
+++ b/internal/console/static/ops.css
@@ -205,8 +205,8 @@
economics knob drawer's parts. */
[co-h3] { font-size: var(--rst-fs-base); margin: var(--rst-sp-5) 0 var(--rst-sp-2); }
-/* The economics knob drawer and the bill form: one row per number, its
- label then its control. The drawer is a card that opens. */
+/* The economics knob drawer: one row per number, its label then its
+ control. The drawer is a card that opens. */
[co-knobs] > summary { cursor: pointer; font-weight: 600; }
[co-knobs] > summary + * { margin-block-start: var(--rst-sp-4); }
[co-knob] { align-items: center; display: flex; flex-wrap: wrap; gap: var(--rst-sp-2) var(--rst-sp-3); margin: 0 0 var(--rst-sp-2); }
@@ -216,6 +216,10 @@
[co-knobs] [rst-textarea] { max-inline-size: 32rem; }
[co-knobs] .co-table-wrap { border: 1px solid var(--rst-line); border-radius: var(--rst-radius-sm); }
+/* The economics bill-entry form: Rastrillo fields, kept to a readable
+ width. */
+[co-billform] { max-inline-size: 34rem; }
+
/* The economics accounts page's tier form, under the tier's pill. */
[co-tier] { align-items: center; display: flex; flex-wrap: wrap; gap: var(--rst-sp-2); margin-block-start: var(--rst-sp-2); }
[co-tier] [rst-input] { font-size: var(--rst-fs-sm); inline-size: auto; min-block-size: 0; padding: 0.2rem 0.4rem; }
diff --git a/internal/console/templates/economics.html b/internal/console/templates/economics.html
index 7fb737a62..675f25a0c 100644
--- a/internal/console/templates/economics.html
+++ b/internal/console/templates/economics.html
@@ -224,21 +224,30 @@
{{with index .Economics.BillBasisHints $curBill.Month}}<p co-note>{{.}}</p>{{end}}
<p>Delta, bill minus model: <strong id="breakdown-delta">{{usd $delta}}</strong></p>
{{else}}
-<p co-note>No bill on file for {{periodMonth .Economics.Period}} — enter one manually.</p>
-<form rst-card co-pad co-knobs method="post" action="/fleet/economics/bill">
+<p co-note>{{printf "No AWS bill on file for %s yet. Enter it below." (periodMonth .Economics.Period)}}</p>
+<form rst-card co-pad co-billform method="post" action="/fleet/economics/bill">
<input type="hidden" name="csrf" value="{{.CSRF}}">
- <div co-knob>
- <label for="bill-month">Month</label>
- <input rst-input type="text" id="bill-month" name="month" pattern="\d{4}-\d{2}" value="{{periodMonth .Economics.Period}}" required>
+ <div rst-field-row>
+ <div rst-field>
+ <label rst-field-label for="bill-month">Month</label>
+ <input rst-input type="text" id="bill-month" name="month" pattern="\d{4}-\d{2}" value="{{periodMonth .Economics.Period}}" size="8" required>
+ </div>
+ <div rst-field class="rst-grow">
+ <label rst-field-label for="bill-total">Total USD</label>
+ <input rst-input type="number" step="0.01" min="0" id="bill-total" name="total" required>
+ </div>
</div>
- <div co-knob>
- <label for="bill-total">Total USD</label>
- <input rst-input type="number" step="0.01" min="0" id="bill-total" name="total" required>
+ <div rst-field>
+ <label rst-field-label for="bill-basis">What this bill covers</label>
+ <select rst-input id="bill-basis" name="basis">
+ <option value="account"{{if eq .Economics.BillFormBasis "account"}} selected{{end}}>The whole account, which runs only CARLOS</option>
+ <option value="whole"{{if eq .Economics.BillFormBasis "whole"}} selected{{end}}>The whole account, CARLOS and other things</option>
+ </select>
</div>
- <div co-knob>
- <label for="bill-lines">Services, one "Service=USD" per line</label>
+ <div rst-field>
+ <label rst-field-label for="bill-lines">Services, one "Service=USD" per line</label>
+ <textarea rst-textarea id="bill-lines" name="lines" rows="5" placeholder="EC2=120.50&#10;S3=42.10"></textarea>
</div>
- <p><textarea rst-textarea id="bill-lines" name="lines" rows="6" cols="48" placeholder="EC2=120.50&#10;S3=42.10"></textarea></p>
<button rst-btn type="submit">Save bill</button>
</form>
{{end}}
diff --git a/internal/provision/testdata/plan14-root-reads-billing-dash-3-cost.tsv b/internal/provision/testdata/plan14-root-reads-billing-dash-3-cost.tsv
index da7df45f8..55c76952d 100644
--- a/internal/provision/testdata/plan14-root-reads-billing-dash-3-cost.tsv
+++ b/internal/provision/testdata/plan14-root-reads-billing-dash-3-cost.tsv
@@ -1,3 +1,4 @@
# Census overlay billing-dash-3-cost, written by census-propose (#369). census-ruling-billing-dash-3-cost, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-billing-dash-3-cost.md.
-# 0 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+# 0 body, 0 sites, 2 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+@coverage . 95c19a4b0a5a61ce3be1bf698c849e60d29f5fecf085e8d0cc6fea30ce3ac8ed
@coverage internal/economics 2c7a25baab91215d83101249e4966e37781b06f5a4d0ba889c03e88cb465408a