feat: delivery areas drawn on a map: the customer pins the address (plan 6R.G)

- services/fees.py: the site's engine (shapes matched by the pin), shared cases
- checkout: price_cart(pin=), delivery_areas with kind (+ geometry for shapes),
  venue_point in the public menu (postcodes and rules stay on the cloud)
- orders: quote / create take lat / lng; online_orders.lat / lng (Alembic 0007),
  sent to the site with the pending orders
- order app: PinMap (Leaflet + OpenStreetMap tiles), 'Pin it on the map' first
  when the venue drew areas, the browser's location offered; lat / lng sent
- tests: cloud test_fees (pinned quote and order), order-app logic

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 21:56:13 +02:00
co-authored by Claude Opus 5.5
parent e55157fa86
commit d5b8492512
17 changed files with 406 additions and 41 deletions
@@ -101,3 +101,22 @@ test('a dish\'s allergens by level (6.3)', () => {
assert.deepEqual(allergensOf({ allergens: { sesame: 'may_contain', milk: 'contains', gluten: 'contains' } }), { contains: ['gluten', 'milk'], may_contain: ['sesame'] })
assert.deepEqual(allergensOf({ allergens: ['gluten'] }), { contains: [], may_contain: [] })
})
test('6R.G: where the delivery goes: a pin when the venue drew areas', async () => {
const { areaKinds, whereOptions } = await import('../src/logic.js')
const areas = [{ id: 1, name: 'Centre', kind: 'postcodes' }, { id: 2, name: 'Drawn', kind: 'polygon', geometry: [[37, 22], [37, 22.1], [37.1, 22]] },
{ id: 3, name: 'Ring', kind: 'circle', geometry: { center: [37, 22], radius_m: 900 } }, { id: 4, name: 'Old style' }]
assert.deepEqual(areaKinds(areas).listed.map(a => a.id), [1, 4])
assert.deepEqual(areaKinds(areas).shapes.map(a => a.id), [2, 3])
assert.deepEqual(whereOptions(areas), ['map', 'area', 'postcode'])
assert.deepEqual(whereOptions([areas[0]]), ['area', 'postcode'])
assert.deepEqual(whereOptions([]), ['postcode'])
const form = { name: 'Maria', phone: '6911111111', address: 'Harbour 7', notes: '', postcode: '', areaId: '', where: 'map', pin: null, when: 'asap' }
assert.deepEqual(checkoutProblems(form, 'delivery', { areas, asap: true }), ['pin'])
const pinned = { ...form, pin: [37.05, 22.05] }
assert.deepEqual(checkoutProblems(pinned, 'delivery', { areas, asap: true }), [])
const body = orderBody(pinned, 'delivery', [], null)
assert.deepEqual([body.lat, body.lng, body.area_id, body.postcode], [37.05, 22.05, null, null])
assert.deepEqual([orderBody(pinned, 'takeaway', [], null).lat, orderBody({ ...pinned, where: 'postcode' }, 'delivery', [], null).lng], [undefined, undefined])
})