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.
order_lines.json · 12.2 KB · 266 lines
| 1 | { |
| 2 | "name": "order_lines", |
| 3 | "title": "Order Lines", |
| 4 | "version": 9, |
| 5 | "description": "Line items belonging to one order. line_total_cents and line_tax_cents are stamped by the order_totals handler on every create/update/delete. See objects/system/order_totals.py. A line also carries what was ASKED FOR on it (line_note) and what that instruction cost (modifier_cents), which is how a kitchen order works: a large latte is genuinely its own product with its own SKU, price and stock, and variants-as-products already handles that, but 'no onions' is not a product -- it has no SKU, it is an instruction on one line of one order, and modelling it as a product would put thousands of dead rows in the catalogue. 'Oat milk +60c' is the same instruction with a price delta, which is why the delta lives on the line rather than in the price book. The note is never money and the delta always is: the note prints on the kitchen ticket and touches no total, while the delta is inside line_total_cents everywhere that number is folded. v3 records whether a line was BACKORDERED -- sold with the shop's open agreement that the goods are not here yet. The shipment builder reads it so a parcel never claims to carry what the shelf does not hold. v4: relation.requires update on the order (a line is what the order bills and ships) and read on the product. A registered user's own line could be added to anybody's order. v5: a line of an order that RESERVES stock (orders.reserves_stock, an online order) is a HOLD on the shelf, and the locked check `stock_hold` (system_stock_hold.LOCKED_CHECK, lock `stock`) refuses one that would promise more than is available -- on hand less what other live online orders hold -- inside the write lock, for every writer, so two shoppers racing for the last unit cannot both have it. The arithmetic is object_reservations; see its module docstring for the owner's decision and why the hold is the line rather than a reservation ledger. v6: unit_code says what the quantity counts (UN/ECE Rec 20: KGM, C62, XBG ...); a partner's box receives it with the line, so ten kilograms and ten bags arrive distinguishable (docs/box-to-box-exchange.md). v7: partner_line_id, on a line made from a partner's purchase order (or added from a partner's confirmation): the partner's own id for that line, which a confirmation names line by line so the buyer's box can compare each line it asked for with the one it got. v8 freezes a sold line (Corner Cup, a Haiku simulation of a counter cafe, edited a paid soup into a salad on the order and, separately, on the invoice, and deleted a line of an unpaid order while the invoice kept billing it). The locked check settled_line (system_line_freeze, lock ledger, rule in object_corrections) refuses, for every writer: any priced change or delete once money has been received against the order's invoice (a correction is a new record citing the line), and anything but a VOID (quantity and amounts to zero with voided_at and void_reason_code, done by app-counter's action_counter_void on the order line and the invoice line together) once the invoice is issued. A zero-priced line (a remake's kitchen ticket line) may still be added. remake_of_line_id and the void fields are read_only: only an in-process writer sets them. unit_code (what the quantity counts) is a term of the sale and freezes with the quantity; partner_line_id is a reference and does not. v9: line amounts round half-up, the cart's rule (finding M18), and line_tax_cents is the line's share of the order's tax computed once per rate group (decision 2, 2026-11-30).", |
| 6 | "locked_checks": [ |
| 7 | { |
| 8 | "name": "stock_hold", |
| 9 | "object": "system_stock_hold", |
| 10 | "function": "LOCKED_CHECK", |
| 11 | "reads": [ |
| 12 | "orders", |
| 13 | "products", |
| 14 | "stock_moves", |
| 15 | "locations", |
| 16 | "shipment_lines", |
| 17 | "payments", |
| 18 | "invoices", |
| 19 | "pickup_slots", |
| 20 | "app_settings" |
| 21 | ], |
| 22 | "lock": "stock", |
| 23 | "on": { |
| 24 | "create": true, |
| 25 | "update": [ |
| 26 | "quantity", |
| 27 | "product_id", |
| 28 | "order_id" |
| 29 | ], |
| 30 | "delete": false |
| 31 | } |
| 32 | }, |
| 33 | { |
| 34 | "name": "settled_line", |
| 35 | "object": "system_line_freeze", |
| 36 | "function": "LOCKED_CHECK", |
| 37 | "reads": [ |
| 38 | "orders", |
| 39 | "invoices", |
| 40 | "payments" |
| 41 | ], |
| 42 | "lock": "ledger", |
| 43 | "on": { |
| 44 | "create": true, |
| 45 | "update": [ |
| 46 | "order_id", |
| 47 | "product_id", |
| 48 | "description", |
| 49 | "quantity", |
| 50 | "unit_code", |
| 51 | "unit_price_cents", |
| 52 | "modifier_cents", |
| 53 | "discount_bps", |
| 54 | "line_discount_cents", |
| 55 | "line_total_cents", |
| 56 | "tax_rate_bps", |
| 57 | "line_tax_cents", |
| 58 | "voided_at", |
| 59 | "void_reason_code", |
| 60 | "voided_by" |
| 61 | ], |
| 62 | "delete": true |
| 63 | } |
| 64 | } |
| 65 | ], |
| 66 | "fields": [ |
| 67 | { |
| 68 | "name": "id" |
| 69 | }, |
| 70 | { |
| 71 | "name": "order_id", |
| 72 | "subject": "relation", |
| 73 | "type": "relation", |
| 74 | "required": true, |
| 75 | "relation": { |
| 76 | "collection": "orders", |
| 77 | "display_field": "number", |
| 78 | "requires": "update" |
| 79 | }, |
| 80 | "label": "Order", |
| 81 | "help": "Set once at creation and not intended to change after. Not schema read_only -- same reason as app-invoices' invoice_lines.invoice_id: a required, client-submitted-at-creation field cannot also be read_only on this platform (the server rejects any client submission of a read_only field, even the first one)." |
| 82 | }, |
| 83 | { |
| 84 | "name": "product_id", |
| 85 | "label": "Product", |
| 86 | "relation": { |
| 87 | "collection": "products", |
| 88 | "display_field": "name", |
| 89 | "requires": "read" |
| 90 | }, |
| 91 | "help": "Optional cross-reference to app-catalog's products collection. A line may reference a catalog product or stand alone as a free-text description -- optional, not required, so this package has no hard dependency on app-catalog." |
| 92 | }, |
| 93 | { |
| 94 | "name": "description", |
| 95 | "type": "text", |
| 96 | "required": true, |
| 97 | "label": "Description", |
| 98 | "validation": { |
| 99 | "min_length": 1, |
| 100 | "max_length": 300 |
| 101 | } |
| 102 | }, |
| 103 | { |
| 104 | "name": "quantity", |
| 105 | "type": "number", |
| 106 | "default": "1", |
| 107 | "label": "Quantity", |
| 108 | "help": "A count/measure, not money -- may be fractional. This is the one deliberate use of a float-shaped field in this package; every *_cents field stays integer. Same exception app-invoices' invoice_lines.quantity documents." |
| 109 | }, |
| 110 | { |
| 111 | "name": "unit_code", |
| 112 | "type": "text", |
| 113 | "label": "Unit", |
| 114 | "help": "What the quantity counts, as a UN/ECE Recommendation 20 code: KGM kilogram, C62 one, H87 piece, LTR litre, XBG bag, XBX box, HUR hour. Blank means the product's unit (its free-text unit, coded when the line is sent to a partner's box), or C62 for a line with no product. Ten kilograms and ten bags are different orders; this is what says which.", |
| 115 | "validation": { |
| 116 | "pattern": "^[A-Z0-9]{1,3}$" |
| 117 | } |
| 118 | }, |
| 119 | { |
| 120 | "name": "unit_price_cents", |
| 121 | "type": "integer", |
| 122 | "required": true, |
| 123 | "label": "Unit Price (cents)" |
| 124 | }, |
| 125 | { |
| 126 | "name": "partner_line_id", |
| 127 | "type": "text", |
| 128 | "label": "Partner's Line", |
| 129 | "help": "The trading partner's id for this line (app-exchange): set when the line came from their document, and how a confirmation answers it line by line.", |
| 130 | "validation": { |
| 131 | "max_length": 128 |
| 132 | } |
| 133 | }, |
| 134 | { |
| 135 | "name": "line_note", |
| 136 | "type": "text", |
| 137 | "label": "Line Note", |
| 138 | "help": "What was asked for on THIS line -- 'no onions', 'extra hot', 'cut in half'. An instruction, not a product: it has no SKU and it is true of one line of one order. It prints on the kitchen ticket, where a cook actually reads it, and it is never money -- no total anywhere moves because somebody typed here.", |
| 139 | "validation": { |
| 140 | "max_length": 300 |
| 141 | } |
| 142 | }, |
| 143 | { |
| 144 | "name": "modifier_cents", |
| 145 | "type": "integer", |
| 146 | "default": "0", |
| 147 | "label": "Modifier (cents)", |
| 148 | "help": "The price delta the instruction carries -- 'oat milk +60c' -- in integer minor units, PER UNIT, so two oat lattes cost two deltas. Inside line_total_cents, never beside it: money that appears in one total and not another is the bug this codebase is organised against, so order_totals folds it in and the invoice line carries it in its unit price.", |
| 149 | "validation": { |
| 150 | "min": 0 |
| 151 | } |
| 152 | }, |
| 153 | { |
| 154 | "name": "backordered", |
| 155 | "type": "boolean", |
| 156 | "default": "false", |
| 157 | "label": "Backordered", |
| 158 | "help": "The shop sold this line knowing it did not have the goods, and said so at checkout. It lives HERE, on the order, because the picker and the packer read the order -- a fact kept only in another app's collection is a fact the warehouse never sees, and the consequence of not seeing it is a short parcel plus a stock ledger driven negative on goods nobody could pick. Written by checkout, read by the shipment builder, which packs what is on the shelf and leaves the rest owed." |
| 159 | }, |
| 160 | { |
| 161 | "name": "discount_bps", |
| 162 | "type": "integer", |
| 163 | "label": "Discount %", |
| 164 | "help": "A negotiated reduction on THIS line, in basis points (1000 = 10%). Not a promotion -- a promo code applies to the whole basket and is rounded once (app-promotions); this comes off one row and prints beside it. Tax is charged on the discounted amount, because a discount on goods reduces the taxable base. A flat per-unit reduction is a negative modifier_cents; the percentage is what nothing else could express." |
| 165 | }, |
| 166 | { |
| 167 | "name": "line_discount_cents", |
| 168 | "type": "integer", |
| 169 | "label": "Discount", |
| 170 | "help": "Computed from discount_bps." |
| 171 | }, |
| 172 | { |
| 173 | "name": "line_total_cents", |
| 174 | "type": "integer", |
| 175 | "default": "0", |
| 176 | "label": "Line Total (cents)", |
| 177 | "help": "Stamped by order_totals: floor(quantity * (unit_price_cents + modifier_cents)). Never user-entered." |
| 178 | }, |
| 179 | { |
| 180 | "name": "tax_rate_bps", |
| 181 | "type": "integer", |
| 182 | "label": "Tax Rate (bps)", |
| 183 | "help": "Basis points, e.g. 825 = 8.25%. Optional; blank or 0 means no tax on this line." |
| 184 | }, |
| 185 | { |
| 186 | "name": "line_tax_cents", |
| 187 | "type": "integer", |
| 188 | "default": "0", |
| 189 | "label": "Line Tax (cents)", |
| 190 | "help": "This line's share of the order's tax: the rate is stamped at issue, the tax is computed once per rate group (sum of the group's nets x rate, rounded half-up) and shared out, the odd cent to the line with the largest remainder (object_lines.allocate_tax). Never recalculated after issue (decision 2, 2026-11-30)." |
| 191 | }, |
| 192 | { |
| 193 | "name": "remake_of_line_id", |
| 194 | "type": "text", |
| 195 | "read_only": true, |
| 196 | "label": "Remake of", |
| 197 | "validation": { |
| 198 | "max_length": 64 |
| 199 | }, |
| 200 | "description": "On a zero-priced kitchen ticket line made to replace another: the order line it remakes (app-counter's remakes record links the two and the waste move). Server-stamped." |
| 201 | }, |
| 202 | { |
| 203 | "name": "voided_at", |
| 204 | "type": "datetime", |
| 205 | "read_only": true, |
| 206 | "label": "Voided at", |
| 207 | "description": "When this line was voided (app-counter's action_counter_void). A voided line keeps its row and its reason: quantity and amounts go to zero, on the order line and the invoice line billing it together. Server-stamped." |
| 208 | }, |
| 209 | { |
| 210 | "name": "void_reason_code", |
| 211 | "type": "text", |
| 212 | "read_only": true, |
| 213 | "label": "Void reason", |
| 214 | "validation": { |
| 215 | "max_length": 64 |
| 216 | }, |
| 217 | "description": "Why it was voided: a correction_reasons code (app-counter). Server-stamped by the void." |
| 218 | }, |
| 219 | { |
| 220 | "name": "voided_by", |
| 221 | "type": "text", |
| 222 | "read_only": true, |
| 223 | "label": "Voided by", |
| 224 | "validation": { |
| 225 | "max_length": 120 |
| 226 | }, |
| 227 | "description": "Who voided it. Server-stamped by the void." |
| 228 | }, |
| 229 | { |
| 230 | "name": "owner_id", |
| 231 | "type": "text", |
| 232 | "label": "Owner" |
| 233 | }, |
| 234 | { |
| 235 | "name": "created_at", |
| 236 | "type": "datetime", |
| 237 | "label": "Created", |
| 238 | "read_only": true |
| 239 | } |
| 240 | ], |
| 241 | "forms": { |
| 242 | "default": { |
| 243 | "fields": [ |
| 244 | "order_id", |
| 245 | "product_id", |
| 246 | "description", |
| 247 | "quantity", |
| 248 | "unit_code", |
| 249 | "unit_price_cents", |
| 250 | "line_note", |
| 251 | "modifier_cents", |
| 252 | "tax_rate_bps" |
| 253 | ] |
| 254 | } |
| 255 | }, |
| 256 | "views": { |
| 257 | "list_mode": "table", |
| 258 | "list_fields": [ |
| 259 | "description", |
| 260 | "quantity", |
| 261 | "unit_code", |
| 262 | "unit_price_cents", |
| 263 | "line_total_cents" |
| 264 | ] |
| 265 | } |
| 266 | } |