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

0 downloads

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.

danq9 signup: the person chooses the password and name on the confirm page 83c7aa6 2 weeks, 5 days ago History
promotions.json · 6.6 KB · 54 lines
1{
2 "name": "promotions",
3 "title": "Promotions",
4 "version": 1,
5 "description": "A code somebody types at checkout, and the terms it buys them. Two decisions carry this schema. FIRST, redemptions_used is a ROLLUP over promotion_redemptions and nothing may write it -- the identical argument wallets.balance_minor makes about wallet_entries: a mutable counter beside a log of uses is two truths that drift, and when they drift the customer holding a receipt is right and you cannot prove otherwise. object_promotions.blockers counts the redemption ROWS rather than reading this caption, because a gate must be authoritative and a derived number it could recompute is not. SECOND, a promotion VERSIONS FORWARD like rate_cards and billing_plans: re-running a campaign on new terms is a NEW ROW with a later starts_on, never an edit, because the terms are stamped on the redemption at use and last month's receipts must forever say what last month's shopper was actually given (docs/logic-decisions.md #1). Two rows may share a code; object_promotions.resolve picks the newest one that had already started and never looks forward. The code is compared case-insensitively at redemption because a code is something a human retypes off a postcard, and losing a sale to a shift key is not a policy anybody chose. value carries basis points for percent (2000 = 20%) and integer cents for fixed, matching invoice_lines' own bps convention and this repo's integer-minor-units doctrine (docs/logic-decisions.md #10); free_shipping ignores value entirely, because 'free shipping worth up to five dollars' is a fixed discount wearing a costume and deserves to be typed as one. stacking is honoured by the fold and not yet exercised by the shop, which applies one code per basket -- named here so it reads as a decision rather than a field nobody wired up.",
6 "fields": [
7 {"name": "id"},
8 {"name": "code", "type": "text", "required": true, "label": "Code",
9 "validation": {"max_length": 40},
10 "help": "What the shopper types. Stored as the seller wrote it, COMPARED upper-cased and trimmed, so SPRING20 and spring20 are the same code. Uniqueness is per version, not absolute: a second row with the same code and a later starts_on is a re-run of the campaign on new terms, which is exactly how a promotion changes without restating anybody's receipt."},
11 {"name": "kind", "type": "enum", "required": true, "default": "percent",
12 "label": "Kind", "enum": ["percent", "fixed", "free_shipping"],
13 "help": "percent takes basis points off the goods; fixed takes cents off the goods; free_shipping takes the postage off and nothing else. The split matters for TAX: a goods discount reduces the taxable base, free postage reduces the postage (and, where a jurisdiction taxes delivery, that tax with it)."},
14 {"name": "value", "type": "integer", "default": "0", "label": "Value",
15 "help": "Basis points when kind is percent (2000 = 20%), integer cents when kind is fixed, ignored when kind is free_shipping. Never a float and never a percentage sign: the same integer-minor-units doctrine as every other number in this building."},
16 {"name": "minimum_spend_cents", "type": "integer", "default": "0",
17 "label": "Minimum Spend",
18 "help": "The basket has to reach this before the code applies. 0 means no minimum. Measured on GOODS, before postage and before tax, because that is the number a shopper can see on the basket page and check for themselves."},
19 {"name": "starts_on", "type": "date", "label": "Starts",
20 "help": "The day this version comes into force. Blank means it has always applied. Resolution never looks forward: a row starting next month cannot discount today's basket, however loudly somebody types its code."},
21 {"name": "ends_on", "type": "date", "label": "Ends",
22 "help": "The last day it applies, inclusive. Blank means it never expires. An expired code is refused WITH THIS DATE -- 'that code ended on the 30th of June' ends the conversation, 'that code has expired' starts a support ticket."},
23 {"name": "max_redemptions", "type": "integer", "default": "0",
24 "label": "Total Limit",
25 "help": "How many times this code may be used in all. 0 means unlimited. Enforced by COUNTING promotion_redemptions rows, never by reading redemptions_used below."},
26 {"name": "redemptions_used", "type": "computed", "label": "Used",
27 "rollup": {"collection": "promotion_redemptions", "fk_field": "promotion_id",
28 "op": "count"},
29 "help": "Derived, never written: how many redemption rows name this promotion. If this and the rows ever disagreed the rows would be right, which is why nothing may set it and why the gate does not read it."},
30 {"name": "per_customer_limit", "type": "integer", "default": "0",
31 "label": "Per Customer",
32 "help": "How many times one email address may use it. 0 means unlimited. Matched case-insensitively on the address, because a limit that a capital letter walks around is not a limit."},
33 {"name": "stacking", "type": "enum", "default": "never", "label": "Stacking",
34 "enum": ["never", "with_others"],
35 "help": "Whether this code may be combined with another promotion. Default never, which is the safe direction: two codes that were each meant to be the whole offer add up to a discount nobody signed off. The shop applies one code per basket today, so this is honoured by object_promotions.blockers and not yet reached from checkout."},
36 {"name": "is_active", "type": "boolean", "default": "true", "label": "Active",
37 "help": "Switching a promotion off stops it applying to NEW baskets. It never restates a redemption already made -- the terms of that one are stamped on its own row."},
38 {"name": "notes", "type": "textarea", "label": "Notes",
39 "help": "Where the code was published, who asked for it, what it was meant to do. The context that makes a stale promotion safe to retire."},
40 {"name": "owner_id", "type": "text", "label": "Owner"},
41 {"name": "entity_id", "type": "text", "label": "Entity",
42 "relation": {"collection": "entities", "display_field": "name"}},
43 {"name": "created_at", "type": "datetime", "read_only": true, "label": "Created"}
44 ],
45 "search": {"fields": ["code", "notes"]},
46 "forms": {"default": {"fields": ["code", "kind", "value", "minimum_spend_cents",
47 "starts_on", "ends_on", "max_redemptions",
48 "per_customer_limit", "stacking",
49 "is_active", "notes"]}},
50 "views": {"list_mode": "table",
51 "list_fields": ["code", "kind", "value", "starts_on", "ends_on",
52 "redemptions_used", "is_active"],
53 "filter_fields": ["kind", "is_active"]}
54}