feat: delivery areas and fee rules with "test an order" (platform-v2 3S, S.3)

- models/fees.py + Alembic 0018: delivery_areas, fee_rules; key connect_orders.fees
  (owner, store manager; existing ones get it).
- services/fees.py: the pure engine (set / add / % / free / minimum, conditions: sales
  points, areas, products total, item count, days, time incl. past midnight, stop), the
  same file as the cloud's; tests/fixtures/fee_cases.json shared, plus a test that the
  cloud copy is identical.
- routers/fees.py at /api/connect/fees: areas and rules CRUD (validated), order, preview.
- Snapshot carries fees + the venue's time zone; a change to products, pricing or fees
  pushes the menu within ~5 s (middleware -> cloud_sync.request_menu_push).
- Manager: Online -> Delivery fees page (@xenia/ui): rules in order with words for each,
  areas with postcodes, "Test an order"; en/el texts; feesLogic.js unit-tested.
- Tests: test_fees.py (39), manager unit +5, manager.mjs +7 on the real page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 12:28:29 +02:00
co-authored by Claude Opus 5.5
parent ffeb2b45cb
commit 9bfe54554d
24 changed files with 1723 additions and 9 deletions
+6
View File
@@ -97,5 +97,11 @@
"invalid": "This refund doesn't add up ({{reason}}).",
"too_old": "Only payments from today's business day can be refunded at the counter.",
"items_changed": "Some of these items were refunded in the meantime. Check the order and try again."
},
"fees": {
"area_not_found": "Delivery area {{area_id}} not found.",
"rule_not_found": "Fee rule {{rule_id}} not found.",
"area_in_use": "This area is used by fee rules: {{rules}}. Change those rules first.",
"order_invalid": "The new order must list every rule once."
}
}
+141 -1
View File
@@ -44,7 +44,8 @@
"license": "License",
"devices": "Devices",
"sessions": "Signed in now",
"approvals": "Manager approvals"
"approvals": "Manager approvals",
"deliveryFees": "Delivery fees"
},
"profile": {
"edit": "Edit profile",
@@ -369,5 +370,144 @@
"language": "Staff language",
"timezone": "Time zone",
"languageHint": "The language of staff screens (each person can choose their own) and of printed tickets and reports."
},
"fees": {
"title": "Delivery areas and fees",
"intro": "Fees for online orders, looked at from the top: every rule whose conditions hold changes the fee, or refuses the order below a minimum. The customer sees the fee before ordering, and the online checkout charges exactly what \"Test an order\" shows. Without rules there is no fee.",
"rules": "Fee rules",
"addRule": "Add a rule",
"editRule": "Edit rule",
"noRules": "No fee rules",
"noRulesBody": "Online orders are charged no fee. Add a rule for a delivery fee, a minimum order or free delivery above an amount.",
"areas": "Delivery areas",
"addArea": "Add an area",
"editArea": "Edit area",
"noAreas": "No areas: deliveries are accepted to any address. Add areas to deliver only there and to charge by area.",
"byNameOnly": "Picked by name (no postcodes)",
"areaName": "Name",
"areaNameHint": "What customers pick, e.g. a village or a neighbourhood",
"postcodes": "Postcodes",
"postcodesHint": "Optional, separated by commas. A customer who types one of these is in this area.",
"postcode": "Postcode",
"areaActive": "We deliver here",
"edit": "Edit",
"delete": "Delete",
"up": "Move up",
"down": "Move down",
"active": "On",
"save": "Save",
"cancel": "Cancel",
"saved": "Saved",
"deleted": "Deleted",
"deleteArea": "Delete the area \"{{name}}\"?",
"deleteRule": "Delete the rule \"{{name}}\"?",
"deleteBody": "Online orders use the rules as they are after this, within a few seconds.",
"when": "When:",
"then": "Then:",
"stopShort": "stop here",
"cond": {
"areas": "area {{names}}",
"subtotalBetween": "products {{minMoney}} to under {{maxMoney}}",
"subtotalFrom": "products {{minMoney}} or more",
"subtotalBelow": "products under {{maxMoney}}",
"itemsBetween": "{{min}} to {{max}} items",
"itemsFrom": "{{min}} items or more",
"itemsUpTo": "up to {{max}} items",
"days": "{{days}}",
"time": "{{from}}–{{to}}"
},
"do": {
"set": "the fee is {{value}}",
"add": "add {{value}} to the fee",
"percent": "add {{value}} % of the products",
"free": "no fee",
"minimum": "refuse orders under {{value}}"
},
"ruleName": "Name",
"ruleNameHint": "For you, e.g. \"Delivery\", \"Free over €25\"",
"what": "What it does",
"action": {
"set": "Set the fee to",
"add": "Add to the fee",
"percent": "Add a % of the products",
"free": "No fee (free delivery)",
"minimum": "Minimum order"
},
"valueLabel": {
"set": "Fee in euros",
"add": "Amount in euros",
"percent": "Percent",
"minimum": "Minimum in euros"
},
"actionHint": {
"set": "Replaces the fee so far. Use it for the base delivery fee.",
"add": "Added to the fee so far (a negative amount lowers it), e.g. a surcharge for a far area or a big order.",
"percent": "A percentage of the products' total, added to the fee.",
"free": "The fee becomes 0. Usually with \"stop here\", e.g. free delivery over an amount.",
"minimum": "Orders whose products cost less are refused; the customer is told the minimum."
},
"salesPoints": "For",
"conditions": "Only when (all that you fill in)",
"conditionsHint": "Leave empty for always.",
"onlyAreas": "Delivery areas",
"subtotalMin": "Products from (€)",
"subtotalMax": "Products under (€)",
"itemsMin": "Items from",
"itemsMax": "Items up to",
"onlyDays": "Days",
"timeFrom": "From",
"timeTo": "Until",
"timeHint": "An end before the start runs past midnight (e.g. 22:00–02:00).",
"stop": "Stop here",
"stopHint": "When this rule applies, the rules below it are not looked at.",
"problem": {
"name": "Give the rule a name.",
"value": "Enter an amount.",
"negative": "Only \"Add to the fee\" takes a negative amount.",
"percent": "A percentage is at most 100.",
"subtotalRange": "The lower amount must be below the upper one.",
"itemsRange": "The lower count must not be above the upper one.",
"times": "Give both times, or neither.",
"salesPoints": "Pick at least one."
},
"dayShort": {
"0": "Mon",
"1": "Tue",
"2": "Wed",
"3": "Thu",
"4": "Fri",
"5": "Sat",
"6": "Sun"
},
"dayLong": {
"0": "Monday",
"1": "Tuesday",
"2": "Wednesday",
"3": "Thursday",
"4": "Friday",
"5": "Saturday",
"6": "Sunday"
},
"test": "Test an order",
"testSalesPoint": "Ordered as",
"testWhere": "Where",
"testByArea": "Pick an area",
"testByPostcode": "Type a postcode",
"testNoArea": "No area",
"testSubtotal": "Products (€)",
"testItems": "Items",
"testDay": "Day",
"testTime": "Time",
"now": "Now",
"testRun": "Work out the fee",
"testFee": "Fee:",
"testTotal": "Total with products: {{total}}",
"testArea": "Area: {{name}}",
"testApplied": "Rules applied: {{names}}",
"testNone": "No rule applied.",
"refused": {
"minimum_not_met": "Refused: the minimum order is {{minimum}}.",
"area_not_served": "Refused: no delivery to this address."
}
}
}
+2 -1
View File
@@ -37,7 +37,8 @@
"name": "Online orders",
"description": "Orders placed from the QR menu, brought in from the cloud.",
"permissions": {
"manage": "Accept and manage online orders"
"manage": "Accept and manage online orders",
"fees": "Set delivery areas and fees"
}
},
"connect_remote": {