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.
invoice_credits.json · 3.0 KB · 29 lines
| 1 | { |
| 2 | "name": "invoice_credits", |
| 3 | "title": "Invoice Credits", |
| 4 | "version": 3, |
| 5 | "description": "A credit note applied: credit_note_id is the credit note (an invoices row of doc_type credit_note), invoice_id the invoice it reduces, or blank while the credit stands on the customer's account. One row is the whole act, and it moves two derived numbers at once: the invoice's credited_cents (so its balance_due_cents falls by the credit) and the credit note's own credit_applied_cents (so a credit note never reads as a balance the customer owes us -- the two-company simulation found exactly that). Neither number is stored by hand: both are rollups over these rows (logic-decisions: money never mutates, it moves). Credits are not payments: amount_paid_cents does not move. The invoice's status follows the money (v3, the owner's decision of 2026-11-30): system_invoice_status reads credits with payments and refunds, so a fully credited invoice reads credited, one credited and paid back reads refunded, and a credit on a paid bill reads credit_owed until the money goes back. Sending a credit note to a partner's box (app-exchange) applies it as its document says, so the partner's books and ours reduce the same invoice by the same amount; a row made that way (source exchange) is frozen. Staff's, like invoice money. v2: source counter, the row app-counter's action_counter_correct writes in the same act that issues a credit note at the counter, so a counter credit note lowers the credited invoice's balance exactly as one sent through the exchange does (and sending it later applies nothing twice); locked like an exchange row.", |
| 6 | "fields": [ |
| 7 | {"name": "id"}, |
| 8 | {"name": "credit_note_id", "type": "relation", "required": true, "label": "Credit Note", |
| 9 | "relation": {"collection": "invoices", "display_field": "number", "requires": "update"}}, |
| 10 | {"name": "invoice_id", "type": "relation", "label": "Invoice Credited", |
| 11 | "help": "Blank: the credit stands on the customer's account until it is applied.", |
| 12 | "relation": {"collection": "invoices", "display_field": "number", "requires": "update"}}, |
| 13 | {"name": "amount_cents", "type": "integer", "required": true, "label": "Amount", |
| 14 | "validation": {"min": 1}}, |
| 15 | {"name": "applied_on", "type": "date", "label": "Applied On"}, |
| 16 | {"name": "source", "type": "enum", "default": "manual", "enum": ["manual", "exchange", "counter"], |
| 17 | "label": "Source"}, |
| 18 | {"name": "owner_id", "type": "text"}, |
| 19 | {"name": "created_at", "type": "datetime", "read_only": true, "label": "Created"} |
| 20 | ], |
| 21 | "locked_when": [ |
| 22 | {"when": {"source": "exchange"}, "except": [], |
| 23 | "message": "This credit was applied as the signed credit note sent to the customer's box says."}, |
| 24 | {"when": {"source": "counter"}, "except": [], |
| 25 | "message": "This credit was applied by the counter in the act that issued the credit note, citing the item it corrects. A correction to it is another credit note, not an edit."} |
| 26 | ], |
| 27 | "views": {"list_mode": "table", |
| 28 | "list_fields": ["credit_note_id", "invoice_id", "amount_cents", "applied_on"]} |
| 29 | } |