go/svc/invoice: refactor
We unify calculation logic, move the existing Invoice proto message into
InvoiceData, and create other messages/fields around it to hold
denormalized data.
diff --git a/go/svc/invoice/statusz.go b/go/svc/invoice/statusz.go
index dbc59f1..f076299 100644
--- a/go/svc/invoice/statusz.go
+++ b/go/svc/invoice/statusz.go
@@ -7,6 +7,7 @@
"code.hackerspace.pl/hscloud/go/mirko"
"code.hackerspace.pl/hscloud/go/statusz"
+ pb "code.hackerspace.pl/hscloud/proto/invoice"
"github.com/golang/glog"
)
@@ -37,17 +38,17 @@
<th>Actions</th>
</tr>
{{ range .Invoices }}
- {{ if .Sealed }}
+ {{ if eq .State 2 }}
<tr>
{{ else }}
<tr style="opacity: 0.5">
{{ end }}
- <td>{{ .ID }}</td>
- <td>{{ .Number }}</td>
- <td>{{ index .Proto.CustomerBilling 0 }}</td>
+ <td>{{ .Uid }}</td>
+ <td>{{ .FinalUid }}</td>
+ <td>{{ index .Data.CustomerBilling 0 }}</td>
<td>{{ .TotalNetPretty }}</td>
<td>
- <a href="/debug/view?id={{ .ID }}">View</a>
+ <a href="/debug/view?id={{ .Uid }}">View</a>
</td>
</tr>
{{ end }}
@@ -56,7 +57,7 @@
`
type templateInvoice struct {
- invoice
+ *pb.Invoice
TotalNetPretty string
}
@@ -70,8 +71,8 @@
res.Invoices = make([]templateInvoice, len(invoices))
for i, inv := range invoices {
res.Invoices[i] = templateInvoice{
- invoice: inv,
- TotalNetPretty: fmt.Sprintf("%.2f %s", float64(inv.TotalNet)/100, inv.Proto.Unit),
+ Invoice: inv,
+ TotalNetPretty: fmt.Sprintf("%.2f %s", float64(inv.TotalNet)/100, inv.Unit),
}
}