feat: sales points, offerings and prices per sales point (platform-v2 phase 3S, step S.1)
- core/sales_points.py: in_store, in_store_takeaway, qr_table, online_takeaway, online_delivery, online_preorder (+ old channel names mapped). - Alembic 0017: orders.sales_point (backfilled), products.sold_at (from digital_visible), digital_price/digital_discount -> item price modifiers for the QR menu and online, order_channel conditions -> sales points; drops the three digital columns. - Every order records its sales point; the pricing engine's channel is it; items not sold there are refused (order.not_sold_here, pos.line_invalid not_sold_here). - POS menu: only what the counter sells, prices per counter sales point; the screen shows the order type's products and prices. Waiter app asks for in-person products. - Cloud snapshot: products sold by the customer apps, priced by the engine. - Manager: product "Where it's sold" tab; pricing condition shows sales points. - Products API, catalogue export/import carry sold_at. - Tests: test_sales_points.py (8, incl. the migration), access +1, terminal +1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,8 @@ import { useState, useEffect, useRef } from 'react'
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import toast from 'react-hot-toast'
|
||||
import client from '../../api/client'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { SALES_POINTS } from '@xenia/access'
|
||||
|
||||
// ── Small helpers ─────────────────────────────────────────────────────────────
|
||||
function moveItem(arr, i, dir) {
|
||||
@@ -195,13 +197,11 @@ function buildFormFromProduct(product) {
|
||||
allow_multi_select: ps.allow_multi_select ?? false,
|
||||
allow_choice_quantity: ps.allow_choice_quantity ?? false,
|
||||
})) ?? [],
|
||||
digital_visible: product.digital_visible ?? true,
|
||||
sold_at: product.sold_at ?? [...SALES_POINTS],
|
||||
digital_available: product.digital_available ?? true,
|
||||
digital_name: product.digital_name ?? '',
|
||||
digital_description: product.digital_description ?? '',
|
||||
digital_image_url: product.digital_image_url ?? '',
|
||||
digital_price: product.digital_price ?? '',
|
||||
digital_discount: product.digital_discount ?? '',
|
||||
// Phase 2A — cost tracking
|
||||
cost_mode: product.cost_breakdown?.length ? 'detailed' : 'simple',
|
||||
cost_simple: product.cost_simple ?? '',
|
||||
@@ -556,13 +556,11 @@ export default function ProductFormModal({ product, categories, printers, prepZo
|
||||
allow_multi_select: ps.allow_multi_select ?? false,
|
||||
allow_choice_quantity: ps.allow_choice_quantity ?? false,
|
||||
})),
|
||||
digital_visible: form.digital_visible,
|
||||
sold_at: form.sold_at,
|
||||
digital_available: form.digital_available,
|
||||
digital_name: form.digital_name || null,
|
||||
digital_description: form.digital_description || null,
|
||||
digital_image_url: form.digital_image_url || null,
|
||||
digital_price: form.digital_price !== '' ? parseFloat(form.digital_price) : null,
|
||||
digital_discount: form.digital_discount !== '' ? parseFloat(form.digital_discount) : null,
|
||||
// Phase 2A — cost tracking
|
||||
cost_simple: form.cost_mode === 'simple' && form.cost_simple !== '' ? parseFloat(form.cost_simple) : null,
|
||||
cost_breakdown: form.cost_mode === 'detailed' && form.cost_breakdown.length > 0
|
||||
@@ -642,7 +640,7 @@ export default function ProductFormModal({ product, categories, printers, prepZo
|
||||
{[
|
||||
{ key: 'info', label: 'Πληροφορίες' },
|
||||
...(!form.is_service_item ? [
|
||||
{ key: 'digital', label: 'Digital Menu' },
|
||||
{ key: 'digital', label: 'Πού πωλείται' },
|
||||
{ key: 'cost', label: 'Κόστος' },
|
||||
...(fiscalEnabled ? [{ key: 'fiscal', label: 'Ταμειακή' }] : []),
|
||||
] : []),
|
||||
@@ -842,90 +840,8 @@ export default function ProductFormModal({ product, categories, printers, prepZo
|
||||
</div>}
|
||||
</>)}
|
||||
|
||||
{/* Tab 2: Digital Menu */}
|
||||
{leftTab === 'digital' && (() => {
|
||||
const basePrice = parseFloat(form.base_price) || 0
|
||||
const dp = form.digital_price !== '' ? parseFloat(form.digital_price) : null
|
||||
const disc = form.digital_discount !== '' ? parseFloat(form.digital_discount) : null
|
||||
let customerPrice = basePrice
|
||||
if (dp !== null && !isNaN(dp)) customerPrice = dp
|
||||
else if (disc !== null && !isNaN(disc) && disc > 0) customerPrice = Math.round(basePrice * (1 - disc / 100) * 100) / 100
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<p className="text-xs font-semibold text-gray-400 uppercase tracking-widest mb-3">Ορατότητα</p>
|
||||
<div className="space-y-3">
|
||||
<label className="flex items-center gap-3 cursor-pointer select-none">
|
||||
<input type="checkbox" checked={form.digital_visible}
|
||||
onChange={e => setField('digital_visible', e.target.checked)}
|
||||
className="w-4 h-4 accent-primary-700" />
|
||||
<span className="text-sm font-medium text-gray-700">Show on digital menu</span>
|
||||
</label>
|
||||
<div>
|
||||
<label className="flex items-center gap-3 cursor-pointer select-none">
|
||||
<input type="checkbox" checked={form.digital_available}
|
||||
onChange={e => setField('digital_available', e.target.checked)}
|
||||
className="w-4 h-4 accent-primary-700" />
|
||||
<span className="text-sm font-medium text-gray-700">Available for ordering</span>
|
||||
</label>
|
||||
<p className="text-xs text-gray-400 mt-1 ml-7">Uncheck to show as ‘Out of stock’</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p className="text-xs font-semibold text-gray-400 uppercase tracking-widest mb-1">Display overrides</p>
|
||||
<p className="text-xs text-gray-400 mb-3">Leave blank to use the standard product value</p>
|
||||
<div className="space-y-3">
|
||||
<div>
|
||||
<label className="label">Display name (override)</label>
|
||||
<input className="input" value={form.digital_name}
|
||||
onChange={e => setField('digital_name', e.target.value)}
|
||||
placeholder={form.name || 'Leave blank to use product name'} />
|
||||
</div>
|
||||
<div>
|
||||
<label className="label">Description</label>
|
||||
<textarea className="input resize-none" rows={3}
|
||||
value={form.digital_description}
|
||||
onChange={e => setField('digital_description', e.target.value)}
|
||||
placeholder="Leave blank to use product description"
|
||||
style={{ lineHeight: 1.5, fontSize: 13 }} />
|
||||
</div>
|
||||
<div>
|
||||
<label className="label">Image URL</label>
|
||||
<input className="input" value={form.digital_image_url}
|
||||
onChange={e => setField('digital_image_url', e.target.value)}
|
||||
placeholder="https://…" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p className="text-xs font-semibold text-gray-400 uppercase tracking-widest mb-3">Pricing</p>
|
||||
<div className="space-y-3">
|
||||
<div>
|
||||
<label className="label">Online price (override)</label>
|
||||
<input type="number" step="0.01" min="0" className="input w-40"
|
||||
value={form.digital_price}
|
||||
onChange={e => setField('digital_price', e.target.value)}
|
||||
placeholder="e.g. 9.50" />
|
||||
</div>
|
||||
<div>
|
||||
<label className="label">Discount %</label>
|
||||
<input type="number" step="1" min="0" max="100" className="input w-40"
|
||||
value={form.digital_discount}
|
||||
onChange={e => setField('digital_discount', e.target.value)}
|
||||
placeholder="e.g. 10 for 10% off" />
|
||||
</div>
|
||||
<div className="rounded-lg bg-green-50 border border-green-200 px-4 py-3 text-sm text-green-800">
|
||||
Customer sees: <span className="font-bold">€{customerPrice.toFixed(2)}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})()}
|
||||
{/* Tab 2: where it's sold (phase 3S) and what the customer apps show */}
|
||||
{leftTab === 'digital' && <SoldAtTab form={form} setField={setField} />}
|
||||
|
||||
{/* Tab 3: Cost */}
|
||||
{leftTab === 'cost' && (
|
||||
@@ -1423,3 +1339,74 @@ export default function ProductFormModal({ product, categories, printers, prepZo
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// Where a product is sold (plan phase 3S): one checkbox per sales point, the customer apps'
|
||||
// display overrides, and where prices per sales point live (price rules, not fields here).
|
||||
function SoldAtTab({ form, setField }) {
|
||||
const { t } = useTranslation('common')
|
||||
const toggle = sp => setField('sold_at', form.sold_at.includes(sp)
|
||||
? form.sold_at.filter(x => x !== sp)
|
||||
: SALES_POINTS.filter(x => x === sp || form.sold_at.includes(x)))
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<p className="text-xs font-semibold text-ink-3 uppercase tracking-widest mb-1">Πού πωλείται</p>
|
||||
<p className="text-xs text-ink-3 mb-3">Όπου δεν είναι επιλεγμένο, το προϊόν δεν εμφανίζεται και δεν γίνεται δεκτό σε παραγγελίες.</p>
|
||||
<div className="space-y-2" data-testid="sold-at">
|
||||
{SALES_POINTS.map(sp => (
|
||||
<label key={sp} className="flex items-start gap-3 cursor-pointer select-none">
|
||||
<input type="checkbox" checked={form.sold_at.includes(sp)} onChange={() => toggle(sp)}
|
||||
className="w-4 h-4 mt-0.5 accent-accent" data-testid={`sold-at-${sp}`} />
|
||||
<span>
|
||||
<span className="block text-sm font-medium text-ink">{t(`salesPoints.${sp}.name`)}</span>
|
||||
<span className="block text-xs text-ink-3">{t(`salesPoints.${sp}.hint`)}</span>
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
<p className="text-xs text-ink-2 mt-3 rounded-lg bg-surface-2 border border-line px-3 py-2">
|
||||
Διαφορετική τιμή ανά σημείο πώλησης (π.χ. φθηνότερο σε πακέτο): Τιμολόγηση → Τροποποιητές, με συνθήκη «Κανάλι παραγγελίας».
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p className="text-xs font-semibold text-ink-3 uppercase tracking-widest mb-3">QR μενού και online</p>
|
||||
<div>
|
||||
<label className="flex items-center gap-3 cursor-pointer select-none">
|
||||
<input type="checkbox" checked={form.digital_available}
|
||||
onChange={e => setField('digital_available', e.target.checked)}
|
||||
className="w-4 h-4 accent-accent" />
|
||||
<span className="text-sm font-medium text-ink">Διαθέσιμο για παραγγελία τώρα</span>
|
||||
</label>
|
||||
<p className="text-xs text-ink-3 mt-1 ml-7">Ξετσεκάρετε για να εμφανίζεται ως «Εξαντλήθηκε».</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p className="text-xs font-semibold text-ink-3 uppercase tracking-widest mb-1">Εμφάνιση στους πελάτες</p>
|
||||
<p className="text-xs text-ink-3 mb-3">Αφήστε κενό για να χρησιμοποιηθούν τα στοιχεία του προϊόντος.</p>
|
||||
<div className="space-y-3">
|
||||
<div>
|
||||
<label className="label">Όνομα</label>
|
||||
<input className="input" value={form.digital_name}
|
||||
onChange={e => setField('digital_name', e.target.value)}
|
||||
placeholder={form.name || ''} />
|
||||
</div>
|
||||
<div>
|
||||
<label className="label">Περιγραφή</label>
|
||||
<textarea className="input resize-none" rows={3}
|
||||
value={form.digital_description}
|
||||
onChange={e => setField('digital_description', e.target.value)}
|
||||
style={{ lineHeight: 1.5, fontSize: 13 }} />
|
||||
</div>
|
||||
<div>
|
||||
<label className="label">Διεύθυνση εικόνας</label>
|
||||
<input className="input" value={form.digital_image_url}
|
||||
onChange={e => setField('digital_image_url', e.target.value)}
|
||||
placeholder="https://…" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { Plus, Gift, Power, Pencil, Trash2, X, Info } from 'lucide-react'
|
||||
import toast from 'react-hot-toast'
|
||||
import client from '../../../api/client'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { SALES_POINTS, normalizeSalesPoints } from '@xenia/access'
|
||||
import Button from '../../../ui/Button'
|
||||
import Modal from '../../../ui/Modal'
|
||||
import { ConfirmModal } from '../../../ui/Modal'
|
||||
@@ -31,12 +33,12 @@ const CONDITION_TYPES = [
|
||||
{ value: 'time_range', label: 'Ώρα ημέρας' },
|
||||
{ value: 'day_of_week', label: 'Ημέρα εβδομάδας' },
|
||||
{ value: 'date_range', label: 'Εύρος ημερομηνιών' },
|
||||
{ value: 'order_channel', label: 'Κανάλι παραγγελίας' },
|
||||
{ value: 'order_channel', label: 'Σημείο πώλησης' },
|
||||
{ value: 'price_group_active',label: 'Ομάδα τιμής ενεργή' },
|
||||
]
|
||||
|
||||
const DAYS = ['Δευτέρα','Τρίτη','Τετάρτη','Πέμπτη','Παρασκευή','Σάββατο','Κυριακή']
|
||||
const CHANNELS = ['pos','online','qr','takeaway']
|
||||
const CHANNELS = SALES_POINTS // phase 3S: the order_channel condition holds sales points
|
||||
|
||||
const ACTION_TYPES = [
|
||||
{ value: 'apply_modifier', label: 'Εφαρμογή τροποποιητή' },
|
||||
@@ -50,6 +52,7 @@ const ACTION_TYPES = [
|
||||
// ─── Reuse condition editor (simplified for deals) ────────────────────────────
|
||||
|
||||
function ConditionRow({ cond, onChange, onRemove, groups }) {
|
||||
const { t } = useTranslation('common')
|
||||
const set = (k, v) => onChange({ ...cond, params: { ...cond.params, [k]: v } })
|
||||
const setType = t => onChange({ condition_type: t, params: {} })
|
||||
|
||||
@@ -123,10 +126,10 @@ function ConditionRow({ cond, onChange, onRemove, groups }) {
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{CHANNELS.map(ch => (
|
||||
<button type="button" key={ch}
|
||||
onClick={() => { const channels = cond.params.channels ?? []; set('channels', channels.includes(ch) ? channels.filter(x => x !== ch) : [...channels, ch]) }}
|
||||
onClick={() => { const channels = normalizeSalesPoints(cond.params.channels); set('channels', channels.includes(ch) ? channels.filter(x => x !== ch) : [...channels, ch]) }}
|
||||
className={`px-2.5 py-1 rounded text-[11px] font-medium transition-colors ${
|
||||
(cond.params.channels ?? []).includes(ch) ? 'bg-sky-100 text-sky-700' : 'bg-white border border-slate-200 text-slate-500 hover:bg-slate-50'
|
||||
}`}>{ch}</button>
|
||||
normalizeSalesPoints(cond.params.channels).includes(ch) ? 'bg-sky-100 text-sky-700' : 'bg-white border border-slate-200 text-slate-500 hover:bg-slate-50'
|
||||
}`}>{t(`salesPoints.${ch}.name`)}</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -6,6 +6,8 @@ import {
|
||||
} from 'lucide-react'
|
||||
import toast from 'react-hot-toast'
|
||||
import client from '../../../api/client'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { SALES_POINTS, normalizeSalesPoints } from '@xenia/access'
|
||||
import Button from '../../../ui/Button'
|
||||
import Modal from '../../../ui/Modal'
|
||||
import { ConfirmModal } from '../../../ui/Modal'
|
||||
@@ -40,14 +42,14 @@ const CONDITION_TYPES = [
|
||||
{ value: 'min_item_quantity', label: 'Ελάχιστη ποσότητα προϊόντος' },
|
||||
{ value: 'min_category_qty', label: 'Ελάχιστη ποσότητα κατηγορίας' },
|
||||
{ value: 'min_order_value', label: 'Ελάχιστη αξία παραγγελίας' },
|
||||
{ value: 'order_channel', label: 'Κανάλι παραγγελίας' },
|
||||
{ value: 'order_channel', label: 'Σημείο πώλησης' },
|
||||
{ value: 'price_group_active', label: 'Ομάδα τιμής ενεργή' },
|
||||
{ value: 'user_tier', label: 'Επίπεδο πελάτη (placeholder)' },
|
||||
{ value: 'low_stock', label: 'Χαμηλό απόθεμα (placeholder)' },
|
||||
]
|
||||
|
||||
const DAYS = ['Δευτέρα','Τρίτη','Τετάρτη','Πέμπτη','Παρασκευή','Σάββατο','Κυριακή']
|
||||
const CHANNELS = ['pos','online','qr','takeaway']
|
||||
const CHANNELS = SALES_POINTS // phase 3S: the order_channel condition holds sales points
|
||||
|
||||
const ROUND_OPTIONS = [
|
||||
{ value: '', label: 'Χωρίς στρογγυλοποίηση' },
|
||||
@@ -62,6 +64,7 @@ const ROUND_OPTIONS = [
|
||||
// ─── Condition editor ─────────────────────────────────────────────────────────
|
||||
|
||||
function ConditionEditor({ cond, onChange, onRemove, groups, categories, prepZones }) {
|
||||
const { t } = useTranslation('common')
|
||||
const set = (k, v) => onChange({ ...cond, params: { ...cond.params, [k]: v } })
|
||||
const setType = t => onChange({ condition_type: t, params: {} })
|
||||
|
||||
@@ -175,12 +178,12 @@ function ConditionEditor({ cond, onChange, onRemove, groups, categories, prepZon
|
||||
{CHANNELS.map(ch => (
|
||||
<button type="button" key={ch}
|
||||
onClick={() => {
|
||||
const channels = cond.params.channels ?? []
|
||||
const channels = normalizeSalesPoints(cond.params.channels)
|
||||
set('channels', channels.includes(ch) ? channels.filter(x => x !== ch) : [...channels, ch])
|
||||
}}
|
||||
className={`px-2.5 py-1 rounded text-[11px] font-medium transition-colors ${
|
||||
(cond.params.channels ?? []).includes(ch) ? 'bg-sky-100 text-sky-700' : 'bg-white border border-slate-200 text-slate-500 hover:bg-slate-50'
|
||||
}`}>{ch}</button>
|
||||
normalizeSalesPoints(cond.params.channels).includes(ch) ? 'bg-sky-100 text-sky-700' : 'bg-white border border-slate-200 text-slate-500 hover:bg-slate-50'
|
||||
}`}>{t(`salesPoints.${ch}.name`)}</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user