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.
stock_moves.json · 6.4 KB · 145 lines
| 1 | { |
| 2 | "name": "stock_moves", |
| 3 | "title": "Stock Moves", |
| 4 | "version": 7, |
| 5 | "storage": "append", |
| 6 | "hooks": { |
| 7 | "before_write": "hook_stock_moves" |
| 8 | }, |
| 9 | "description": "Immutable ledger of inventory movement: product_id moves quantity from from_location_id to to_location_id. Never updated once written -- stock LEVELS are derived by folding this log (see object_stock.py), never stored on this collection or anywhere else. Reconciled against a private predecessor-system catalog audit, not part of this repo (its StockMove model: 'immutable, levels DERIVED not stored'). This is the textbook append-mode collection per docs/append-only-storage-design.md: write-heavy, never updated, an inspectable audit trail by design -- see docs/storage-modes.md's 'Append (opt-in per collection)' section for what that changes about how this collection is physically written and read. TAX POSTURE: some jurisdictions assess business personal property tax on inventory VALUE as of a specific date, per location -- this log supports that by construction (fold moves up to any date, per location, at stamped unit_cost_cents); nothing may ever collapse the location dimension or overwrite stamped costs. v4: 'never updated once written' was true of the storage mode and not of the API -- the permission rule let the owner PUT and DELETE, and the hook gated create only. hook_stock_moves now refuses any edit and any delete for anybody who is not an admin; the correction is a new compensating move. v6: relation.requires update on the product, both locations and the entity. Stock levels ARE the moves, so a registered user's own move against somebody else's product changed that product's level, cost and books. v7: evaporation and shrinkage loss reasons. Quantities were already decimal (number, folded with Decimal): a product sold by the litre or the kilo moves 2.25 of itself, and levels, sale costing, counts and the moving average stay exact (tests/test_stock_losses_and_decimals.py).", |
| 10 | "fields": [ |
| 11 | { |
| 12 | "name": "id" |
| 13 | }, |
| 14 | { |
| 15 | "name": "product_id", |
| 16 | "type": "relation", |
| 17 | "required": true, |
| 18 | "relation": { |
| 19 | "collection": "products", |
| 20 | "display_field": "name", |
| 21 | "requires": "update"}, |
| 22 | "label": "Product" |
| 23 | }, |
| 24 | { |
| 25 | "name": "from_location_id", |
| 26 | "label": "From Location", |
| 27 | "relation": { |
| 28 | "collection": "locations", |
| 29 | "display_field": "name", |
| 30 | "requires": "update"}, |
| 31 | "validation": { |
| 32 | "required_when": { |
| 33 | "reason": ["waste", "breakage", "theft", "expiry", "damage", "disaster", "evaporation", "shrinkage"] |
| 34 | } |
| 35 | }, |
| 36 | "help": "Optional -- blank means an external origin (e.g. a purchase, where stock enters from outside any tracked location)." |
| 37 | }, |
| 38 | { |
| 39 | "name": "to_location_id", |
| 40 | "label": "To Location", |
| 41 | "relation": { |
| 42 | "collection": "locations", |
| 43 | "display_field": "name", |
| 44 | "requires": "update"}, |
| 45 | "help": "Optional -- blank means an external destination (e.g. a sale, where stock leaves to outside any tracked location)." |
| 46 | }, |
| 47 | { |
| 48 | "name": "quantity", |
| 49 | "type": "number", |
| 50 | "required": true, |
| 51 | "label": "Quantity", |
| 52 | "validation": { |
| 53 | "exclusive_min": 0 |
| 54 | }, |
| 55 | "help": "More than zero: direction comes from the from/to locations and a correction is a new compensating move, never a negative row. A count/measure, not money -- may be fractional. The one deliberate float-shaped exception in this package, same as app-orders' order_lines.quantity: Decimal arithmetic everywhere this is read (object_stock.py), never a bare float." |
| 56 | }, |
| 57 | { |
| 58 | "name": "unit_cost_cents", |
| 59 | "type": "integer", |
| 60 | "label": "Unit Cost (cents)", |
| 61 | "help": "Optional. Integer cents, never a float or currency type, per 00-doctrine-and-contract.md." |
| 62 | }, |
| 63 | { |
| 64 | "name": "reason", |
| 65 | "type": "enum", |
| 66 | "label": "Reason", |
| 67 | "default": "transfer", |
| 68 | "enum": [ |
| 69 | "purchase", |
| 70 | "sale", |
| 71 | "transfer", |
| 72 | "adjustment", |
| 73 | "return", |
| 74 | "count", |
| 75 | "waste", |
| 76 | "breakage", |
| 77 | "theft", |
| 78 | "expiry", |
| 79 | "damage", |
| 80 | "disaster", |
| 81 | "evaporation", |
| 82 | "shrinkage" |
| 83 | ], |
| 84 | "help": "The first six match the predecessor system's stock move reasons (reconciled against a private source audit, not part of this repo). v3 adds the LOSS taxonomy (plan/inventory-adjustments-spec.md): waste/breakage/theft/expiry/damage/disaster name what actually happened instead of hiding it under 'adjustment' -- a loss move leaves from_location_id with NO to_location_id (goods left the system; hook-enforced) and composes a shrinkage journal (system_stock_books). 'adjustment' remains for count variances only (action_apply_count writes them). v7 adds evaporation (a liquid lost volume in storage: spirits in a cask, fuel in a tank) and shrinkage (missing, cause unknown -- what a count finds and nobody can explain); both are loss reasons with the same shape, and a count may name either for its shortage (action_apply_count reason=...). Each may route to its own account (inventory.journal.evaporation_account / shrinkage_account)." |
| 85 | }, |
| 86 | { |
| 87 | "name": "reference", |
| 88 | "type": "text", |
| 89 | "label": "Reference", |
| 90 | "help": "Free-text provenance pointer, e.g. an order id. No enforced relation -- this package has no hard dependency on app-orders." |
| 91 | }, |
| 92 | { |
| 93 | "name": "occurred_at", |
| 94 | "type": "datetime", |
| 95 | "label": "Occurred" |
| 96 | }, |
| 97 | { |
| 98 | "name": "owner_id", |
| 99 | "type": "text", |
| 100 | "label": "Owner" |
| 101 | }, |
| 102 | { |
| 103 | "name": "entity_id", |
| 104 | "type": "text", |
| 105 | "label": "Entity", |
| 106 | "relation": { |
| 107 | "collection": "entities", |
| 108 | "display_field": "name", |
| 109 | "requires": "update"}, |
| 110 | "help": "The set of books this belongs to (65 multi-entity). Optional during rollout; backfilled to the owner's default entity, set by the entity switcher on new writes." |
| 111 | }, |
| 112 | { |
| 113 | "name": "created_at", |
| 114 | "type": "datetime", |
| 115 | "label": "Created", |
| 116 | "read_only": true |
| 117 | } |
| 118 | ], |
| 119 | "forms": { |
| 120 | "default": { |
| 121 | "fields": [ |
| 122 | "product_id", |
| 123 | "from_location_id", |
| 124 | "to_location_id", |
| 125 | "quantity", |
| 126 | "unit_cost_cents", |
| 127 | "reason", |
| 128 | "reference", |
| 129 | "occurred_at" |
| 130 | ] |
| 131 | } |
| 132 | }, |
| 133 | "views": { |
| 134 | "list_mode": "table", |
| 135 | "list_fields": [ |
| 136 | "product_id", |
| 137 | "reason", |
| 138 | "quantity", |
| 139 | "occurred_at" |
| 140 | ], |
| 141 | "filter_fields": [ |
| 142 | "reason" |
| 143 | ] |
| 144 | } |
| 145 | } |