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.
loss_events.json · 7.8 KB · 91 lines
| 1 | { |
| 2 | "name": "loss_events", |
| 3 | "title": "Loss Events", |
| 4 | "version": 1, |
| 5 | "description": "One record for any loss, of stock or of equipment or of anything else: what was lost, when, how it was found out, the evidence, the estimated and the final amount, the insurance claim and what it recovered, and who approved it. A loss is reported by one person and approved by ANOTHER (the hook stamps reported_by and approved_by from the signed-in user; the locked check refuses an approved row whose approver is blank or is the reporter, for every writer). Approved is frozen, except the insurance claim's progress and notes; once the insurer has paid, the recovery is frozen too. The numbers in the books trace back to this row: an inventory loss is booked by its stock move (stock_move_id), an equipment loss by its asset disposal (whose loss_event_id points here, and which a theft or casualty cannot be posted without), anything else by the write-off this row composes once approved (DR loss / CR write_off_account_id); an insurance recovery is booked once, from here or on the disposal. Unapproved losses are counted on the home page (attention losses_to_approve).", |
| 6 | "fields": [ |
| 7 | {"name": "id"}, |
| 8 | {"name": "occurred_on", "type": "date", "required": true, "label": "Occurred On", |
| 9 | "help": "When it happened, as best anybody knows."}, |
| 10 | {"name": "discovered_on", "type": "date", "label": "Discovered On"}, |
| 11 | {"name": "kind", "type": "enum", "required": true, "label": "Kind", |
| 12 | "enum": ["theft", "damage", "casualty", "spoilage", "evaporation", "shrinkage", "other"], |
| 13 | "help": "casualty: fire, flood, storm, a burst pipe -- sudden and from outside. spoilage: it went off. evaporation: a liquid lost volume in storage. shrinkage: missing, cause unknown."}, |
| 14 | {"name": "subject", "type": "enum", "required": true, "label": "What Kind Of Thing", |
| 15 | "enum": ["inventory", "equipment", "other"]}, |
| 16 | {"name": "what", "type": "text", "required": true, "label": "What Was Lost", "validation": {"min_length": 1, "max_length": 300}}, |
| 17 | {"name": "how_discovered", "type": "textarea", "required": true, "label": "How It Was Discovered"}, |
| 18 | {"name": "evidence_refs", "type": "textarea", "label": "Evidence", |
| 19 | "validation": {"required_when": {"status": ["approved"]}}, |
| 20 | "help": "Photos, a police report number, the count sheet, the adjuster's report: references, or files attached to this record. Required to approve."}, |
| 21 | {"name": "estimated_amount_cents", "type": "integer", "label": "Estimated Amount (cents)", "validation": {"min": 0}}, |
| 22 | {"name": "final_amount_cents", "type": "integer", "label": "Final Amount (cents)", "validation": {"min": 0, |
| 23 | "required_when": {"status": ["approved"]}}, |
| 24 | "help": "At cost, not at selling price. Required to approve."}, |
| 25 | {"name": "product_id", "type": "relation", "label": "Product", |
| 26 | "relation": {"collection": "products", "display_field": "name", "requires": "read"}}, |
| 27 | {"name": "stock_move_id", "type": "relation", "label": "Stock Move", |
| 28 | "relation": {"collection": "stock_moves", "display_field": "reference", "requires": "read"}, |
| 29 | "help": "Inventory: the loss move that took it off the shelf (and booked it)."}, |
| 30 | {"name": "asset_id", "type": "relation", "label": "Fixed Asset", |
| 31 | "relation": {"collection": "fixed_assets", "display_field": "name", "requires": "read"}, |
| 32 | "help": "Equipment: the asset. Its disposal books the loss."}, |
| 33 | {"name": "journal_id", "type": "relation", "label": "Linked Journal", |
| 34 | "relation": {"collection": "fin_journals", "display_field": "description", "requires": "read"}, |
| 35 | "help": "A journal entered by hand that already books this loss."}, |
| 36 | {"name": "write_off_account_id", "label": "Written Off From", |
| 37 | "relation": {"collection": "fin_accounts", "display_field": "name", "requires": "update"}, |
| 38 | "help": "Only for a loss nothing else books (cash, a deposit): the account it came out of. Approval books DR loss / CR this account."}, |
| 39 | {"name": "loss_account_id", "label": "Loss Account", |
| 40 | "relation": {"collection": "fin_accounts", "display_field": "name", "requires": "update"}, |
| 41 | "help": "Blank: losses.journal.<kind>_account, else losses.journal.loss_account."}, |
| 42 | {"name": "insurance_status", "type": "enum", "label": "Insurance", "default": "none", |
| 43 | "enum": ["none", "claimed", "paid", "denied"], |
| 44 | "transitions": {"none": ["claimed", "paid"], "claimed": ["paid", "denied"], "denied": ["claimed"]}}, |
| 45 | {"name": "insurance_claim_ref", "type": "text", "label": "Claim Reference", "validation": {"max_length": 200}}, |
| 46 | {"name": "insurance_recovery_cents", "type": "integer", "label": "Insurance Recovery (cents)", |
| 47 | "validation": {"min": 0, "required_when": {"insurance_status": ["paid"]}}}, |
| 48 | {"name": "recovered_on", "type": "date", "label": "Recovered On", |
| 49 | "validation": {"required_when": {"insurance_status": ["paid"]}}}, |
| 50 | {"name": "status", "type": "enum", "label": "Status", "default": "reported", |
| 51 | "enum": ["reported", "approved", "rejected"], |
| 52 | "transitions": {"reported": ["approved", "rejected"], "rejected": ["reported"]}, |
| 53 | "help": "Approved by somebody other than the person who reported it. Approved is final."}, |
| 54 | {"name": "reported_by", "type": "text", "label": "Reported By", |
| 55 | "help": "Stamped from the signed-in user when the loss is recorded; never typed."}, |
| 56 | {"name": "approved_by", "type": "text", "label": "Approved By", |
| 57 | "help": "Stamped from the signed-in user at approval; never typed."}, |
| 58 | {"name": "approved_at", "type": "datetime", "label": "Approved At"}, |
| 59 | {"name": "writeoff_journal_id", "type": "text", "label": "Write-off Journal", "read_only": true}, |
| 60 | {"name": "recovery_journal_id", "type": "text", "label": "Recovery Journal", "read_only": true}, |
| 61 | {"name": "notes", "type": "textarea", "label": "Notes"}, |
| 62 | {"name": "owner_id", "type": "text", "label": "Owner"}, |
| 63 | {"name": "entity_id", "type": "text", "label": "Entity", |
| 64 | "relation": {"collection": "entities", "display_field": "name", "requires": "update"}}, |
| 65 | {"name": "created_at", "type": "datetime", "label": "Created", "read_only": true} |
| 66 | ], |
| 67 | "hooks": {"before_write": "hook_loss_events"}, |
| 68 | "locked_when": [ |
| 69 | {"when": {"status": ["approved"]}, |
| 70 | "except": ["notes", "insurance_status", "insurance_claim_ref", "insurance_recovery_cents", "recovered_on"], |
| 71 | "message": "This loss is approved and on the books. Only the insurance claim's progress and notes may change; correct anything else with a new loss event or a reversing journal."}, |
| 72 | {"when": {"status": ["approved"], "insurance_status": ["paid"]}, "except": ["notes"], |
| 73 | "message": "The insurer has paid and the recovery is on the books. Only notes may change."} |
| 74 | ], |
| 75 | "locked_checks": [ |
| 76 | {"name": "approval", "object": "hook_loss_events", "function": "LOCKED_CHECK", |
| 77 | "on": {"create": true, "update": true, "delete": false}} |
| 78 | ], |
| 79 | "capabilities": {"comments": true, "attachments": true}, |
| 80 | "forms": {"default": {"fields": ["occurred_on", "discovered_on", "kind", "subject", "what", "how_discovered", |
| 81 | "evidence_refs", "estimated_amount_cents", "final_amount_cents", |
| 82 | "product_id", "stock_move_id", "asset_id", "journal_id", |
| 83 | "write_off_account_id", "loss_account_id", "insurance_status", |
| 84 | "insurance_claim_ref", "insurance_recovery_cents", "recovered_on", |
| 85 | "status", "notes"]}}, |
| 86 | "views": {"list_mode": "table", |
| 87 | "list_fields": ["occurred_on", "kind", "subject", "what", "estimated_amount_cents", |
| 88 | "final_amount_cents", "insurance_status", "status", "reported_by", "approved_by"], |
| 89 | "filter_fields": ["status", "kind", "subject", "insurance_status"]}, |
| 90 | "search": {"fields": ["what", "how_discovered", "evidence_refs", "insurance_claim_ref", "notes"]} |
| 91 | } |