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/proto/invoice/invoice.proto b/proto/invoice/invoice.proto
index 90fc874..187e358 100644
--- a/proto/invoice/invoice.proto
+++ b/proto/invoice/invoice.proto
@@ -9,6 +9,9 @@
// in thousands of percent points
// (ie 23% == 23000)
uint64 vat = 4;
+ // Denormalized fields follow.
+ uint64 total_net = 5;
+ uint64 total = 6;
}
message ContactPoint {
@@ -16,7 +19,7 @@
string contact = 2;
}
-message Invoice {
+message InvoiceData {
repeated Item item = 1;
repeated string invoicer_billing = 2;
repeated ContactPoint invoicer_contact = 3;
@@ -32,8 +35,28 @@
string unit = 13;
}
+message Invoice {
+ // Original invoice parameters/data.
+ InvoiceData data = 1;
+ enum State {
+ STATE_INVALID = 0;
+ STATE_PROFORMA = 1;
+ STATE_SEALED = 2;
+ };
+ State state = 2;
+ string uid = 9;
+ // If sealed, otherwise 'proforma'.
+ string final_uid = 3;
+ int64 date = 4;
+ int64 due_date = 5;
+ // Denormalized fields follow.
+ uint64 total_net = 6;
+ uint64 total = 7;
+ string unit = 8;
+}
+
message CreateInvoiceRequest {
- Invoice invoice = 1;
+ InvoiceData invoice_data = 1;
}
message CreateInvoiceResponse {
@@ -47,13 +70,6 @@
message GetInvoiceResponse {
Invoice invoice = 1;
- enum State {
- STATE_INVALID = 0;
- STATE_PROFORMA = 1;
- STATE_SEALED = 2;
- };
- State state = 2;
- string final_uid = 3;
}
message RenderInvoiceRequest {