Metrics → Customers: only customers who have spent more than $0

A customer counts when their paid invoices' amount_paid, less refunds,
is above zero. Trials ($0 invoices), fully discounted invoices, only-open
invoices and payments refunded in full no longer put someone on the list.

Also ticks the Market Fetch check in TEST.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-30 12:27:27 -07:00
co-authored by Claude Opus 5.5
parent 5451fe6d63
commit 6f2fbdf63a
5 changed files with 74 additions and 17 deletions
+1 -1
View File
@@ -116,7 +116,7 @@ func TestCustomersPage(t *testing.T) {
s.DB.Exec(`INSERT INTO crm_records (entity, espo_id, name, email, domain, data, synced_at) VALUES ('Account', 'a1', 'Acme', '', 'acme.example', '{}', '')`)
s.DB.Exec(`INSERT INTO stripe_objects (kind, id, customer, data) VALUES ('customer', 'cus_x', 'cus_x', '{"name":"Xco","email":"x@xco.example"}'),
('customer', 'cus_a', 'cus_a', '{"name":"Acme Ltd","email":"pay@acme.example"}')`)
s.DB.Exec(`INSERT INTO stripe_objects (kind, id, customer, status, currency, data) VALUES ('invoice', 'in_1', 'cus_x', 'paid', 'usd', '{}'), ('invoice', 'in_2', 'cus_a', 'paid', 'usd', '{}')`)
s.DB.Exec(`INSERT INTO stripe_objects (kind, id, customer, status, currency, data) VALUES ('invoice', 'in_1', 'cus_x', 'paid', 'usd', '{"amount_paid":1000}'), ('invoice', 'in_2', 'cus_a', 'paid', 'usd', '{"amount_paid":1000}')`)
body := do(h, http.MethodGet, "/metrics/customers", nil, nil).Body.String()
if !strings.Contains(body, "Xco") || strings.Contains(body, "Acme Ltd") {
t.Fatal("the to-fix list should hold only the unmatched customer")
@@ -1,6 +1,6 @@
{{define "content"}}{{with .Data}}{{$d := .}}
<div class="heading"><h1>Customers and the CRM</h1></div>
<p class="lede">Each Stripe customer with billing, matched to its EspoCRM Account: first by a stored ID (a Stripe customer ID in the Account, or an EspoCRM ID in Stripe's metadata), then by email (the Account's, or one of its Contacts'), then by the email's domain (free mail like Gmail doesn't count). Fix what it gets wrong; your choice is kept. Pipeline influence and per-account numbers build on this.</p>
<p class="lede">Each Stripe customer who has spent more than $0 (paid invoices, less refunds; trials and unpaid invoices don't count), matched to its EspoCRM Account: first by a stored ID (a Stripe customer ID in the Account, or an EspoCRM ID in Stripe's metadata), then by email (the Account's, or one of its Contacts'), then by the email's domain (free mail like Gmail doesn't count). Fix what it gets wrong; your choice is kept. Pipeline influence and per-account numbers build on this.</p>
<section class="card">
{{if not .CRMCount}}