Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.

0 downloads

Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-object-server.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-object-server.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-object-server.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 signup: the person chooses the password and name on the confirm page 83c7aa6 2 weeks, 5 days ago History
invoices.json · 9.8 KB · 351 lines
1{
2 "name": "invoices",
3 "title": "Invoices",
4 "version": 5,
5 "description": "Line-item invoices, quotes, and credit notes. Lines live in invoice_lines; subtotal/tax/total/balance are stamped by the invoice_totals handler, never typed by hand. See plan/vocabulary/20-invoice-spec.md.",
6 "fields": [
7 {
8 "name": "id"
9 },
10 {
11 "name": "doc_type",
12 "type": "enum",
13 "label": "Document Type",
14 "default": "invoice",
15 "enum": [
16 "invoice",
17 "credit_note",
18 "quote"
19 ],
20 "help": "invoice/credit_note/quote share this schema. Real predecessor numbers each type separately (INV-####/CN-####/QT-####); auto-numbering is deferred here (see the number field) but the type is captured now so nothing is lost."
21 },
22 {
23 "name": "number",
24 "type": "text",
25 "required": true,
26 "label": "Number",
27 "help": "Human document number, e.g. INV-0001. v1 is typed by the owner, not auto-assigned -- a sequenced invoice_counters collection + closed create route is a later slice (plan/vocabulary/20-invoice-spec.md), not built here."
28 },
29 {
30 "name": "customer_id",
31 "label": "Customer (contact)",
32 "relation": {
33 "collection": "contacts",
34 "display_field": "first_name"
35 },
36 "help": "Optional cross-reference only. The snapshot fields below are what every surface renders -- editing the contact later never rewrites an already-issued document."
37 },
38 {
39 "name": "customer_name",
40 "type": "text",
41 "required": true,
42 "label": "Bill To",
43 "validation": {
44 "min_length": 1,
45 "max_length": 200
46 }
47 },
48 {
49 "name": "customer_email",
50 "type": "text",
51 "label": "Customer Email",
52 "validation": {
53 "max_length": 254
54 }
55 },
56 {
57 "name": "customer_address",
58 "type": "textarea",
59 "label": "Billing Address"
60 },
61 {
62 "name": "currency",
63 "type": "text",
64 "default": "USD",
65 "label": "Currency (ISO 4217)",
66 "validation": {
67 "pattern": "^[A-Z]{3}$"
68 }
69 },
70 {
71 "name": "status",
72 "type": "enum",
73 "label": "Status",
74 "default": "draft",
75 "enum": [
76 "draft",
77 "sent",
78 "paid",
79 "partial",
80 "overdue",
81 "void"
82 ],
83 "transitions": {
84 "draft": [
85 {
86 "to": "sent",
87 "when": {
88 "owner_id": "$user_id"
89 }
90 },
91 {
92 "to": "void",
93 "when": {
94 "owner_id": "$user_id"
95 }
96 }
97 ],
98 "sent": [
99 {
100 "to": "paid",
101 "when": {
102 "owner_id": "$user_id"
103 }
104 },
105 {
106 "to": "partial",
107 "when": {
108 "owner_id": "$user_id"
109 }
110 },
111 {
112 "to": "overdue",
113 "when": {
114 "owner_id": "$user_id"
115 }
116 },
117 {
118 "to": "void",
119 "when": {
120 "owner_id": "$user_id"
121 }
122 }
123 ],
124 "partial": [
125 {
126 "to": "paid",
127 "when": {
128 "owner_id": "$user_id"
129 }
130 },
131 {
132 "to": "void",
133 "when": {
134 "owner_id": "$user_id"
135 }
136 },
137 {
138 "to": "overdue",
139 "when": {
140 "owner_id": "$user_id"
141 }
142 }
143 ],
144 "overdue": [
145 {
146 "to": "paid",
147 "when": {
148 "owner_id": "$user_id"
149 }
150 },
151 {
152 "to": "partial",
153 "when": {
154 "owner_id": "$user_id"
155 }
156 },
157 {
158 "to": "void",
159 "when": {
160 "owner_id": "$user_id"
161 }
162 }
163 ],
164 "paid": [
165 {
166 "to": "partial",
167 "when": {
168 "owner_id": "$user_id"
169 }
170 }
171 ]
172 },
173 "help": "paid and void are terminal. Every other move requires the invoice owner. overdue is a manual move in v1 -- a daemon pass that flips sent->overdue once due_date has passed is a later slice, not built here."
174 },
175 {
176 "name": "issue_date",
177 "type": "date",
178 "label": "Issue Date"
179 },
180 {
181 "name": "due_date",
182 "type": "date",
183 "label": "Due Date"
184 },
185 {
186 "name": "subtotal_cents",
187 "type": "integer",
188 "default": "0",
189 "label": "Subtotal (cents)",
190 "help": "Stamped by the invoice_totals handler: sum of every line's line_total_cents. Never user-entered -- see package README-equivalent (dbbasic-package.json description) for why this is not schema read_only."
191 },
192 {
193 "name": "tax_cents",
194 "type": "integer",
195 "default": "0",
196 "label": "Tax (cents)",
197 "help": "Stamped by invoice_totals: sum of every line's line_tax_cents (line_total_cents * tax_rate_bps // 10000, floored)."
198 },
199 {
200 "name": "total_cents",
201 "type": "integer",
202 "default": "0",
203 "label": "Total (cents)",
204 "help": "Stamped by invoice_totals: subtotal_cents + tax_cents."
205 },
206 {
207 "name": "payments_received_cents",
208 "type": "computed",
209 "label": "Payments (cents)",
210 "rollup": {
211 "collection": "payments",
212 "fk_field": "invoice_id",
213 "op": "sum",
214 "field": "amount_cents",
215 "where": {
216 "status": "received"
217 }
218 }
219 },
220 {
221 "name": "refunded_cents",
222 "type": "computed",
223 "label": "Refunded (cents)",
224 "rollup": {
225 "collection": "refunds",
226 "fk_field": "invoice_id",
227 "op": "sum",
228 "field": "amount_cents"
229 }
230 },
231 {
232 "name": "amount_paid_cents",
233 "type": "computed",
234 "label": "Paid (cents)",
235 "formula": "payments_received_cents - refunded_cents"
236 },
237 {
238 "name": "balance_due_cents",
239 "type": "computed",
240 "label": "Balance due (cents)",
241 "formula": "total_cents - amount_paid_cents"
242 },
243 {
244 "name": "dunning_level",
245 "type": "integer",
246 "default": "0",
247 "label": "Dunning level"
248 },
249 {
250 "name": "last_dunned_on",
251 "type": "date",
252 "label": "Last dunned"
253 },
254 {
255 "name": "notes",
256 "type": "textarea",
257 "label": "Notes"
258 },
259 {
260 "name": "payment_link",
261 "type": "text",
262 "label": "Payment Link"
263 },
264 {
265 "name": "paid_at",
266 "type": "datetime",
267 "label": "Paid At"
268 },
269 {
270 "name": "public_token",
271 "type": "text",
272 "label": "Public Link Token",
273 "help": "Separate rotatable token for a future public/printable view (plan/vocabulary/20-invoice-spec.md's /i/{token} route). The public page itself is a later slice -- not built here."
274 },
275 {
276 "name": "portal_token",
277 "type": "text",
278 "read_only": true,
279 "label": "Portal Link Token",
280 "help": "secrets.token_urlsafe(32), minted server-side (action_regenerate_portal_link, or lazily by system_invoice_aging the first time a dunning email needs a working link). Distinct from public_token on purpose -- this token grants a capability (view this one invoice AND see its live balance/payment-instructions state), not merely a read, so it gets its own rotatable credential rather than overloading the printable-view token with a different trust level. read_only because it is never client-submitted; a server-side write uses preserve_read_only, same posture invoice_totals.py documents for stamped totals. Deliberately absent from forms.default.fields, views.list_fields, and search.fields below so the generic form/list/search generators never round-trip it -- and it is further shielded from ever crossing an owner boundary because plain row_filter scoping (permissions/rules.json: {\"owner_id\": \"$user_id\"}) already means a non-owner's list/search call returns zero rows for someone else's invoice, token included."
281 },
282 {
283 "name": "portal_views",
284 "type": "integer",
285 "default": "0",
286 "label": "Portal Views",
287 "help": "Stamped by site_invoice_portal on every /pay/{token} view (best-effort -- a counter write must never break the page the customer is trying to read). Dunning intelligence: 'viewed 3x, still unpaid' is a materially different follow-up than 'never opened', per plan/customer-payment-portal-spec.md."
288 },
289 {
290 "name": "last_viewed_at",
291 "type": "datetime",
292 "label": "Portal Last Viewed",
293 "help": "Stamped alongside portal_views on every portal page view. Blank means never opened."
294 },
295 {
296 "name": "source_order_id",
297 "type": "text",
298 "label": "Source Order",
299 "help": "Provenance link to the order this invoice was converted from (real predecessor's convert_to_invoice). No orders/catalog package exists yet in this codebase -- the field is kept so a future app-orders package has somewhere to record it without a backfill."
300 },
301 {
302 "name": "owner_id",
303 "type": "text",
304 "label": "Owner"
305 },
306 {
307 "name": "created_at",
308 "type": "datetime",
309 "label": "Created",
310 "read_only": true
311 }
312 ],
313 "forms": {
314 "default": {
315 "fields": [
316 "doc_type",
317 "number",
318 "customer_id",
319 "customer_name",
320 "customer_email",
321 "customer_address",
322 "currency",
323 "issue_date",
324 "due_date",
325 "status",
326 "notes",
327 "payment_link"
328 ]
329 }
330 },
331 "views": {
332 "list_mode": "table",
333 "list_fields": [
334 "number",
335 "customer_name",
336 "status",
337 "total_cents",
338 "due_date"
339 ]
340 },
341 "search": {
342 "fields": [
343 "number",
344 "customer_name"
345 ]
346 },
347 "capabilities": {
348 "comments": true,
349 "attachments": true
350 }
351}