askrobots / dbbasic-object-server
Public
Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.
dbbasic-package.json · 13.0 KB · 141 lines
| 1 | { |
| 2 | "id": "app-invoices", |
| 3 | "name": "Invoices", |
| 4 | "version": "0.24.2", |
| 5 | "description": "Line-item invoices, quotes, and credit notes (doc_type on one shared schema): owner-scoped CRUD, guarded status lifecycle (draft/sent/paid/partial/overdue/void), and a HANDLES totals handler (system_invoice_totals) that stamps subtotal/tax/total/balance from invoice_lines in integer cents on every line change. Deferred to a later slice: auto-numbered sequences per doc_type (invoice_counters + a closed invoices create route), the tokenized public/printable /i/{token} view, order-to-invoice conversion, and partial-payment recording (amount_paid_cents exists but nothing writes it yet). See plan/vocabulary/20-invoice-spec.md. subtotal_cents/tax_cents/total_cents/balance_due_cents/line_total_cents/line_tax_cents are deliberately NOT schema read_only -- see objects/system/invoice_totals.py's module docstring for why (update_collection_record has no read_only write exception, so a truly read_only field could never be re-stamped). The invoice permalink /invoices/{invoice_id:uuid} is now a seeded 59 detail view (site_view_render): a composed page of three generic block renderers -- an editable+deletable `detail` block (the invoice; the status field's own 10-flow transition guards enforce legal moves through the owner edit form, so no one-click Send/Void buttons are built, the same make-it-basic trade app-forum's pin/lock retrofit made), a `related` block (invoice_lines by invoice_id -- lines stay their own relational collection, never embedded, because they are the thing receipts/notes attach to later), and a `form` block with fixed:{invoice_id:$record_id} (Add Line, FK locked to the page's invoice). No bespoke per-invoice page or hand-written money-totals table -- the detail block's own /form cents formatting renders subtotal/tax/total/paid/balance correctly with no custom JS. No public/anonymous path in this slice; plan/vocabulary/20-invoice-spec.md's tokenized /i/{public_token} view is still a later slice. 0.5.0 adds the customer payment portal: /pay/{token}, an unguessable capability URL that lets the person who owes money see the invoice and how to pay it WITHOUT an account. The customer is not a user of this system, and a signup wall between a willing payer and their money is why invoices age. The token is schema read_only so no client can choose its own -- a predictable capability URL is not a capability -- and system_invoice_portal_link mints one the moment an invoice leaves draft, because a link that only appears once an invoice goes overdue exists only for the customers who already failed to pay. Dunning emails now carry the link, which is what finally makes them actionable. There is no card processing yet, so the page shows the business's own payment instructions rather than a Pay button that does nothing: a link that lies is worse than no link. 0.6.0 deletes the bespoke /invoices list page object: it was ~90 lines of chrome around two generator calls with no business logic of its own, and is now a seeded VIEW record over the same `list` block the invoice detail's own retrofit already established the precedent for. Declares an attention count (collection + where, counted per viewer) for invoices past their due date, at severity `warning` because this is not work that arrived, it is work that is already late. Overdue is a queue that appears out of the calendar with no write happening, which is exactly the kind nothing draws attention to. Drafts and non-invoice doc_types are excluded: an invoice nobody sent cannot be late. Line discounts arrive with the same shape app-orders uses and the same shared arithmetic (object_lines): discount_bps is a per-line negotiated rate, tax is charged on the discounted amount, and line_discount_cents is STORED beside the total it produced so an invoice can print \"10% off -2.00\" next to the line -- a reader holding only the net total cannot say what was taken off, or whether anything was. Invoices declare capabilities.comments + attachments: the customer's paperwork (a signed PO, their remittance) belongs ON the invoice, and the chase history is a thread rather than a field somebody overwrites. 0.13.0: invoices gain number_key (read_only, unique) and action_generate_tm_invoice claims through it -- the header write is the number claim, so two generated invoices never share a number (a taken one moves to -2, -3, ...) -- and claims each time entry and expense with expected_rev before billing it, so overlapping runs cannot bill the same hours twice. 0.14.1: a row a registered user writes could point at anybody's record, because the rules asked only that the new row be the writer's own. Every pointer a non-admin can write now declares relation.requires (invoice_lines.invoice_id update, invoices.customer_id read), so over the API a row points only at a record its writer may see, or, where it moves money, stock or state of what it points at, may update; a record they may not see is answered like a missing one (docs/permissions-model.md, 'Pointing at a record you may not act on'). 0.15.0: an invoice's lifecycle and money are staff's and the platform's, not its owner's. Checkout and the subscription biller raise invoices OWNED BY THE CUSTOMER they bill, and that owner could PUT status=paid on their own unpaid invoice -- dunning stopped, the balance stayed, and app-shop's fulfillment handler trusts status=paid before it ships -- or PUT a line's unit_price_cents to 0, or delete the invoice. The schemas now declare field permissions (invoices: status, doc_type, currency, dates, stamped totals, dunning stamps, paid_at, tokens, portal counters, source_order_id; invoice_lines: invoice_id and every quantity, price, rate and stamped amount) editable by role:manager and role:admin only; role:manager gains create/read/update on every invoice and line; the registered grants lose delete and the owner fallback is off for delete (an issued invoice is voided). The status transitions keep their map but drop the owner_id guards, which would have refused the staff who must move a customer's invoice. Reactions write in process and are untouched. The old grants are in rules.json's retracted list. 0.16.0: invoice_lines.unit_code (UN/ECE Rec 20), staff-only like quantity, sent with the line to a partner's box. 0.17.0: credit notes net. invoice_credits records a credit note applied (to the invoice it credits, or on the customer's account); invoices.credited_cents and credit_applied_cents are rollups over it, and balance_due_cents is total less paid less both, so a credited invoice owes less and an applied credit note owes nothing (it used to read its own total as due). credits_invoice_id names the invoice a credit note credits. Payments, amount_paid_cents and the payment-driven status rules are untouched: a credit is not a payment. invoice_credits is staff's (role:manager); its owner reads it and does not change it. 0.18.0: invoices.exchange_status (read only), where app-exchange says the customer's box refused the invoice or credit note (\"Refused by <partner>: <reason>\"); nothing else about the invoice changes. 0.19.0: staff roles read the shop's records. role:cashier, role:shift_lead, role:manager and role:owner read every sale, not only rows they own: checkout files a guest sale under the shop's account, so staff saw nothing and signed in as the owner. Read only; changes go through app-counter's actions. 0.20.0: a billed line is not rewritten in place. invoice_lines v5 declares the locked check settled_line (system_invoice_line_freeze, lock ledger, the same rule as order lines in object_corrections) and order_line_id, the order line a line bills, stamped by checkout. 0.21.0: invoices v12: a credit note also carries its reason code and approver, and invoice_lines v6 credits_line_id names the credited invoice's line; a credit-note line citing an order line is refused, inside the ledger lock, when with the refunds and credit notes already citing the line it would correct more than was sold. One credit-note model with app-exchange: invoice_credits v2 adds source counter, the row app-counter writes in the act that issues a credit note, so a counter credit note lowers the credited invoice's balance exactly as a sent one does, and sending it later applies nothing twice. 0.22.0: status follows the money (the owner's decision of 2026-11-30). invoices v13: an issued invoice's total never changes; its status is read off received, refunded and credited (object_corrections.money_status), with three new states -- credit_owed, refunded, credited -- and paid no longer terminal, so a bounced, deleted or refunded-without-credit payment reopens the invoice and the aging pass duns it again. The aging pass's overdue fall-back reads the same rule. An issued invoice line is never voided in place: it comes off by a credit note (the settled_line check refuses the void). 0.23.0: tax is stamped per line at issue (decision 2, 2026-11-30). invoice_totals folds DRAFT invoices only -- an issued invoice's total and tax are never recalculated, so a description edit no longer restates a checkout invoice from 23.00 to 20.90 (finding M1) or a stamped 54 to 53 (M18) -- and a draft's tax is computed once per rate group, half-up, with each line stamped its share (object_lines.allocate_tax). invoices v14, invoice_lines v7. 0.24.0: invoice_lines v8: service_start and service_end, the period a line bills (stamped by the subscription biller), so revenue billed in advance can be deferred and released as it is earned. 0.24.1: action_generate_tm_invoice raises the invoice as the caller, the record API's create rule: an owner_id in the body naming somebody else is refused unless the caller is an admin, and with none the invoice and its lines are the caller's (they used to go to the body's owner_id, or else to whoever logged the first billed hour). customer_id is asked the record API's relation.requires question (read, through object_access) before anything is read or written: a contact the caller may not read and a missing one get its one 400. In-process calls with no identity name their owner as before. 0.24.2: the permission notes say who owns an invoice: the customer being billed when checkout or a subscription raised it, the staff member who raised it when staff did, by hand or from hours. Notes only; no rule's effect changed.", |
| 6 | "compatibility": { |
| 7 | "dbbasic_object_server": ">=0.1.0" |
| 8 | }, |
| 9 | "dependencies": [ |
| 10 | "app-views" |
| 11 | ], |
| 12 | "objects": [ |
| 13 | { |
| 14 | "id": "system_invoice_totals", |
| 15 | "path": "objects/system/invoice_totals.py" |
| 16 | }, |
| 17 | { |
| 18 | "id": "system_invoice_aging", |
| 19 | "path": "objects/system/invoice_aging.py" |
| 20 | }, |
| 21 | { |
| 22 | "id": "site_invoice_portal", |
| 23 | "path": "objects/site/invoice_portal.py" |
| 24 | }, |
| 25 | { |
| 26 | "id": "action_regenerate_portal_link", |
| 27 | "path": "objects/action/regenerate_portal_link.py" |
| 28 | }, |
| 29 | { |
| 30 | "id": "system_invoice_portal_link", |
| 31 | "path": "objects/system/invoice_portal_link.py" |
| 32 | }, |
| 33 | { |
| 34 | "id": "action_generate_tm_invoice", |
| 35 | "path": "objects/action/generate_tm_invoice.py" |
| 36 | }, |
| 37 | { |
| 38 | "id": "system_invoice_line_freeze", |
| 39 | "path": "objects/system/invoice_line_freeze.py" |
| 40 | } |
| 41 | ], |
| 42 | "schemas": [ |
| 43 | { |
| 44 | "collection": "invoices", |
| 45 | "path": "schemas/invoices.json" |
| 46 | }, |
| 47 | { |
| 48 | "collection": "invoice_lines", |
| 49 | "path": "schemas/invoice_lines.json" |
| 50 | }, |
| 51 | { |
| 52 | "collection": "invoice_credits", |
| 53 | "path": "schemas/invoice_credits.json" |
| 54 | } |
| 55 | ], |
| 56 | "permissions": [ |
| 57 | { |
| 58 | "path": "permissions/rules.json" |
| 59 | } |
| 60 | ], |
| 61 | "seed": [ |
| 62 | { |
| 63 | "collection": "invoices", |
| 64 | "path": "seed/invoices.tsv" |
| 65 | }, |
| 66 | { |
| 67 | "collection": "invoice_lines", |
| 68 | "path": "seed/invoice_lines.tsv" |
| 69 | }, |
| 70 | { |
| 71 | "collection": "views", |
| 72 | "path": "seed/views.tsv" |
| 73 | }, |
| 74 | { |
| 75 | "collection": "site_routes", |
| 76 | "path": "seed/site_routes.tsv" |
| 77 | }, |
| 78 | { |
| 79 | "collection": "notify_rules", |
| 80 | "path": "seed/notify_rules.tsv" |
| 81 | } |
| 82 | ], |
| 83 | "migrations": [], |
| 84 | "schedules": [ |
| 85 | { |
| 86 | "id": "invoice_aging_daily", |
| 87 | "object_id": "system_invoice_aging", |
| 88 | "schedule": "10 6 * * *", |
| 89 | "description": "Flip sent invoices to overdue once past due, and escalate dunning." |
| 90 | } |
| 91 | ], |
| 92 | "nav": [ |
| 93 | { |
| 94 | "id": "invoices", |
| 95 | "label": "Invoices", |
| 96 | "path": "/invoices", |
| 97 | "blurb": "Bill customers and track what has been paid, in integer cents", |
| 98 | "surface": "member", |
| 99 | "group": "Money", |
| 100 | "order": 300 |
| 101 | } |
| 102 | ], |
| 103 | "attention": [ |
| 104 | { |
| 105 | "id": "invoices_overdue", |
| 106 | "collection": "invoices", |
| 107 | "where": { |
| 108 | "status": { |
| 109 | "op": "in", |
| 110 | "value": [ |
| 111 | "sent", |
| 112 | "partial", |
| 113 | "overdue", |
| 114 | "" |
| 115 | ] |
| 116 | }, |
| 117 | "doc_type": { |
| 118 | "op": "in", |
| 119 | "value": [ |
| 120 | "invoice", |
| 121 | "" |
| 122 | ] |
| 123 | }, |
| 124 | "due_date": { |
| 125 | "op": "older_than_days", |
| 126 | "value": 1 |
| 127 | } |
| 128 | }, |
| 129 | "detail": { |
| 130 | "op": "max_age_days", |
| 131 | "field": "due_date", |
| 132 | "text": "oldest {value} days late" |
| 133 | }, |
| 134 | "label": "Invoices past due", |
| 135 | "path": "/invoices", |
| 136 | "nav_id": "invoices", |
| 137 | "group": "Money", |
| 138 | "severity": "warning" |
| 139 | } |
| 140 | ] |
| 141 | } |