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

9 downloads

Install on DigitalOcean 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.

Daniel Quellhorst Changelog for this batch. 65ef78d 3 hours, 31 minutes ago History
dbbasic-package.json · 16.7 KB · 112 lines
1{
2 "id": "app-orders",
3 "name": "Orders",
4 "version": "0.19.0",
5 "description": "Sales and purchase orders (doc_type on one shared schema, the real SO/PO split): owner-scoped CRUD, guarded status lifecycle (draft/confirmed/processing/shipped/delivered/cancelled), and a HANDLES totals handler (system_order_totals) that stamps subtotal/tax/total from order_lines in integer cents on every line change. Order lines optionally relate to app-catalog's products collection but do not require it -- a line may be free-text. Reconciled against a private predecessor-system audit, not part of this repo. Deferred to a later slice: auto-numbered sequences per doc_type (an order_counters collection + a closed orders create route), the convert_to_invoice ACTION (invoice_id exists on orders so the provenance link has somewhere to land once that flow is built), stock decrement on ship, and purchase-order receiving. subtotal_cents/tax_cents/total_cents/line_total_cents/line_tax_cents are deliberately NOT schema read_only -- see objects/system/order_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 order permalink /orders/{order_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 order; money renders via /form's cents formatting, no custom JS, and status transitions become status-field edits in the owner edit form, guarded by the 10-flow transitions above -- no one-click status buttons, the same make-it-basic trade app-forum's pin/lock takes), a `related` block (order_lines flat by order_id), and a `form` block with fixed:{order_id:$record_id} (Add Line, FK locked to the page's order). order_lines stays a RELATIONAL collection, not embedded on orders -- a line is addressable on its own (it can have things attached to it later), matching every other line-item package here (app-invoices' invoice_lines, app-forum's forum_replies). No bespoke per-order page. 0.3.0 deletes the bespoke /orders list page object too: 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 order detail's own retrofit already established the precedent for. Ships an attention provider for committed orders with goods still owed -- the pick queue as a number; it folds four collections, so its number is shown only to a viewer who may read every row of them (`reads`). site_pick_list folds the same arithmetic live and is right to, because it is a working screen somebody opens on purpose; a home page cannot afford that fold a dozen times over, so the daemon runs this on an interval instead. The status set and the shipped-quantity rule are read from site_pick_list so the badge and the page it links to cannot disagree. 0.5.0 gives the CUSTOMER a voice back. Until now a guest paid and heard silence: there was no transactional email anywhere on this server and no way for a buyer without an account to ask where their order was. orders.portal_token (v5 of the schema, read_only like the invoice one) is that missing door -- an unguessable capability URL minted by system_order_portal_link the moment an order stops being a draft, and synchronously by app-shop's action_checkout so the checkout response can hand the shopper the link while they are still standing there. site_order_status renders it at /orders/track/{token}, PUBLIC: order number, date, the itemised receipt with prices (unlike the packing slip, which carries none because it goes in the box), the status translated out of warehouse vocabulary into words a person waiting for a parcel understands, the carrier and tracking number when a shipment has them, the pay link while the bill is open, and a return link carrying the same token once something has shipped. Looked up by token only with a constant-time compare; an unknown token gets a friendly 404 that never hints another one would have worked. system_order_email composes the three messages a shop owes a buyer -- confirmed, shipped, refunded -- each fired by a TRANSITION rather than a button, because a button is a thing somebody forgets on a busy Friday. It QUEUES into app-email's outbox and never sends inline, so a slow relay cannot slow the write that triggered it, and it is idempotent by provenance: the marker lives in the outbox row's source_object_id, so a replayed event composes nothing. No nav entry for the tracking page and none wanted -- it is a per-record customer document, not a door into the app, and this package already declares its front door at /orders. No new dependencies either: the email, shipment and invoice reads are all wrapped, because app-shipping already depends on app-orders and the arrow cannot point both ways. 0.6.0 is DROP-SHIPPING, the composition test plan/fulfillment-logistics-spec.md set for the whole fulfillment build -- and it lands here, in the orders package, with no new collection anywhere, because the v1 decision to give sales and purchase orders one shared schema turns out to have already modelled it: 'the vendor ships straight to my customer' is a sale order and a purchase order pointing at each other. orders v6 adds the five fields that link them (fulfillment_source, linked_order_id, vendor_id, ship_to_name, ship_to_address) and action_dropship_order writes both ends in one pass -- the PO confirmed rather than draft (a draft is not a commitment, and a customer waiting on a parcel nobody ordered is the whole failure), carrying the customer's ship-to onto the vendor's document, which is the one place in this repo where the counterparty on an order and the destination of its goods are different people. It refuses a sale order that already has stock moves against it (you cannot drop-ship what you already picked, and the refusal names the moves), refuses a second PO for the same sale order (one duplicate commitment to buy is one supplier who will happily send the goods twice), and reports every blocker together the way checkout does. The vendor's price is asked for -- per line, or flat, or from the product's recorded cost -- and when none of those exist the PO is raised at zero with a WARNING naming the lines, because a cost of zero reads as 100% margin and a cost copied from the sale price reads as none, and both are lies. site_dropship_margin at /orders/{order_id}/margin is the read the spec promised: two rows, one subtraction, object_billing.margin doing the arithmetic rather than a second implementation of it. THE HONEST HALF, named rather than hidden: a drop-ship order must never move our stock, and today the data says so while one handler does not read it. Receiving is safe by construction (nothing raises a receipt on its own, so a drop-ship PO nobody checks in never touches a shelf), but system_order_fulfillment in app-shipping composes a `sale` move for every shipment line at `shipped` without looking at fulfillment_source -- so a shipment recorded against a drop-ship sale order would decrement a shelf that never held the goods. The fix is one condition in a package this slice does not own; tests/test_dropship.py holds it as a strict xfail so it is an acceptance test the day somebody writes it, and app-shipping's schema still needs the `source: vendor` field the spec names for the vendor's own dispatch. 0.7.0 adds TIME, and it is five fields and three enum values rather than a new collection because everything about the MONEY was already built here and almost nothing about the time was (plan/pickup-and-counter-service-spec.md). A food business is a scheduling business that happens to sell food, and until orders v7 this collection could say `shipped` and `delivered` and had no way at all to say 'ready at 6:15' -- which is the whole of what a cafe needed that a parcel shop did not. fulfillment_method (shipping | pickup | delivery | counter, defaulting to shipping so no existing row changes meaning, the same argument fulfillment_source above already makes) is the fact every downstream behaviour keys off. requested_at and promised_at stay TWO fields because 'you wanted 6:00, we said 6:20' is worth keeping and collapsing them hides every capacity failure the shop ever had; ready_at and collected_at are stamped as they happen and never predicted. The status enum grows preparing/ready/collected -- new values, not a reuse of shipped/delivered, because a status a customer reads must use the customer's word -- and WHICH subset of the ladder an order may climb is decided by fulfillment_method in the objects, never by the enum, since an enum cannot condition on another field (the same note `shipments` carries about its own inbound and outbound ladders). site_order_status learns the three new words plus a promised-time line, and a shipping order's page is byte-for-byte what it was: the overlay is keyed on the method and falls back to the old wording when the field is blank. The slots those promised times come from, the generator that creates them and the checkout gate that books them all live in app-pickup, which depends on this package and not the other way round. v0.x adds LINE DISCOUNTS: discount_bps on a line is a negotiated reduction on that row -- ex-display stock, a trade rate, ten per cent off this item -- and it is deliberately NOT a promotion. app-promotions owns codes somebody types, applied to the whole basket and ROUNDED ONCE so four separately-rounded lines cannot accumulate an error nobody can reconcile against the percentage on the receipt; a line discount comes off one row and prints beside it. The two compose, and keeping them apart is what stops \"10% off\" meaning two different numbers depending on which layer applied it. Tax is charged on the DISCOUNTED amount, because a discount on goods reduces the taxable base -- the same thing object_promotions.applies_to already says, and the two must not disagree. The discount floors off the already-floored gross, which is what makes a zero discount arithmetically invisible: every historical line total is bit-identical to what it was. A rate over 100% is clamped rather than honoured, because 12000 basis points is a typo and a line that pays the customer is not something to infer from one. The arithmetic itself moved to object_lines, shared with app-invoices: the two copies of _line_amounts were near enough identical that one was the other plus modifier_cents, which was survivable until both had to subtract a discount. Orders declare capabilities.comments + attachments for the same reason invoices do -- the customer's PO and the internal thread about a specific order. 0.12.0: orders v10 adds action_claim, the compare-and-set claim (object_claims) that action_dropship_order -- and app-shipping's, app-receiving's and app-returns' order actions -- take before they read the order's history, so a double click cannot raise two purchase orders, shipments, receipts or return authorizations. 0.12.2: 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 (order_lines.order_id update, order_lines.product_id read, orders.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.12.3: site_order_status shows an order's invoice (and its pay link, the capability to the bill) only when one owner owns both. orders.invoice_id is free text an order's owner may set, so an order pointed at somebody else's invoice showed that customer's pay link on its own tracking page. It stays free text on purpose: every field is re-validated on every write, so as a relation an order whose invoice was deleted could no longer change status; each reader of the link checks the owner instead. 0.13.0: an online order RESERVES. The owner's decision: 'if i order online and drive to the damn store i expect it to still be there when i arrive'. orders v12 adds reserves_stock (stamped by app-shop's checkout, read_only) and pay_at_pickup; order_lines v5 declares the locked check `stock_hold` (system_stock_hold.LOCKED_CHECK, lock `stock`), which refuses a line of a reserving order that would promise more than on hand less what other live reserving orders hold. It runs inside the write lock for every writer, so racing checkouts cannot both take the last unit -- they did: one unit sold to two orders, three to ten. The hold is the line itself (no reservation ledger), it becomes the stock move when the goods leave, ends on cancel, and an unpaid one lapses by object_pickup.hold_lapsed. Back-office orders do not reserve and are never refused for stock. See object_reservations. 0.13.1: the stock_hold check also refuses a reserving order's line for a product sold in store only (products.in_store_only) or beyond its online limit per order (products.online_max_per_order). Back-office orders are still never refused. 0.14.0: order_lines.unit_code (UN/ECE Rec 20: KGM, C62, XBG ...) says what a quantity counts; blank means the product's unit. A partner's box receives it with the line (app-exchange), so ten kilograms and ten bags arrive distinguishable. 0.15.0: order_lines.partner_line_id, the trading partner's id for a line that came from (or was added by) its document; a confirmation names it line by line. 0.16.0: orders.exchange_status (read only), where app-exchange says a partner's box refused the document made from this order. 0.17.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.18.0: a sold line is not rewritten in place. order_lines v6 declares the locked check settled_line (system_line_freeze, lock ledger): once the order's invoice is issued a line changes only by a void (app-counter), and once money is received nothing priced changes and nothing is deleted; a correction is a new record citing the line. Corner Cup (a Haiku cafe simulation) edited a paid soup into a salad and deleted a line of an unpaid order while its invoice kept billing it. 0.19.0: orders v14 store shipping_cents and discount_cents, and order_totals' total is subtotal - discount + shipping + tax: it was the order's own lines plus tax, which dropped a checkout order's postage and put its promotion discount back on (findings M2). Line amounts round half-up, the cart's rule (M18); where lines state rates the tax is computed once per rate group. order_lines v9.",
6 "compatibility": {
7 "dbbasic_object_server": ">=0.1.0"
8 },
9 "dependencies": [
10 "app-views"
11 ],
12 "objects": [
13 {
14 "id": "system_order_totals",
15 "path": "objects/system/order_totals.py"
16 },
17 {
18 "id": "system_order_attention",
19 "path": "objects/system/order_attention.py"
20 },
21 {
22 "id": "system_order_portal_link",
23 "path": "objects/system/order_portal_link.py"
24 },
25 {
26 "id": "system_order_email",
27 "path": "objects/system/order_email.py"
28 },
29 {
30 "id": "site_order_status",
31 "path": "objects/site/order_status.py"
32 },
33 {
34 "id": "action_dropship_order",
35 "path": "objects/action/dropship_order.py"
36 },
37 {
38 "id": "site_dropship_margin",
39 "path": "objects/site/dropship_margin.py"
40 },
41 {
42 "id": "system_stock_hold",
43 "path": "objects/system/stock_hold.py"
44 },
45 {
46 "id": "system_line_freeze",
47 "path": "objects/system/line_freeze.py"
48 }
49 ],
50 "schemas": [
51 {
52 "collection": "orders",
53 "path": "schemas/orders.json"
54 },
55 {
56 "collection": "order_lines",
57 "path": "schemas/order_lines.json"
58 }
59 ],
60 "permissions": [
61 {
62 "path": "permissions/rules.json"
63 }
64 ],
65 "seed": [
66 {
67 "collection": "orders",
68 "path": "seed/orders.tsv"
69 },
70 {
71 "collection": "order_lines",
72 "path": "seed/order_lines.tsv"
73 },
74 {
75 "collection": "views",
76 "path": "seed/views.tsv"
77 },
78 {
79 "collection": "site_routes",
80 "path": "seed/site_routes.tsv"
81 }
82 ],
83 "migrations": [],
84 "nav": [
85 {
86 "id": "orders",
87 "label": "Orders",
88 "path": "/orders",
89 "blurb": "Sales and purchase orders with their lines and totals",
90 "surface": "member",
91 "group": "Commerce",
92 "order": 420
93 }
94 ],
95 "attention": [
96 {
97 "id": "orders_to_pick",
98 "object_id": "system_order_attention",
99 "label": "Orders to pick",
100 "path": "/orders",
101 "nav_id": "orders",
102 "group": "Commerce",
103 "severity": "normal",
104 "reads": [
105 "orders",
106 "order_lines",
107 "shipments",
108 "shipment_lines"
109 ]
110 }
111 ]
112}