Inventory: competitor prices, as checked

Each Inventory entry can hold its plans' prices: the plan, the price,
what it's per, when it was checked and where. Comparison and alternative
pages, and new sections, state a competitor's price only as entered,
with the month it was checked; a missing one is left out and listed as a
to-do. A price checked more than six months ago is flagged on the entry
and adds a to-do to every page that names the competitor. Prices go out
and come back with the Inventory's YAML.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-24 08:18:31 -07:00
co-authored by Claude Opus 5.5
parent e0e74af86c
commit f5d87164ac
10 changed files with 357 additions and 4 deletions
+24 -1
View File
@@ -5,6 +5,7 @@ import (
"errors"
"io"
"net/http"
"net/url"
"strconv"
"strings"
"time"
@@ -40,10 +41,14 @@ type entryData struct {
Suggestions []inventory.Suggestion
CanCheck bool // Reddit could be asked about the suggestions
Drafted bool
Today string // for new price rows
Blank []int // empty price rows to show
Stale []inventory.Price // prices due for another look
}
func (s *Server) entryForm(e *inventory.Entry) entryData {
d := entryData{E: e, Relationships: inventory.Relationships, NoAI: !s.aiReady()}
d := entryData{E: e, Relationships: inventory.Relationships, NoAI: !s.aiReady(),
Today: time.Now().Format("2006-01-02"), Blank: []int{0, 1}, Stale: e.StalePrices(time.Now())}
if len(e.Websites) > 0 {
d.DraftURL = e.Websites[0]
}
@@ -111,9 +116,27 @@ func entryFromForm(r *http.Request) *inventory.Entry {
Keywords: profile.Lines(f.Get("keywords")),
TalkingPoints: f.Get("talking_points"),
MentionPolicy: f.Get("mention_policy"),
Prices: pricesFromForm(f),
}
}
// pricesFromForm reads the price rows (price_plan, price_amount… in step).
func pricesFromForm(f url.Values) []inventory.Price {
var out []inventory.Price
amounts := f["price_amount"]
at := func(name string, i int) string {
if v := f[name]; i < len(v) {
return v[i]
}
return ""
}
for i := range amounts {
out = append(out, inventory.Price{Plan: at("price_plan", i), Amount: amounts[i], Per: at("price_per", i),
Checked: at("price_checked", i), Source: at("price_source", i)})
}
return out
}
// inventoryFill fills the form's empty boxes from the entry's website, with
// the AI, and shows the form again, unsaved.
func (s *Server) inventoryFill(w http.ResponseWriter, r *http.Request) {
+34
View File
@@ -0,0 +1,34 @@
package web
import (
"net/http"
"net/url"
"strconv"
"strings"
"testing"
"supermarket/internal/inventory"
)
func TestInventoryPrices(t *testing.T) {
s, h := newTestServer(t, nil)
form := url.Values{"name": {"Zendesk"}, "relationship": {"competitor"}, "mention_policy": {"name"},
"price_plan": {"Suite Team", ""}, "price_amount": {"$55", ""}, "price_per": {"per agent per month", ""},
"price_checked": {"2026-11-20", "2026-11-24"}, "price_source": {"https://zendesk.com/pricing", ""}}
if rec := postForm(h, "/inventory/save", form); rec.Code != http.StatusSeeOther {
t.Fatalf("save: %d %s", rec.Code, rec.Body.String())
}
es, _ := inventory.List(s.DB, "")
if len(es) != 1 || len(es[0].Prices) != 1 || es[0].Prices[0].Amount != "$55" {
t.Fatalf("saved: %+v", es)
}
body := do(h, http.MethodGet, "/inventory/"+strconv.FormatInt(es[0].ID, 10), nil, nil).Body.String()
if !strings.Contains(body, `name="price_amount" value="$55"`) || !strings.Contains(body, "Their prices") {
t.Errorf("edit page: %s", body)
}
form.Set("price_checked", "")
form["price_checked"] = []string{"", ""}
if rec := postForm(h, "/inventory/save", form); !strings.Contains(rec.Body.String(), "say when you checked the price $55") && !strings.Contains(rec.Body.String(), "Say when you checked the price $55") {
t.Errorf("a price without its date was saved: %d", rec.Code)
}
}
+8
View File
@@ -10,6 +10,7 @@ import (
"strings"
"time"
"supermarket/internal/inventory"
"supermarket/internal/seo"
"supermarket/internal/sites"
)
@@ -64,6 +65,13 @@ func (s *Server) composeSection(ctx context.Context, cur siteRepo, p *sites.Site
in.Searches, _ = seo.PageSearches(s.DB, s.scope(st), p.Path, 10)
}
}
if entries, err := inventory.List(s.DB, inventory.Competitor); err == nil {
for i := range entries {
if len(entries[i].Prices) > 0 {
in.Competitors = append(in.Competitors, &entries[i])
}
}
}
out, err := (&sites.Composer{AI: client, Profile: prof}).ComposeSection(ctx, in)
if err != nil {
return err
+25 -1
View File
@@ -1,4 +1,4 @@
{{define "content"}}{{with .Data}}{{$e := .E}}
{{define "content"}}{{with .Data}}{{$d := .}}{{$e := .E}}
<p><a href="/inventory">← Inventory</a></p>
<h1>{{if $e.ID}}{{$e.Name}}{{else}}New entry{{end}}</h1>
@@ -45,6 +45,30 @@
<label>Description <textarea name="description" rows="2">{{$e.Description}}</textarea></label>
<label>Talking points <textarea name="talking_points" rows="4">{{$e.TalkingPoints}}</textarea>
<span class="help">Partners: how you work together. Competitors: how you differ, where you win, and what not to claim.</span></label>
<fieldset class="prices">
<legend>Their prices</legend>
<p class="help">As you read them on their pricing page. Pages that compare with them say only these, with the month you checked; after six months, those pages ask you to check them again. Clear a row to remove it.</p>
{{with $d.Stale}}<p class="warn-text small">{{len .}} {{if eq (len .) 1}}price was{{else}}prices were{{end}} checked more than six months ago: look again{{with (index . 0).Source}} (<a href="{{.}}" target="_blank" rel="noopener noreferrer">their pricing page ↗</a>){{end}}.</p>{{end}}
<div class="table-wrap"><table class="compact price-rows">
<thead><tr><th>Plan</th><th>Price</th><th>Per</th><th>Checked</th><th>Where you read it</th></tr></thead>
<tbody>
{{range $e.Prices}}<tr>
<td><input name="price_plan" value="{{.Plan}}" aria-label="Plan" placeholder="Pro"></td>
<td><input name="price_amount" value="{{.Amount}}" aria-label="Price" placeholder="$25"></td>
<td><input name="price_per" value="{{.Per}}" aria-label="Per" placeholder="per agent per month"></td>
<td><input type="date" name="price_checked" value="{{.Checked}}" aria-label="Checked on"></td>
<td><input type="url" name="price_source" value="{{.Source}}" aria-label="Where you read it" placeholder="https://…/pricing"></td>
</tr>{{end}}
{{range $d.Blank}}<tr>
<td><input name="price_plan" aria-label="Plan" placeholder="Pro"></td>
<td><input name="price_amount" aria-label="Price" placeholder="$25"></td>
<td><input name="price_per" aria-label="Per" placeholder="per agent per month"></td>
<td><input type="date" name="price_checked" value="{{$d.Today}}" aria-label="Checked on"></td>
<td><input type="url" name="price_source" aria-label="Where you read it" placeholder="https://…/pricing"></td>
</tr>{{end}}
</tbody>
</table></div>
</fieldset>
<label>Naming them in posts (competitors only)
<select name="mention_policy">
<option value="category" {{if ne $e.MentionPolicy "name"}}selected{{end}}>Don't name them; talk about the category</option>