feat(backend,waiter,terminal,manager): +1 on a sent line and changing a line's quantity
Owner 2026-11-23 (plan 6F.5). Product flag one_more_enabled (off by default; product editor).
POST /api/orders/{id}/items/{item}/again: a new line like the old one (choices, removed, note,
course), priced now, sent to the kitchen like any new line. Waiter app and the counter's table
panel: +1 beside such lines; the first tap arms it, more taps count up, 'Send +N' sends, 4 s idle
disarms (no stray sends).
POST /api/orders/{id}/items/{item}/quantity: venue setting orders.quantity_change (off | add_only |
add_and_remove, default off), key ordering.items.change_quantity (owner, store manager; Alembic 0049
grants it); up only changes the line, down cuts a cancelled part ('quantity lowered', split_from_id)
and prints a cancellation only when asked (the dialog presets yes while the kitchen hasn't finished).
Waiter: 'Change quantity' in a line's actions (now -> new, -/+). cut_part() now shared with split.
GET /api/orders/{id} items carry the product's one_more_enabled / unit_type, deal ids, split_from_id,
cancel_reason.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -222,6 +222,12 @@ CODES: dict[str, tuple[int, str]] = {
|
|||||||
"order.item_paid": (400, "This item is already paid."),
|
"order.item_paid": (400, "This item is already paid."),
|
||||||
"order.item_not_active": (400, "Only items still on the order can be changed."),
|
"order.item_not_active": (400, "Only items still on the order can be changed."),
|
||||||
"order.price_change_off": (403, "Changing prices by hand is turned off for this venue."),
|
"order.price_change_off": (403, "Changing prices by hand is turned off for this venue."),
|
||||||
|
"order.one_more_off": (400, "\"One more\" isn't turned on for this product."),
|
||||||
|
"order.one_more_line": (400, "This line can't be ordered again with one tap."),
|
||||||
|
"order.quantity_change_off": (403, "Changing quantities is turned off for this venue."),
|
||||||
|
"order.quantity_remove_off": (403, "Quantities can only go up at this venue."),
|
||||||
|
"order.quantity_invalid": (400, "Choose a whole number from 1 to {max}."),
|
||||||
|
"order.quantity_line": (400, "This line's quantity can't be changed here."),
|
||||||
"order.price_change_sent_off": (403, "Prices can only be changed before the items are sent."),
|
"order.price_change_sent_off": (403, "Prices can only be changed before the items are sent."),
|
||||||
"order.price_reason_required": (400, "Say why the price changes."),
|
"order.price_reason_required": (400, "Say why the price changes."),
|
||||||
"order.nothing_paid": (404, "There are no paid items to undo."),
|
"order.nothing_paid": (404, "There are no paid items to undo."),
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
"""One more and quantity changes (owner 2026-11-23, plan 6F.5).
|
||||||
|
|
||||||
|
- products.one_more_enabled (off: the owner turns it on per product).
|
||||||
|
- The key ordering.items.change_quantity for owners and store managers (the venue's setting
|
||||||
|
orders.quantity_change starts 'off').
|
||||||
|
|
||||||
|
Revision ID: 0049_one_more
|
||||||
|
Revises: 0048_order_moves
|
||||||
|
Create Date: 2026-11-23 18:00:00
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
revision = '0049_one_more'
|
||||||
|
down_revision = '0048_order_moves'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
with op.batch_alter_table('products') as b:
|
||||||
|
b.add_column(sa.Column('one_more_enabled', sa.Boolean(), nullable=False, server_default='0'))
|
||||||
|
op.get_bind().execute(sa.text("insert or ignore into user_permissions (user_id, key) "
|
||||||
|
"select id, 'ordering.items.change_quantity' from users where role in ('owner', 'store_manager')"))
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
op.get_bind().execute(sa.text("delete from user_permissions where key = 'ordering.items.change_quantity'"))
|
||||||
|
with op.batch_alter_table('products') as b:
|
||||||
|
b.drop_column('one_more_enabled')
|
||||||
@@ -82,6 +82,8 @@ class Product(Base):
|
|||||||
|
|
||||||
# Quick Add: allow adding 1 unit directly from product list without opening config modal
|
# Quick Add: allow adding 1 unit directly from product list without opening config modal
|
||||||
quick_add_enabled = Column(Boolean, default=True, nullable=False)
|
quick_add_enabled = Column(Boolean, default=True, nullable=False)
|
||||||
|
# "One more" (6F.5): a sent line of this product shows +1 (re-order the same, printed as new)
|
||||||
|
one_more_enabled = Column(Boolean, default=False, nullable=False, server_default="0")
|
||||||
|
|
||||||
# Service item: non-inventoried table-service items (cutlery, glasses, etc.)
|
# Service item: non-inventoried table-service items (cutlery, glasses, etc.)
|
||||||
is_service_item = Column(Boolean, default=False, nullable=False)
|
is_service_item = Column(Boolean, default=False, nullable=False)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ MODULE = Module(
|
|||||||
Perm('ordering.orders.cancel', 'Cancel items already sent', roles=('owner', 'store_manager'), overridable=True),
|
Perm('ordering.orders.cancel', 'Cancel items already sent', roles=('owner', 'store_manager'), overridable=True),
|
||||||
Perm('ordering.prices.modify', "Change an item's price before it is sent", roles=('owner',), overridable=True),
|
Perm('ordering.prices.modify', "Change an item's price before it is sent", roles=('owner',), overridable=True),
|
||||||
Perm('ordering.prices.modify_sent', "Change the price of an item already sent or served", roles=('owner',), overridable=True),
|
Perm('ordering.prices.modify_sent', "Change the price of an item already sent or served", roles=('owner',), overridable=True),
|
||||||
|
Perm('ordering.items.change_quantity', "Change a sent line's quantity (no new ticket)", roles=('owner', 'store_manager'), overridable=True),
|
||||||
Perm('ordering.prices.view_changes', 'See the prices changed by hand (who, when, why)', roles=('owner', 'store_manager')),
|
Perm('ordering.prices.view_changes', 'See the prices changed by hand (who, when, why)', roles=('owner', 'store_manager')),
|
||||||
Perm('ordering.refunds', 'Refund payments from other shifts', roles=('owner', 'store_manager'), overridable=True),
|
Perm('ordering.refunds', 'Refund payments from other shifts', roles=('owner', 'store_manager'), overridable=True),
|
||||||
Perm('ordering.payments.revert', 'Turn paid items back to unpaid', roles=('owner', 'store_manager'), overridable=True),
|
Perm('ordering.payments.revert', 'Turn paid items back to unpaid', roles=('owner', 'store_manager'), overridable=True),
|
||||||
@@ -24,6 +25,7 @@ MODULE = Module(
|
|||||||
SettingDef('orders.auto_close_on_full_payment', 'false', "Automatically close the table order when all items have been paid: 'true' | 'false'", type='bool'),
|
SettingDef('orders.auto_close_on_full_payment', 'false', "Automatically close the table order when all items have been paid: 'true' | 'false'", type='bool'),
|
||||||
SettingDef('orders.close_with_unpaid', 'false', "Allow closing an order that still has unpaid items (they are written off as unpaid): 'true' | 'false'. When 'false', closing asks for the payment first (plan step 4.8).", type='bool'),
|
SettingDef('orders.close_with_unpaid', 'false', "Allow closing an order that still has unpaid items (they are written off as unpaid): 'true' | 'false'. When 'false', closing asks for the payment first (plan step 4.8).", type='bool'),
|
||||||
SettingDef('orders.bypass_kds_serve', 'false', "Skip KDS pending/serve flow — new orders and items are immediately marked as served: 'true' | 'false'", type='bool'),
|
SettingDef('orders.bypass_kds_serve', 'false', "Skip KDS pending/serve flow — new orders and items are immediately marked as served: 'true' | 'false'", type='bool'),
|
||||||
|
SettingDef('orders.quantity_change', 'off', "Changing a sent line's quantity without sending it again (6F.5): 'off' | 'add_only' | 'add_and_remove' (lowering cancels the difference; also needs ordering.orders.cancel). Who may: ordering.items.change_quantity.", type='enum', choices=('off', 'add_only', 'add_and_remove')),
|
||||||
SettingDef('orders.price_change', 'anytime', "Changing a line's price by hand (6F.3): 'off' | 'before_sending' (only in the cart) | 'anytime' (also a sent or served line). Who may: the keys ordering.prices.modify / modify_sent.", type='enum', choices=('off', 'before_sending', 'anytime')),
|
SettingDef('orders.price_change', 'anytime', "Changing a line's price by hand (6F.3): 'off' | 'before_sending' (only in the cart) | 'anytime' (also a sent or served line). Who may: the keys ordering.prices.modify / modify_sent.", type='enum', choices=('off', 'before_sending', 'anytime')),
|
||||||
SettingDef('orders.price_change_reason', 'false', "A price changed by hand needs a reason: 'true' | 'false' (6F.3).", type='bool'),
|
SettingDef('orders.price_change_reason', 'false', "A price changed by hand needs a reason: 'true' | 'false' (6F.3).", type='bool'),
|
||||||
SettingDef('orders.price_change_reasons', '[]', 'JSON array of quick reasons offered when a price is changed by hand (6F.3); [] = the built-in ones.', type='json'),
|
SettingDef('orders.price_change_reasons', '[]', 'JSON array of quick reasons offered when a price is changed by hand (6F.3); [] = the built-in ones.', type='json'),
|
||||||
|
|||||||
+136
-21
@@ -343,7 +343,8 @@ def get_order(order_id: int, db: Session = Depends(get_db), user: User = Depends
|
|||||||
"id": i.id,
|
"id": i.id,
|
||||||
"order_id": i.order_id,
|
"order_id": i.order_id,
|
||||||
"product_id": i.product_id,
|
"product_id": i.product_id,
|
||||||
"product": {"id": i.product.id, "name": i.product.name} if i.product else None,
|
"product": {"id": i.product.id, "name": i.product.name, "unit_type": i.product.unit_type or "piece",
|
||||||
|
"one_more_enabled": bool(i.product.one_more_enabled)} if i.product else None, # 6F.5: +1
|
||||||
"product_name": i.product_name, "category_id": i.category_id, "category_name": i.category_name,
|
"product_name": i.product_name, "category_id": i.category_id, "category_name": i.category_name,
|
||||||
"added_by": i.added_by,
|
"added_by": i.added_by,
|
||||||
"added_by_name": name_map.get(i.added_by),
|
"added_by_name": name_map.get(i.added_by),
|
||||||
@@ -366,6 +367,9 @@ def get_order(order_id: int, db: Session = Depends(get_db), user: User = Depends
|
|||||||
"system_key": i.system_key, # the delivery fee line (phase 3S, S.5)
|
"system_key": i.system_key, # the delivery fee line (phase 3S, S.5)
|
||||||
"source": i.source, # waiter | counter | qr | online (4.8)
|
"source": i.source, # waiter | counter | qr | online (4.8)
|
||||||
"course_id": i.course_id,
|
"course_id": i.course_id,
|
||||||
|
"deal_id": i.deal_id, "linked_item_id": i.linked_item_id,
|
||||||
|
"split_from_id": i.split_from_id, # 6F.4: the line it was cut from
|
||||||
|
"cancel_reason": i.cancel_reason,
|
||||||
}
|
}
|
||||||
|
|
||||||
def fmt_log(l):
|
def fmt_log(l):
|
||||||
@@ -1618,26 +1622,7 @@ def split_item(
|
|||||||
|
|
||||||
# Reduce original item
|
# Reduce original item
|
||||||
item.quantity -= body.quantity
|
item.quantity -= body.quantity
|
||||||
|
new_item = cut_part(item, body.quantity)
|
||||||
# Create split-off item
|
|
||||||
new_item = OrderItem(
|
|
||||||
source=item.source,
|
|
||||||
order_id=order_id,
|
|
||||||
product_id=item.product_id,
|
|
||||||
added_by=item.added_by,
|
|
||||||
quantity=body.quantity,
|
|
||||||
unit_price=item.unit_price,
|
|
||||||
selected_options=item.selected_options,
|
|
||||||
removed_ingredients=item.removed_ingredients,
|
|
||||||
notes=item.notes,
|
|
||||||
status="active",
|
|
||||||
printed=item.printed,
|
|
||||||
split_from_id=item.id, # 6F.4: the moves the line had come with this part
|
|
||||||
# the rest of what the line was (kitchen, course, price, names, cost) goes with the part
|
|
||||||
kds_status=item.kds_status, course_id=item.course_id, price_adjustment=item.price_adjustment,
|
|
||||||
unit_cost=item.unit_cost, product_name=item.product_name, category_id=item.category_id,
|
|
||||||
category_name=item.category_name,
|
|
||||||
)
|
|
||||||
db.add(new_item)
|
db.add(new_item)
|
||||||
db.commit()
|
db.commit()
|
||||||
db.refresh(item)
|
db.refresh(item)
|
||||||
@@ -1645,6 +1630,136 @@ def split_item(
|
|||||||
return [item, new_item]
|
return [item, new_item]
|
||||||
|
|
||||||
|
|
||||||
|
def cut_part(item, quantity, **changes):
|
||||||
|
"""A new line cut from `item` (a split, a lowered quantity, 6F.4/6F.5): everything the line was
|
||||||
|
(product, price and its change, choices, note, kitchen state, course, cost, names, source) for
|
||||||
|
`quantity`, linked by split_from_id so its moves follow it. Not added to the session."""
|
||||||
|
fields = dict(
|
||||||
|
source=item.source, order_id=item.order_id, product_id=item.product_id, added_by=item.added_by,
|
||||||
|
quantity=quantity, unit_price=item.unit_price, selected_options=item.selected_options,
|
||||||
|
removed_ingredients=item.removed_ingredients, notes=item.notes, status="active", printed=item.printed,
|
||||||
|
split_from_id=item.id, kds_status=item.kds_status, course_id=item.course_id,
|
||||||
|
price_adjustment=item.price_adjustment, unit_cost=item.unit_cost, product_name=item.product_name,
|
||||||
|
category_id=item.category_id, category_name=item.category_name,
|
||||||
|
) # added_at = now: the moment it was cut (services/moves.py reads it)
|
||||||
|
fields.update(changes)
|
||||||
|
return OrderItem(**fields)
|
||||||
|
|
||||||
|
|
||||||
|
# ─── One more of a line, and a line's quantity (6F.5) ────────────────────────
|
||||||
|
|
||||||
|
class AgainRequest(BaseModel):
|
||||||
|
quantity: int = Field(default=1, ge=1, le=50)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/{order_id}/items/{item_id}/again", response_model=AddItemsResponse)
|
||||||
|
def order_again(order_id: int, item_id: int, body: AgainRequest, request: Request, db: Session = Depends(get_db),
|
||||||
|
user: User = Depends(get_current_user)):
|
||||||
|
""""One more" (6F.5): a new line just like this one (product, choices, removed ingredients, note,
|
||||||
|
course) for `quantity`, priced by the server now and sent like any new line (kitchen ticket,
|
||||||
|
KDS). Only for products with one_more_enabled, counted in pieces, from an active, paid or
|
||||||
|
tabbed line that isn't a deal's or the system's. Needs ordering.orders.open."""
|
||||||
|
from core.access.context import current_device
|
||||||
|
from schemas.order import OrderItemInput, SelectedOptionInput
|
||||||
|
_need(request, db, user, "ordering.orders.open", target=f"order:{order_id}")
|
||||||
|
order = db.get(Order, order_id)
|
||||||
|
if order is None:
|
||||||
|
raise XeniaError("order.not_found", order_id=order_id)
|
||||||
|
if not _can_access_order(order, user, db):
|
||||||
|
raise XeniaError("order.not_yours")
|
||||||
|
item = db.query(OrderItem).filter(OrderItem.id == item_id, OrderItem.order_id == order_id).first()
|
||||||
|
if item is None:
|
||||||
|
raise XeniaError("order.item_not_found")
|
||||||
|
product = item.product
|
||||||
|
if product is None or not product.one_more_enabled:
|
||||||
|
raise XeniaError("order.one_more_off")
|
||||||
|
if item.status not in ("active", "paid", "tabbed") or item.deal_id or item.linked_item_id \
|
||||||
|
or product.system_key or (product.unit_type or "piece") != "piece":
|
||||||
|
raise XeniaError("order.one_more_line")
|
||||||
|
try:
|
||||||
|
options = [SelectedOptionInput(**o) for o in json.loads(item.selected_options or "[]") if isinstance(o, dict)]
|
||||||
|
removed = [str(x) for x in json.loads(item.removed_ingredients or "[]")]
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
options, removed = [], []
|
||||||
|
device = current_device(request, db)
|
||||||
|
source = "counter" if device is not None and device.app_key == "pos_counter" else "waiter"
|
||||||
|
result = add_priced_items(order_id, AddItemsRequest(items=[OrderItemInput(
|
||||||
|
product_id=item.product_id, quantity=body.quantity, selected_options=options or None,
|
||||||
|
removed_ingredients=removed or None, notes=item.notes, course_id=item.course_id, source=source,
|
||||||
|
)]), db, user)
|
||||||
|
_audit(db, order_id, "ITEM_REORDERED", waiter_id=user.id, item_ids=[item.id],
|
||||||
|
note=f"{body.quantity:g} more of #{item.id}")
|
||||||
|
db.commit()
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
class QuantityRequest(BaseModel):
|
||||||
|
quantity: int = Field(ge=1, le=999)
|
||||||
|
print_cancellation: bool = False # lowering: send a cancellation to the kitchen (the app asks)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/{order_id}/items/{item_id}/quantity")
|
||||||
|
def change_quantity(order_id: int, item_id: int, body: QuantityRequest, request: Request, background_tasks: BackgroundTasks,
|
||||||
|
db: Session = Depends(get_db), user: User = Depends(get_current_user)):
|
||||||
|
"""Change a sent line's quantity without sending it again (6F.5). The venue
|
||||||
|
(orders.quantity_change: off | add_only | add_and_remove) and ordering.items.change_quantity
|
||||||
|
decide; lowering also needs ordering.orders.cancel (or a manager's PIN each). Up: the line
|
||||||
|
grows, nothing is printed. Down: the removed part becomes its own cancelled line ("quantity
|
||||||
|
lowered", split_from_id = the line) and, when asked, a cancellation ticket goes to the kitchen.
|
||||||
|
Only unpaid lines counted in pieces, not a deal's or the system's."""
|
||||||
|
from models.settings import PosSettings
|
||||||
|
order = db.get(Order, order_id)
|
||||||
|
if order is None:
|
||||||
|
raise XeniaError("order.not_found", order_id=order_id)
|
||||||
|
if not _can_access_order(order, user, db):
|
||||||
|
raise XeniaError("order.not_yours")
|
||||||
|
row = db.query(PosSettings).filter(PosSettings.key == "orders.quantity_change").first()
|
||||||
|
mode = row.value if row is not None and row.value in ("off", "add_only", "add_and_remove") else "off"
|
||||||
|
if mode == "off":
|
||||||
|
raise XeniaError("order.quantity_change_off")
|
||||||
|
item = db.query(OrderItem).filter(OrderItem.id == item_id, OrderItem.order_id == order_id).first()
|
||||||
|
if item is None:
|
||||||
|
raise XeniaError("order.item_not_found")
|
||||||
|
product = item.product
|
||||||
|
if item.status != "active" or item.deal_id or item.linked_item_id or (product is not None and product.system_key) \
|
||||||
|
or (item.unit_type or "piece") != "piece" or item.quantity != int(item.quantity):
|
||||||
|
raise XeniaError("order.quantity_line")
|
||||||
|
old = int(item.quantity)
|
||||||
|
if body.quantity == old:
|
||||||
|
return {"item_id": item.id, "quantity": old, "cancelled_item_id": None}
|
||||||
|
lowering = body.quantity < old
|
||||||
|
if lowering and mode != "add_and_remove":
|
||||||
|
raise XeniaError("order.quantity_remove_off")
|
||||||
|
approval = _need(request, db, user, "ordering.items.change_quantity", target=f"order:{order_id} item:{item_id}")
|
||||||
|
cancel_approval = None
|
||||||
|
if lowering and not holds(user, "core.dashboard.access") and not _waiter_can_cancel(user, db):
|
||||||
|
cancel_approval = require_override(request, db, "ordering.orders.cancel", target=f"order:{order_id}")
|
||||||
|
note = f"{old} → {body.quantity}" + (f" · {_approval_note(approval)}" if approval is not None else "")
|
||||||
|
part = None
|
||||||
|
if lowering:
|
||||||
|
now = utcnow()
|
||||||
|
part = cut_part(item, old - body.quantity, status="cancelled", cancelled_by=user.id, cancelled_at=now,
|
||||||
|
cancel_reason="quantity lowered")
|
||||||
|
db.add(part)
|
||||||
|
item.quantity = body.quantity
|
||||||
|
db.flush()
|
||||||
|
_audit(db, order_id, "ITEM_CANCELLED", waiter_id=user.id, item_ids=[part.id],
|
||||||
|
note=("quantity lowered" + (f" · {_approval_note(cancel_approval)}" if cancel_approval is not None else "")
|
||||||
|
+ ("" if body.print_cancellation else " · no kitchen ticket")))
|
||||||
|
else:
|
||||||
|
item.quantity = body.quantity
|
||||||
|
_audit(db, order_id, "QUANTITY_CHANGED", waiter_id=user.id, item_ids=[item.id], note=note)
|
||||||
|
db.commit()
|
||||||
|
broadcast_sync("order_updated", {"order_id": order_id, "table_id": order.table_id, "status": order.status,
|
||||||
|
"action": "quantity_changed", "item_ids": [item.id]})
|
||||||
|
if part is not None:
|
||||||
|
broadcast_sync("order_updated", {"order_id": order_id, "table_id": order.table_id, "status": order.status,
|
||||||
|
"action": "items_cancelled", "item_ids": [part.id]})
|
||||||
|
if body.print_cancellation:
|
||||||
|
background_tasks.add_task(print_cancellation_ticket, order_id, [part.id])
|
||||||
|
return {"item_id": item.id, "quantity": item.quantity, "cancelled_item_id": part.id if part is not None else None}
|
||||||
|
|
||||||
|
|
||||||
# ─── Adjust price on an existing item ────────────────────────────────────────
|
# ─── Adjust price on an existing item ────────────────────────────────────────
|
||||||
|
|
||||||
class PriceAdjustRequest(BaseModel):
|
class PriceAdjustRequest(BaseModel):
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ def _product_out(p, price: float, prices: dict | None = None) -> dict:
|
|||||||
"price": round(price, 2), "prices": {k: round(v, 2) for k, v in (prices or {}).items()},
|
"price": round(price, 2), "prices": {k: round(v, 2) for k, v in (prices or {}).items()},
|
||||||
"sold_at": [sp for sp in sales_points.sold_at(p) if sp in sales_points.IN_PERSON],
|
"sold_at": [sp for sp in sales_points.sold_at(p) if sp in sales_points.IN_PERSON],
|
||||||
"base_price": round(p.base_price, 2), "unit_type": p.unit_type or "piece",
|
"base_price": round(p.base_price, 2), "unit_type": p.unit_type or "piece",
|
||||||
|
"one_more": bool(p.one_more_enabled), # 6F.5
|
||||||
"tags": _tags(p.tags),
|
"tags": _tags(p.tags),
|
||||||
"allergens": allergens.of(p),
|
"allergens": allergens.of(p),
|
||||||
"primary_category_id": p.primary_category_id,
|
"primary_category_id": p.primary_category_id,
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ class AddItemsRequest(BaseModel):
|
|||||||
class ProductNameOut(BaseModel):
|
class ProductNameOut(BaseModel):
|
||||||
id: int
|
id: int
|
||||||
name: str
|
name: str
|
||||||
|
one_more_enabled: bool = False # 6F.5: the line shows +1
|
||||||
|
unit_type: Optional[str] = None
|
||||||
model_config = {"from_attributes": True}
|
model_config = {"from_attributes": True}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -386,6 +386,7 @@ class ProductBase(BaseModel):
|
|||||||
cost_breakdown: Optional[List[CostBreakdownItem]] = None
|
cost_breakdown: Optional[List[CostBreakdownItem]] = None
|
||||||
# Quick Add
|
# Quick Add
|
||||||
quick_add_enabled: bool = True
|
quick_add_enabled: bool = True
|
||||||
|
one_more_enabled: bool = False # 6F.5
|
||||||
# Tags
|
# Tags
|
||||||
tags: Optional[List[str]] = None
|
tags: Optional[List[str]] = None
|
||||||
# The EU allergens (plan step 6.3): {key: "contains" | "may_contain"}, core/allergens.py
|
# The EU allergens (plan step 6.3): {key: "contains" | "may_contain"}, core/allergens.py
|
||||||
@@ -437,6 +438,7 @@ class ProductUpdate(BaseModel):
|
|||||||
cost_breakdown: Optional[List[CostBreakdownItem]] = None
|
cost_breakdown: Optional[List[CostBreakdownItem]] = None
|
||||||
# Quick Add
|
# Quick Add
|
||||||
quick_add_enabled: Optional[bool] = None
|
quick_add_enabled: Optional[bool] = None
|
||||||
|
one_more_enabled: Optional[bool] = None # 6F.5
|
||||||
# Tags
|
# Tags
|
||||||
tags: Optional[List[str]] = None
|
tags: Optional[List[str]] = None
|
||||||
allergens: Optional[Dict[str, str]] = None # None = unchanged, {} = none
|
allergens: Optional[Dict[str, str]] = None # None = unchanged, {} = none
|
||||||
@@ -510,6 +512,7 @@ class ProductOut(ProductBase):
|
|||||||
'cost_simple': data.cost_simple,
|
'cost_simple': data.cost_simple,
|
||||||
'cost_breakdown': parsed,
|
'cost_breakdown': parsed,
|
||||||
'quick_add_enabled': getattr(data, 'quick_add_enabled', True),
|
'quick_add_enabled': getattr(data, 'quick_add_enabled', True),
|
||||||
|
'one_more_enabled': bool(getattr(data, 'one_more_enabled', False)),
|
||||||
'tags': json.loads(data.tags) if isinstance(getattr(data, 'tags', None), str) else (getattr(data, 'tags', None) or []),
|
'tags': json.loads(data.tags) if isinstance(getattr(data, 'tags', None), str) else (getattr(data, 'tags', None) or []),
|
||||||
'allergens': _allergens_of(data),
|
'allergens': _allergens_of(data),
|
||||||
'translations': _menu_tr_of(data),
|
'translations': _menu_tr_of(data),
|
||||||
|
|||||||
@@ -0,0 +1,123 @@
|
|||||||
|
"""One more, and a sent line's quantity (owner 2026-11-23, plan 6F.5).
|
||||||
|
|
||||||
|
- POST /api/orders/{id}/items/{item}/again: a new line like the old one, priced now, printed as new;
|
||||||
|
only with the product's one_more_enabled, from active / paid / tabbed lines in pieces.
|
||||||
|
- POST /api/orders/{id}/items/{item}/quantity: the venue's switch (off | add_only | add_and_remove),
|
||||||
|
the key ordering.items.change_quantity; up changes the line only (no ticket); down cuts a
|
||||||
|
cancelled part ("quantity lowered") and prints a cancellation only when asked.
|
||||||
|
"""
|
||||||
|
import json
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from tests.test_live import err
|
||||||
|
from tests.test_waiter_keys import shop # noqa: F401 (fixture)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def printed(monkeypatch):
|
||||||
|
"""What went to the kitchen: new lines (route_and_print_sync) and cancellations."""
|
||||||
|
import routers.orders as orders
|
||||||
|
got = {"tickets": [], "cancellations": []}
|
||||||
|
monkeypatch.setattr(orders, "route_and_print_sync", lambda *a, **k: (got["tickets"].append(a), [])[1])
|
||||||
|
monkeypatch.setattr(orders, "print_cancellation_ticket", lambda order_id, ids: got["cancellations"].append(list(ids)))
|
||||||
|
return got
|
||||||
|
|
||||||
|
|
||||||
|
def setting(db, key, value):
|
||||||
|
from models.settings import PosSettings
|
||||||
|
row = db.query(PosSettings).filter(PosSettings.key == key).first()
|
||||||
|
if row is None:
|
||||||
|
db.add(PosSettings(key=key, value=value))
|
||||||
|
else:
|
||||||
|
row.value = value
|
||||||
|
db.commit()
|
||||||
|
|
||||||
|
|
||||||
|
def lines(db, order_id):
|
||||||
|
from models.order import OrderItem
|
||||||
|
db.expire_all()
|
||||||
|
return db.query(OrderItem).filter(OrderItem.order_id == order_id).order_by(OrderItem.id).all()
|
||||||
|
|
||||||
|
|
||||||
|
def test_one_more_needs_the_products_switch(client, db, shop, printed):
|
||||||
|
o, item = shop["order"], shop["items"][0]
|
||||||
|
url = f"/api/orders/{o.id}/items/{item.id}/again"
|
||||||
|
assert err(client.post(url, headers=shop["h"], json={})) == "order.one_more_off"
|
||||||
|
item.product.one_more_enabled = True
|
||||||
|
item.notes = "no ice"
|
||||||
|
item.selected_options = json.dumps([{"id": None, "name": "Sweet", "price_delta": 0.0, "type": "quick"}])
|
||||||
|
db.commit()
|
||||||
|
before = len(lines(db, o.id))
|
||||||
|
r = client.post(url, headers=shop["h"], json={"quantity": 2})
|
||||||
|
assert r.status_code == 200, r.text
|
||||||
|
new = lines(db, o.id)[-1]
|
||||||
|
assert len(lines(db, o.id)) == before + 1 and new.id != item.id
|
||||||
|
assert (new.product_id, new.quantity, new.notes, new.status) == (item.product_id, 2, "no ice", "active")
|
||||||
|
assert json.loads(new.selected_options)[0]["name"] == "Sweet" and new.unit_price == 4.0
|
||||||
|
assert len(printed["tickets"]) == 1 # sent to the kitchen like any new line
|
||||||
|
# from a paid line too; never from a cancelled one
|
||||||
|
paid = shop["items"][2]
|
||||||
|
assert client.post(f"/api/orders/{o.id}/items/{paid.id}/again", headers=shop["h"], json={}).status_code == 200
|
||||||
|
paid.status = "cancelled"
|
||||||
|
db.commit()
|
||||||
|
assert err(client.post(f"/api/orders/{o.id}/items/{paid.id}/again", headers=shop["h"], json={})) == "order.one_more_line"
|
||||||
|
|
||||||
|
|
||||||
|
def test_one_more_needs_ordering_orders_open(client, db, shop, login, printed):
|
||||||
|
o, item = shop["order"], shop["items"][0]
|
||||||
|
item.product.one_more_enabled = True
|
||||||
|
db.commit()
|
||||||
|
h = login(shop["new_waiter"](remove=("ordering.orders.open",)), client="waiter")
|
||||||
|
assert err(client.post(f"/api/orders/{o.id}/items/{item.id}/again", headers=h, json={})) == "access.denied"
|
||||||
|
|
||||||
|
|
||||||
|
def test_quantity_follows_the_venue_and_the_key(client, db, shop, login, printed):
|
||||||
|
o, item = shop["order"], shop["items"][0]
|
||||||
|
url = f"/api/orders/{o.id}/items/{item.id}/quantity"
|
||||||
|
assert err(client.post(url, headers=shop["h"], json={"quantity": 3})) == "order.quantity_change_off"
|
||||||
|
setting(db, "orders.quantity_change", "add_only")
|
||||||
|
# a waiter without the key: a manager may approve it
|
||||||
|
assert err(client.post(url, headers=shop["h"], json={"quantity": 3})) == "access.override_possible"
|
||||||
|
h = login(shop["new_waiter"](add=("ordering.items.change_quantity",)), client="waiter")
|
||||||
|
r = client.post(url, headers=h, json={"quantity": 3})
|
||||||
|
assert r.status_code == 200, r.text
|
||||||
|
assert lines(db, o.id)[0].quantity == 3 and printed["tickets"] == [] and printed["cancellations"] == []
|
||||||
|
assert err(client.post(url, headers=h, json={"quantity": 2})) == "order.quantity_remove_off"
|
||||||
|
from models.order import OrderAuditLog
|
||||||
|
log = db.query(OrderAuditLog).filter(OrderAuditLog.event_type == "QUANTITY_CHANGED").one()
|
||||||
|
assert log.note.startswith("1 → 3")
|
||||||
|
|
||||||
|
|
||||||
|
def test_lowering_cancels_the_difference_and_asks_about_the_ticket(client, db, shop, login, printed):
|
||||||
|
o, item = shop["order"], shop["items"][0]
|
||||||
|
item.quantity = 5
|
||||||
|
db.commit()
|
||||||
|
setting(db, "orders.quantity_change", "add_and_remove")
|
||||||
|
url = f"/api/orders/{o.id}/items/{item.id}/quantity"
|
||||||
|
# the key, but not the cancel key: a manager's approval for the cancel part
|
||||||
|
h = login(shop["new_waiter"](add=("ordering.items.change_quantity",), remove=("ordering.orders.cancel",)), client="waiter")
|
||||||
|
assert err(client.post(url, headers=h, json={"quantity": 3})) == "access.override_possible"
|
||||||
|
h = login(shop["new_waiter"](add=("ordering.items.change_quantity", "ordering.orders.cancel")), client="waiter")
|
||||||
|
r = client.post(url, headers=h, json={"quantity": 3, "print_cancellation": False})
|
||||||
|
assert r.status_code == 200, r.text
|
||||||
|
part_id = r.json()["cancelled_item_id"]
|
||||||
|
rows = {i.id: i for i in lines(db, o.id)}
|
||||||
|
assert rows[item.id].quantity == 3 and rows[item.id].status == "active"
|
||||||
|
part = rows[part_id]
|
||||||
|
assert (part.quantity, part.status, part.cancel_reason, part.split_from_id) == (2, "cancelled", "quantity lowered", item.id)
|
||||||
|
assert printed["cancellations"] == []
|
||||||
|
r = client.post(url, headers=h, json={"quantity": 2, "print_cancellation": True})
|
||||||
|
assert printed["cancellations"] == [[r.json()["cancelled_item_id"]]]
|
||||||
|
|
||||||
|
|
||||||
|
def test_only_unpaid_lines_in_pieces(client, db, shop, printed, login):
|
||||||
|
setting(db, "orders.quantity_change", "add_and_remove")
|
||||||
|
o = shop["order"]
|
||||||
|
paid = shop["items"][2]
|
||||||
|
boss = login(shop["owner"])
|
||||||
|
assert err(client.post(f"/api/orders/{o.id}/items/{paid.id}/quantity", headers=boss, json={"quantity": 2})) == "order.quantity_line"
|
||||||
|
item = shop["items"][0]
|
||||||
|
item.product.unit_type = "kg"
|
||||||
|
db.commit()
|
||||||
|
assert err(client.post(f"/api/orders/{o.id}/items/{item.id}/quantity", headers=boss, json={"quantity": 2})) == "order.quantity_line"
|
||||||
@@ -68,9 +68,27 @@ function OrderingSettings() {
|
|||||||
itemLabel={o('quickNote')} placeholder={o('newQuickNote')} testId="settings-quick-notes" newTestId="quick-note" />
|
itemLabel={o('quickNote')} placeholder={o('newQuickNote')} testId="settings-quick-notes" newTestId="quick-note" />
|
||||||
</SettingsCard>
|
</SettingsCard>
|
||||||
<PriceChangeSettings s={s} />
|
<PriceChangeSettings s={s} />
|
||||||
|
<QuantitySettings s={s} />
|
||||||
</>)
|
</>)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A sent line's quantity changed without a new ticket (6F.5). Who may: ordering.items.change_quantity;
|
||||||
|
* lowering also needs ordering.orders.cancel ("What each role may do", a person's permissions). */
|
||||||
|
function QuantitySettings({ s }) {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const q = k => t(`settings.quantity.${k}`)
|
||||||
|
const id = useId()
|
||||||
|
return (
|
||||||
|
<SettingsCard title={q('title')} description={q('intro')} testId="settings-quantity">
|
||||||
|
<SettingRow label={q('when')} hint={q('whenHint')} tip={q('whenTip')} htmlFor={id}>
|
||||||
|
<Select id={id} value={s.get('orders.quantity_change', 'off')} disabled={s.saving} data-testid="setting-orders.quantity_change"
|
||||||
|
onChange={e => s.save('orders.quantity_change', e.target.value)}
|
||||||
|
options={['off', 'add_only', 'add_and_remove'].map(v => ({ value: v, label: q(`modes.${v}`) }))} />
|
||||||
|
</SettingRow>
|
||||||
|
</SettingsCard>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/** Prices changed by hand (6F.3): the venue's switch, the reason, the quick reasons. Who may: the
|
/** Prices changed by hand (6F.3): the venue's switch, the reason, the quick reasons. Who may: the
|
||||||
* keys ordering.prices.modify / modify_sent ("What each role may do", a person's permissions). */
|
* keys ordering.prices.modify / modify_sent ("What each role may do", a person's permissions). */
|
||||||
function PriceChangeSettings({ s }) {
|
function PriceChangeSettings({ s }) {
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ export function InfoTab({ form, set, setForm, categories, prepZones }) {
|
|||||||
<AllergensField value={form.allergens} onChange={v => set('allergens', v)} />
|
<AllergensField value={form.allergens} onChange={v => set('allergens', v)} />
|
||||||
<Switch checked={form.is_available} onChange={v => set('is_available', v)} label={t('products.editor.available')} info={<InfoTip>{t('products.editor.availableTip')}</InfoTip>} description={t('products.editor.availableHint')} />
|
<Switch checked={form.is_available} onChange={v => set('is_available', v)} label={t('products.editor.available')} info={<InfoTip>{t('products.editor.availableTip')}</InfoTip>} description={t('products.editor.availableHint')} />
|
||||||
<Switch checked={form.quick_add_enabled} onChange={v => set('quick_add_enabled', v)} label={t('products.editor.quickAdd')} info={<InfoTip>{t('products.editor.quickAddTip')}</InfoTip>} description={t('products.editor.quickAddHint')} />
|
<Switch checked={form.quick_add_enabled} onChange={v => set('quick_add_enabled', v)} label={t('products.editor.quickAdd')} info={<InfoTip>{t('products.editor.quickAddTip')}</InfoTip>} description={t('products.editor.quickAddHint')} />
|
||||||
|
<Switch checked={form.one_more_enabled} onChange={v => set('one_more_enabled', v)} label={t('products.editor.oneMore')} info={<InfoTip>{t('products.editor.oneMoreTip')}</InfoTip>} description={t('products.editor.oneMoreHint')} data-testid="product-one-more" />
|
||||||
<MediaField value={form.image} onChange={image => set('image', image)} nameAfter={shownText(form.names, venue, form.name)} label={t('media.photo')} testid="product-photo" />
|
<MediaField value={form.image} onChange={image => set('image', image)} nameAfter={shownText(form.names, venue, form.name)} label={t('media.photo')} testid="product-photo" />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ export function buildForm(p) {
|
|||||||
cost_simple: p.cost_simple ?? '',
|
cost_simple: p.cost_simple ?? '',
|
||||||
cost_breakdown: (p.cost_breakdown ?? []).map(e => ({ label: e.label, amount: e.amount })),
|
cost_breakdown: (p.cost_breakdown ?? []).map(e => ({ label: e.label, amount: e.amount })),
|
||||||
quick_add_enabled: p.quick_add_enabled ?? true,
|
quick_add_enabled: p.quick_add_enabled ?? true,
|
||||||
|
one_more_enabled: !!p.one_more_enabled, // 6F.5
|
||||||
tags: [...(p.tags ?? [])],
|
tags: [...(p.tags ?? [])],
|
||||||
is_service_item: !!p.is_service_item,
|
is_service_item: !!p.is_service_item,
|
||||||
fiscal_name: p.fiscal_name ?? '',
|
fiscal_name: p.fiscal_name ?? '',
|
||||||
@@ -143,6 +144,7 @@ export function buildBody(f, venue = 'el') {
|
|||||||
cost_breakdown: f.cost_mode === 'detailed' && f.cost_breakdown.length
|
cost_breakdown: f.cost_mode === 'detailed' && f.cost_breakdown.length
|
||||||
? f.cost_breakdown.map(e => ({ label: e.label, amount: num(e.amount) })) : null,
|
? f.cost_breakdown.map(e => ({ label: e.label, amount: num(e.amount) })) : null,
|
||||||
quick_add_enabled: f.quick_add_enabled,
|
quick_add_enabled: f.quick_add_enabled,
|
||||||
|
one_more_enabled: !!f.one_more_enabled,
|
||||||
tags: f.tags,
|
tags: f.tags,
|
||||||
is_service_item: f.is_service_item,
|
is_service_item: f.is_service_item,
|
||||||
fiscal_name: f.fiscal_name.trim() || null,
|
fiscal_name: f.fiscal_name.trim() || null,
|
||||||
|
|||||||
@@ -140,3 +140,11 @@ test('a category dropped above or below a row lands where the line showed (2026-
|
|||||||
assert.equal(moveIdTo([1, 2, 3], 1, 2, false), null) // already there
|
assert.equal(moveIdTo([1, 2, 3], 1, 2, false), null) // already there
|
||||||
assert.equal(moveIdTo([1, 2, 3], 2, 2, true), null)
|
assert.equal(moveIdTo([1, 2, 3], 2, 2, true), null)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('"One more" travels with the product, off unless set (6F.5)', () => {
|
||||||
|
assert.equal(buildForm({ name: 'Beer', base_price: 4 }).one_more_enabled, false)
|
||||||
|
const f = buildForm({ name: 'Beer', base_price: 4, one_more_enabled: true })
|
||||||
|
assert.equal(f.one_more_enabled, true)
|
||||||
|
assert.equal(buildBody(f).one_more_enabled, true)
|
||||||
|
assert.equal(buildBody({ ...f, one_more_enabled: false }).one_more_enabled, false)
|
||||||
|
})
|
||||||
|
|||||||
@@ -105,7 +105,13 @@
|
|||||||
"product_unavailable": "Το προϊόν {{product_id}} δεν είναι διαθέσιμο.",
|
"product_unavailable": "Το προϊόν {{product_id}} δεν είναι διαθέσιμο.",
|
||||||
"price_change_off": "Η αλλαγή τιμής με το χέρι είναι κλειστή σε αυτό το κατάστημα.",
|
"price_change_off": "Η αλλαγή τιμής με το χέρι είναι κλειστή σε αυτό το κατάστημα.",
|
||||||
"price_change_sent_off": "Οι τιμές αλλάζουν μόνο πριν σταλούν τα είδη.",
|
"price_change_sent_off": "Οι τιμές αλλάζουν μόνο πριν σταλούν τα είδη.",
|
||||||
"price_reason_required": "Γράψτε γιατί αλλάζει η τιμή."
|
"price_reason_required": "Γράψτε γιατί αλλάζει η τιμή.",
|
||||||
|
"one_more_off": "Το «Άλλο ένα» δεν είναι ενεργό για αυτό το προϊόν.",
|
||||||
|
"one_more_line": "Αυτή η γραμμή δεν ξαναπαραγγέλνεται με ένα πάτημα.",
|
||||||
|
"quantity_change_off": "Η αλλαγή ποσότητας είναι κλειστή σε αυτό το κατάστημα.",
|
||||||
|
"quantity_remove_off": "Εδώ οι ποσότητες μόνο αυξάνονται.",
|
||||||
|
"quantity_invalid": "Διαλέξτε ακέραιο από 1 έως {{max}}.",
|
||||||
|
"quantity_line": "Η ποσότητα αυτής της γραμμής δεν αλλάζει εδώ."
|
||||||
},
|
},
|
||||||
"notification": {
|
"notification": {
|
||||||
"not_found": "Η ειδοποίηση {{notification_id}} δεν βρέθηκε."
|
"not_found": "Η ειδοποίηση {{notification_id}} δεν βρέθηκε."
|
||||||
|
|||||||
@@ -759,6 +759,18 @@
|
|||||||
"reasonsHint": "Με ένα πάτημα· το προσωπικό μπορεί και να γράψει δική του. Καμία: οι έτοιμες.",
|
"reasonsHint": "Με ένα πάτημα· το προσωπικό μπορεί και να γράψει δική του. Καμία: οι έτοιμες.",
|
||||||
"reasonItem": "Γρήγορη αιτία",
|
"reasonItem": "Γρήγορη αιτία",
|
||||||
"newReason": "Νέα γρήγορη αιτία…"
|
"newReason": "Νέα γρήγορη αιτία…"
|
||||||
|
},
|
||||||
|
"quantity": {
|
||||||
|
"title": "Αλλαγή ποσότητας σταλμένης γραμμής",
|
||||||
|
"intro": "Το προσωπικό διορθώνει πόσα είναι σε μια γραμμή χωρίς να ξαναστείλει στην κουζίνα. Κάθε αλλαγή κρατιέται στο ιστορικό της παραγγελίας.",
|
||||||
|
"when": "Το προσωπικό μπορεί",
|
||||||
|
"whenHint": "Ποιος: «Τι επιτρέπεται σε κάθε ρόλο» και τα δικαιώματα κάθε ατόμου.",
|
||||||
|
"whenTip": "Μόνο προσθήκη: η ποσότητα μόνο ανεβαίνει (μια μπίρα από το ψυγείο), δεν τυπώνεται τίποτα. Προσθήκη και αφαίρεση: όταν κατεβαίνει, η διαφορά ακυρώνεται ως ξεχωριστή γραμμή και ρωτά αν θα σταλεί ακύρωση στην κουζίνα. Η αφαίρεση θέλει και το δικαίωμα ακύρωσης.",
|
||||||
|
"modes": {
|
||||||
|
"off": "Καθόλου",
|
||||||
|
"add_only": "Μόνο προσθήκη",
|
||||||
|
"add_and_remove": "Προσθήκη και αφαίρεση"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"logs": {
|
"logs": {
|
||||||
@@ -2813,7 +2825,10 @@
|
|||||||
"availableTip": "Όχι: εξαφανίζεται από τα μενού των σερβιτόρων και του ταμείου μέχρι να το ενεργοποιήσετε ξανά (τελείωσε για σήμερα). Τίποτε άλλο δεν αλλάζει.",
|
"availableTip": "Όχι: εξαφανίζεται από τα μενού των σερβιτόρων και του ταμείου μέχρι να το ενεργοποιήσετε ξανά (τελείωσε για σήμερα). Τίποτε άλλο δεν αλλάζει.",
|
||||||
"quickAddTip": "Ναι: ένα πάτημα στη λίστα του σερβιτόρου το προσθέτει κατευθείαν, χωρίς να ανοίξουν οι επιλογές του. Αφήστε το κλειστό για προϊόντα που χρειάζονται επιλογή (ψήσιμο, συνοδευτικά).",
|
"quickAddTip": "Ναι: ένα πάτημα στη λίστα του σερβιτόρου το προσθέτει κατευθείαν, χωρίς να ανοίξουν οι επιλογές του. Αφήστε το κλειστό για προϊόντα που χρειάζονται επιλογή (ψήσιμο, συνοδευτικά).",
|
||||||
"vatGroupTip": "Ο συντελεστής ΦΠΑ που χρησιμοποιεί η φορολογική απόδειξη για το προϊόν. Χρειάζεται για να πληρωθεί όσο ο φορολογικός μηχανισμός είναι ενεργός.",
|
"vatGroupTip": "Ο συντελεστής ΦΠΑ που χρησιμοποιεί η φορολογική απόδειξη για το προϊόν. Χρειάζεται για να πληρωθεί όσο ο φορολογικός μηχανισμός είναι ενεργός.",
|
||||||
"costTip": "Τι σας κοστίζει μία μονάδα (υλικά, συσκευασία). Οι αναφορές το χρησιμοποιούν για το κέρδος· προϊόντα χωρίς κόστος κάνουν το κέρδος κατώτερη εκτίμηση."
|
"costTip": "Τι σας κοστίζει μία μονάδα (υλικά, συσκευασία). Οι αναφορές το χρησιμοποιούν για το κέρδος· προϊόντα χωρίς κόστος κάνουν το κέρδος κατώτερη εκτίμηση.",
|
||||||
|
"oneMore": "Άλλο ένα (+1)",
|
||||||
|
"oneMoreHint": "Μια σταλμένη γραμμή αυτού του προϊόντος έχει κουμπί +1 στα κινητά και στο ταμείο.",
|
||||||
|
"oneMoreTip": "Για ό,τι τα τραπέζια ξαναπαραγγέλνουν (μπίρες, καφέδες). Το +1 παραγγέλνει το ίδιο ξανά, με τις ίδιες επιλογές και σημείωση, στη σημερινή τιμή, και το στέλνει στην κουζίνα ή στο μπαρ όπως κάθε νέα παραγγελία. Κλειστό αρχικά."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"menuTabletSettings": {
|
"menuTabletSettings": {
|
||||||
@@ -3392,7 +3407,9 @@
|
|||||||
"ORDER_CANCELLED": "Ακύρωση",
|
"ORDER_CANCELLED": "Ακύρωση",
|
||||||
"ITEM_CANCELLED": "Ακύρωση γραμμής",
|
"ITEM_CANCELLED": "Ακύρωση γραμμής",
|
||||||
"PRICE_CHANGED": "Αλλαγή τιμής",
|
"PRICE_CHANGED": "Αλλαγή τιμής",
|
||||||
"PRICE_SET_BY_HAND": "Τιμή με το χέρι (εγκρίθηκε)"
|
"PRICE_SET_BY_HAND": "Τιμή με το χέρι (εγκρίθηκε)",
|
||||||
|
"QUANTITY_CHANGED": "Αλλαγή ποσότητας",
|
||||||
|
"ITEM_REORDERED": "Άλλο ένα"
|
||||||
},
|
},
|
||||||
"price": {
|
"price": {
|
||||||
"modifier_applied": "Κανόνας τιμής",
|
"modifier_applied": "Κανόνας τιμής",
|
||||||
|
|||||||
@@ -464,6 +464,9 @@
|
|||||||
"refunds": "Επιστροφή χρημάτων για πληρωμές άλλων βαρδιών",
|
"refunds": "Επιστροφή χρημάτων για πληρωμές άλλων βαρδιών",
|
||||||
"payments": {
|
"payments": {
|
||||||
"revert": "Αναίρεση πληρωμής (πληρωμένα → απλήρωτα)"
|
"revert": "Αναίρεση πληρωμής (πληρωμένα → απλήρωτα)"
|
||||||
|
},
|
||||||
|
"items": {
|
||||||
|
"change_quantity": "Αλλαγή ποσότητας σταλμένης γραμμής (χωρίς νέο δελτίο)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -466,6 +466,11 @@
|
|||||||
},
|
},
|
||||||
"dialog": {
|
"dialog": {
|
||||||
"close": "Κλείσιμο"
|
"close": "Κλείσιμο"
|
||||||
|
},
|
||||||
|
"oneMore": {
|
||||||
|
"send": "Αποστολή +{{count}}",
|
||||||
|
"label": "Άλλο ένα",
|
||||||
|
"sent": "Στάλθηκαν {{count}} ακόμη {{name}}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"display": {
|
"display": {
|
||||||
|
|||||||
@@ -529,7 +529,9 @@
|
|||||||
"moveItems": "Σφάλμα μεταφοράς αντικειμένων",
|
"moveItems": "Σφάλμα μεταφοράς αντικειμένων",
|
||||||
"flags": "Σφάλμα αποθήκευσης σημαιών",
|
"flags": "Σφάλμα αποθήκευσης σημαιών",
|
||||||
"combine": "Σφάλμα συνδυασμού",
|
"combine": "Σφάλμα συνδυασμού",
|
||||||
"price": "Η τιμή δεν άλλαξε."
|
"price": "Η τιμή δεν άλλαξε.",
|
||||||
|
"again": "Το «άλλο ένα» δεν στάλθηκε.",
|
||||||
|
"quantity": "Η ποσότητα δεν άλλαξε."
|
||||||
},
|
},
|
||||||
"openOrder": "Άνοιγμα Παραγγελίας",
|
"openOrder": "Άνοιγμα Παραγγελίας",
|
||||||
"noPaid": "Δεν υπάρχουν πληρωμένα αντικείμενα",
|
"noPaid": "Δεν υπάρχουν πληρωμένα αντικείμενα",
|
||||||
@@ -896,5 +898,25 @@
|
|||||||
"items_moved": "Μεταφορά γραμμών",
|
"items_moved": "Μεταφορά γραμμών",
|
||||||
"orders_merged": "Ένωση τραπεζιών"
|
"orders_merged": "Ένωση τραπεζιών"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"oneMore": {
|
||||||
|
"label": "Άλλο ένα",
|
||||||
|
"send": "Αποστολή +{{count}}"
|
||||||
|
},
|
||||||
|
"quantity": {
|
||||||
|
"title": "Αλλαγή ποσότητας",
|
||||||
|
"actionSub": "Διόρθωση ποσότητας· δεν ξαναστέλνεται στην κουζίνα",
|
||||||
|
"now": "Τώρα",
|
||||||
|
"new": "Νέα",
|
||||||
|
"less": "Ένα λιγότερο",
|
||||||
|
"more": "Ένα ακόμη",
|
||||||
|
"save": "Αποθήκευση",
|
||||||
|
"upNote_one": "{{count}} ακόμη, χωρίς νέο δελτίο",
|
||||||
|
"upNote_other": "{{count}} ακόμη, χωρίς νέο δελτίο",
|
||||||
|
"downNote_one": "{{count}} θα ακυρωθεί",
|
||||||
|
"downNote_other": "{{count}} θα ακυρωθούν",
|
||||||
|
"noChange": "Αλλάξτε τη με − και +",
|
||||||
|
"onlyUp": "Σε αυτό το κατάστημα οι ποσότητες μόνο αυξάνονται.",
|
||||||
|
"sendCancel": "Αποστολή ακύρωσης στην κουζίνα"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,7 +105,13 @@
|
|||||||
"product_unavailable": "Product {{product_id}} isn't available.",
|
"product_unavailable": "Product {{product_id}} isn't available.",
|
||||||
"price_change_off": "Changing prices by hand is turned off for this venue.",
|
"price_change_off": "Changing prices by hand is turned off for this venue.",
|
||||||
"price_change_sent_off": "Prices can only be changed before the items are sent.",
|
"price_change_sent_off": "Prices can only be changed before the items are sent.",
|
||||||
"price_reason_required": "Say why the price changes."
|
"price_reason_required": "Say why the price changes.",
|
||||||
|
"one_more_off": "\"One more\" isn't turned on for this product.",
|
||||||
|
"one_more_line": "This line can't be ordered again with one tap.",
|
||||||
|
"quantity_change_off": "Changing quantities is turned off for this venue.",
|
||||||
|
"quantity_remove_off": "Quantities can only go up at this venue.",
|
||||||
|
"quantity_invalid": "Choose a whole number from 1 to {{max}}.",
|
||||||
|
"quantity_line": "This line's quantity can't be changed here."
|
||||||
},
|
},
|
||||||
"notification": {
|
"notification": {
|
||||||
"not_found": "Notification {{notification_id}} not found."
|
"not_found": "Notification {{notification_id}} not found."
|
||||||
|
|||||||
@@ -759,6 +759,18 @@
|
|||||||
"reasonsHint": "Offered with one tap; staff can still type their own. None: the built-in ones.",
|
"reasonsHint": "Offered with one tap; staff can still type their own. None: the built-in ones.",
|
||||||
"reasonItem": "Quick reason",
|
"reasonItem": "Quick reason",
|
||||||
"newReason": "A new quick reason…"
|
"newReason": "A new quick reason…"
|
||||||
|
},
|
||||||
|
"quantity": {
|
||||||
|
"title": "Changing a sent line's quantity",
|
||||||
|
"intro": "Staff correct how many of a line there are without sending it to the kitchen again. Every change is kept in the order's history.",
|
||||||
|
"when": "Staff may",
|
||||||
|
"whenHint": "Who may: \"What each role may do\" and each person's permissions.",
|
||||||
|
"whenTip": "Only add: the quantity can go up (a beer taken from the fridge), nothing is printed. Add and remove: lowering it also cancels the difference as its own cancelled line, and asks whether to send a cancellation to the kitchen. Removing needs the permission to cancel too.",
|
||||||
|
"modes": {
|
||||||
|
"off": "Not at all",
|
||||||
|
"add_only": "Only add",
|
||||||
|
"add_and_remove": "Add and remove"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"logs": {
|
"logs": {
|
||||||
@@ -2813,7 +2825,10 @@
|
|||||||
"availableTip": "Off: it disappears from the waiters' and the counter's menus until you switch it back on (sold out today). Nothing else about it changes.",
|
"availableTip": "Off: it disappears from the waiters' and the counter's menus until you switch it back on (sold out today). Nothing else about it changes.",
|
||||||
"quickAddTip": "On: one tap in the waiter's product list adds it straight to the order without opening its choices. Leave it off for products whose choices must be picked (cooking, sides).",
|
"quickAddTip": "On: one tap in the waiter's product list adds it straight to the order without opening its choices. Leave it off for products whose choices must be picked (cooking, sides).",
|
||||||
"vatGroupTip": "The VAT rate the fiscal receipt uses for this product. Needed before it can be paid while the fiscal device is on.",
|
"vatGroupTip": "The VAT rate the fiscal receipt uses for this product. Needed before it can be paid while the fiscal device is on.",
|
||||||
"costTip": "What one unit costs you (ingredients, packaging). Reports use it for the profit; products without a cost make the profit a lower estimate."
|
"costTip": "What one unit costs you (ingredients, packaging). Reports use it for the profit; products without a cost make the profit a lower estimate.",
|
||||||
|
"oneMore": "One more (+1)",
|
||||||
|
"oneMoreHint": "A sent line of this product gets a +1 button on the phones and the counter.",
|
||||||
|
"oneMoreTip": "For what tables keep ordering again (beers, coffees). +1 orders the same again, with the same choices and note, at today's price, and sends it to the kitchen or bar like any new order. Off by default."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"menuTabletSettings": {
|
"menuTabletSettings": {
|
||||||
@@ -3392,7 +3407,9 @@
|
|||||||
"ORDER_CANCELLED": "Cancelled",
|
"ORDER_CANCELLED": "Cancelled",
|
||||||
"ITEM_CANCELLED": "Line cancelled",
|
"ITEM_CANCELLED": "Line cancelled",
|
||||||
"PRICE_CHANGED": "Price changed",
|
"PRICE_CHANGED": "Price changed",
|
||||||
"PRICE_SET_BY_HAND": "Price set by hand (approved)"
|
"PRICE_SET_BY_HAND": "Price set by hand (approved)",
|
||||||
|
"QUANTITY_CHANGED": "Quantity changed",
|
||||||
|
"ITEM_REORDERED": "One more"
|
||||||
},
|
},
|
||||||
"price": {
|
"price": {
|
||||||
"modifier_applied": "Price rule",
|
"modifier_applied": "Price rule",
|
||||||
|
|||||||
@@ -464,6 +464,9 @@
|
|||||||
"refunds": "Refund payments from other shifts",
|
"refunds": "Refund payments from other shifts",
|
||||||
"payments": {
|
"payments": {
|
||||||
"revert": "Turn paid items back to unpaid"
|
"revert": "Turn paid items back to unpaid"
|
||||||
|
},
|
||||||
|
"items": {
|
||||||
|
"change_quantity": "Change a sent line's quantity (no new ticket)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -466,6 +466,11 @@
|
|||||||
},
|
},
|
||||||
"dialog": {
|
"dialog": {
|
||||||
"close": "Close"
|
"close": "Close"
|
||||||
|
},
|
||||||
|
"oneMore": {
|
||||||
|
"send": "Send +{{count}}",
|
||||||
|
"label": "One more",
|
||||||
|
"sent": "{{count}} more {{name}} sent"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"display": {
|
"display": {
|
||||||
|
|||||||
@@ -529,7 +529,9 @@
|
|||||||
"moveItems": "Couldn't move the items",
|
"moveItems": "Couldn't move the items",
|
||||||
"flags": "Couldn't save the flags",
|
"flags": "Couldn't save the flags",
|
||||||
"combine": "Couldn't combine the lines",
|
"combine": "Couldn't combine the lines",
|
||||||
"price": "The price didn't change."
|
"price": "The price didn't change.",
|
||||||
|
"again": "One more wasn't sent.",
|
||||||
|
"quantity": "The quantity didn't change."
|
||||||
},
|
},
|
||||||
"openOrder": "Open an order",
|
"openOrder": "Open an order",
|
||||||
"noPaid": "No paid items",
|
"noPaid": "No paid items",
|
||||||
@@ -896,5 +898,25 @@
|
|||||||
"items_moved": "Lines moved",
|
"items_moved": "Lines moved",
|
||||||
"orders_merged": "Tables joined"
|
"orders_merged": "Tables joined"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"oneMore": {
|
||||||
|
"label": "One more",
|
||||||
|
"send": "Send +{{count}}"
|
||||||
|
},
|
||||||
|
"quantity": {
|
||||||
|
"title": "Change quantity",
|
||||||
|
"actionSub": "Correct how many; nothing is sent to the kitchen again",
|
||||||
|
"now": "Now",
|
||||||
|
"new": "New",
|
||||||
|
"less": "One less",
|
||||||
|
"more": "One more",
|
||||||
|
"save": "Save",
|
||||||
|
"upNote_one": "{{count}} more, without a new ticket",
|
||||||
|
"upNote_other": "{{count}} more, without a new ticket",
|
||||||
|
"downNote_one": "{{count}} will be cancelled",
|
||||||
|
"downNote_other": "{{count}} will be cancelled",
|
||||||
|
"noChange": "Use − and + to change it",
|
||||||
|
"onlyUp": "At this venue quantities only go up.",
|
||||||
|
"sendCancel": "Send a cancellation to the kitchen"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// "+1" on a sent line at the counter (plan 6F.5; the waiter app has the same): the first tap arms
|
||||||
|
// it, more taps count up, "Send +N" sends one more of the same line (printed as new); 4 s without
|
||||||
|
// a tap puts it back. Nothing is sent by one stray tap.
|
||||||
|
import { useEffect, useRef, useState } from 'react'
|
||||||
|
import { useTranslation } from '@xenia/i18n'
|
||||||
|
import { Button } from '@xenia/ui'
|
||||||
|
|
||||||
|
const WAIT_MS = 4000
|
||||||
|
|
||||||
|
export default function OneMore({ onSend }) {
|
||||||
|
const { t } = useTranslation('terminal')
|
||||||
|
const [count, setCount] = useState(0)
|
||||||
|
const [busy, setBusy] = useState(false)
|
||||||
|
const timer = useRef(null)
|
||||||
|
useEffect(() => () => clearTimeout(timer.current), [])
|
||||||
|
const tap = () => {
|
||||||
|
if (busy) return
|
||||||
|
setCount(c => Math.min(c + 1, 20))
|
||||||
|
clearTimeout(timer.current)
|
||||||
|
timer.current = setTimeout(() => setCount(0), WAIT_MS)
|
||||||
|
}
|
||||||
|
const send = async () => {
|
||||||
|
if (busy || !count) return
|
||||||
|
clearTimeout(timer.current)
|
||||||
|
setBusy(true)
|
||||||
|
try { await onSend(count) } finally { setBusy(false); setCount(0) }
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<span className="flex items-center gap-1.5 shrink-0 px-2" data-testid="one-more" data-armed={count ? 'true' : 'false'}>
|
||||||
|
{count > 0 && <Button size="sm" variant="primary" loading={busy} onClick={send} data-testid="one-more-send">{t('pos.oneMore.send', { count })}</Button>}
|
||||||
|
<Button size="sm" variant={count ? 'primary' : 'secondary'} onClick={tap} aria-label={t('pos.oneMore.label')} data-testid="one-more-tap">+{count || 1}</Button>
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ import client from '../../api/client'
|
|||||||
import CartLine from './CartLine'
|
import CartLine from './CartLine'
|
||||||
import { setLineQty } from './logic/cart'
|
import { setLineQty } from './logic/cart'
|
||||||
import { itemPayments, orderLines, orderSums, qtyLabel, tableState, toPay } from './logic/tables'
|
import { itemPayments, orderLines, orderSums, qtyLabel, tableState, toPay } from './logic/tables'
|
||||||
|
import OneMore from './OneMore'
|
||||||
import PaymentDialog from './PaymentDialog'
|
import PaymentDialog from './PaymentDialog'
|
||||||
import { PaidSummary } from './SaleCart'
|
import { PaidSummary } from './SaleCart'
|
||||||
import { useOrder, useQuote } from './usePos'
|
import { useOrder, useQuote } from './usePos'
|
||||||
@@ -111,7 +112,14 @@ export default function TablePanel({ table, cart, setCart, byId, canDiscount, on
|
|||||||
<span>{t('pos.table.onOrder')}</span><span>{formatMoney(sums.total)}</span>
|
<span>{t('pos.table.onOrder')}</span><span>{formatMoney(sums.total)}</span>
|
||||||
</h3>
|
</h3>
|
||||||
{lines.map(l => (
|
{lines.map(l => (
|
||||||
<OrderLine key={l.id} line={l} selected={selected.includes(l.id)} onToggle={() => toggle(l.id)} />
|
<div key={l.id} className="flex items-center border-b border-line">
|
||||||
|
<div className="flex-1 min-w-0"><OrderLine line={l} selected={selected.includes(l.id)} onToggle={() => toggle(l.id)} /></div>
|
||||||
|
{l.oneMore && <OneMore onSend={qty => run(async () => {
|
||||||
|
await client.post(`/api/orders/${orderId}/items/${l.id}/again`, { quantity: qty })
|
||||||
|
toast.success(t('pos.oneMore.sent', { count: qty, name: l.name }))
|
||||||
|
reload()
|
||||||
|
})} />}
|
||||||
|
</div>
|
||||||
))}
|
))}
|
||||||
</section>
|
</section>
|
||||||
)}
|
)}
|
||||||
@@ -230,11 +238,11 @@ function OrderLine({ line, selected, onToggle }) {
|
|||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
if (line.paid) {
|
if (line.paid) {
|
||||||
return <div className="px-3 py-2 border-b border-line text-ink-3" data-testid="order-line" data-item={line.id} data-paid="true">{body}</div>
|
return <div className="px-3 py-2 text-ink-3" data-testid="order-line" data-item={line.id} data-paid="true">{body}</div>
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<button type="button" onClick={onToggle} aria-pressed={selected} data-testid="order-line" data-item={line.id} data-paid="false"
|
<button type="button" onClick={onToggle} aria-pressed={selected} data-testid="order-line" data-item={line.id} data-paid="false"
|
||||||
className={`w-full text-left px-3 py-2 border-b border-line transition-colors duration-fast ${selected ? 'bg-accent-soft text-accent-ink' : 'text-ink hover:bg-surface-2'}`}>
|
className={`w-full text-left px-3 py-2 transition-colors duration-fast ${selected ? 'bg-accent-soft text-accent-ink' : 'text-ink hover:bg-surface-2'}`}>
|
||||||
{body}
|
{body}
|
||||||
</button>
|
</button>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ export function orderLines(order) {
|
|||||||
notes: i.notes,
|
notes: i.notes,
|
||||||
kds: i.kds_status ?? 'pending',
|
kds: i.kds_status ?? 'pending',
|
||||||
system: i.system_key ?? null, // a line the system added: 'delivery_fee' (phase 3S)
|
system: i.system_key ?? null, // a line the system added: 'delivery_fee' (phase 3S)
|
||||||
|
// "+1" (6F.5): the product allows it, in pieces, not a deal's line
|
||||||
|
oneMore: !!i.product?.one_more_enabled && (i.unit_type ?? 'piece') === 'piece' && !i.deal_id && !i.linked_item_id,
|
||||||
}))
|
}))
|
||||||
return [...lines.filter(l => !l.paid), ...lines.filter(l => l.paid)]
|
return [...lines.filter(l => !l.paid), ...lines.filter(l => l.paid)]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -749,6 +749,12 @@ try {
|
|||||||
r.check(`${st6} Operation: prices by hand "before sending only", a reason asked, a quick reason added`,
|
r.check(`${st6} Operation: prices by hand "before sending only", a reason asked, a quick reason added`,
|
||||||
pcMode === 'before_sending' && await settingValue2('orders.price_change_reason') === 'true' && reasonsNow.includes('E2E: birthday'))
|
pcMode === 'before_sending' && await settingValue2('orders.price_change_reason') === 'true' && reasonsNow.includes('E2E: birthday'))
|
||||||
await page.getByTestId('setting-orders.price_change').selectOption('anytime')
|
await page.getByTestId('setting-orders.price_change').selectOption('anytime')
|
||||||
|
// 6F.5: changing a sent line's quantity
|
||||||
|
await page.getByTestId('setting-orders.quantity_change').selectOption('add_only')
|
||||||
|
let qMode = ''
|
||||||
|
for (let i = 0; i < 30 && qMode !== 'add_only'; i++) { await sleep(150); qMode = await settingValue2('orders.quantity_change') }
|
||||||
|
r.check(`${st6} Operation: quantity changes "only add"`, qMode === 'add_only')
|
||||||
|
await page.getByTestId('setting-orders.quantity_change').selectOption('off')
|
||||||
await page.getByTestId('settings-price-changes').getByRole('switch').first().click()
|
await page.getByTestId('settings-price-changes').getByRole('switch').first().click()
|
||||||
await sleep(500)
|
await sleep(500)
|
||||||
await page.getByTestId('flag-new').click()
|
await page.getByTestId('flag-new').click()
|
||||||
|
|||||||
@@ -360,6 +360,75 @@ try {
|
|||||||
await setting(boss, 'orders.close_with_unpaid', 'false')
|
await setting(boss, 'orders.close_with_unpaid', 'false')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── 6F.5: "+1" on a sent line, and changing a line's quantity ─────────────────────
|
||||||
|
{
|
||||||
|
await api('PUT', `/api/products/${plain.id}`, { token: boss, body: { one_more_enabled: true } })
|
||||||
|
const mariaKeys = (await api('GET', `/api/waiters/${maria.id}/permissions`, { token: boss })).keys
|
||||||
|
await api('PUT', `/api/waiters/${maria.id}/permissions`, { token: boss,
|
||||||
|
body: { keys: [...new Set([...mariaKeys, 'ordering.items.change_quantity', 'ordering.orders.cancel'])] } })
|
||||||
|
await setting(boss, 'orders.quantity_change', 'add_and_remove')
|
||||||
|
const busyNow = new Set((await api('GET', '/api/orders/', { token: boss })).map(o => o.table_id))
|
||||||
|
const tm = (await api('GET', '/api/tables/', { token: boss })).find(x => x.is_active !== false && !busyNow.has(x.id))
|
||||||
|
const om = await api('POST', '/api/orders/', { token: tokenA, body: { table_id: tm.id } })
|
||||||
|
await api('POST', `/api/orders/${om.id}/items`, { token: tokenA, body: { lines: [{ product_id: plain.id, quantity: 1 }] } })
|
||||||
|
const count = async () => (await api('GET', `/api/orders/${om.id}`, { token: boss })).items.filter(i => i.status !== 'cancelled').length
|
||||||
|
await a.goto(`${APP}/tables/${tm.id}`)
|
||||||
|
await a.reload()
|
||||||
|
await a.getByTestId('one-more-tap').first().waitFor({ timeout: 10_000 })
|
||||||
|
// one stray tap sends nothing: it arms, then goes back after 4 s
|
||||||
|
await a.getByTestId('one-more-tap').first().click()
|
||||||
|
r.check('6F.5: one tap on +1 only arms it ("Send +1" shows)', await shown(a, 'one-more-send', 3000) && await count() === 1)
|
||||||
|
await a.screenshot({ path: path.join(OUT, 'waiter-one-more.png') })
|
||||||
|
await sleep(4600)
|
||||||
|
r.check('6F.5: …and with no second tap it goes back, nothing sent', !(await a.getByTestId('one-more-send').count()) && await count() === 1)
|
||||||
|
// tap, tap, Send → 2 more as a new line, sent like any new line
|
||||||
|
await a.getByTestId('one-more-tap').first().click()
|
||||||
|
await a.getByTestId('one-more-tap').first().click()
|
||||||
|
await a.getByTestId('one-more-send').first().click()
|
||||||
|
const again = await waitFor(async () => {
|
||||||
|
const o = await api('GET', `/api/orders/${om.id}`, { token: boss })
|
||||||
|
const live = o.items.filter(i => i.status === 'active')
|
||||||
|
return live.length === 2 && live[1].quantity === 2 && live[1].product_id === plain.id && o
|
||||||
|
}, 10_000, 500)
|
||||||
|
const newLine = again && again.items.filter(i => i.status === 'active')[1]
|
||||||
|
r.check('6F.5: +1, +1, Send: a new line of 2 for the kitchen (pending, like any new line)', !!newLine && newLine.kds_status === 'pending'
|
||||||
|
&& newLine.id !== again.items[0].id, JSON.stringify(again?.items?.map(i => [i.id, i.status, i.quantity, i.kds_status, i.printed])))
|
||||||
|
// change the first line's quantity: 1 → 3 (nothing printed), then 3 → 2 (one cancelled)
|
||||||
|
const first = again.items.filter(i => i.status === 'active')[0]
|
||||||
|
const openQty = async () => {
|
||||||
|
await a.goto(`${APP}/tables/${tm.id}`)
|
||||||
|
await a.locator('.order-item').first().waitFor({ timeout: 10_000 })
|
||||||
|
await a.locator('.order-item').first().click()
|
||||||
|
await a.getByRole('button', { name: 'ACTIONS', exact: true }).last().click()
|
||||||
|
await a.getByText('Change quantity').first().click({ timeout: 10_000 })
|
||||||
|
await a.getByTestId('quantity-sheet').waitFor({ timeout: 5000 })
|
||||||
|
}
|
||||||
|
await openQty()
|
||||||
|
await a.getByTestId('quantity-more').click()
|
||||||
|
await a.getByTestId('quantity-more').click()
|
||||||
|
r.check('6F.5: the dialog shows now 1 → new 3', (await a.getByTestId('quantity-now').textContent()) === '1' && (await a.getByTestId('quantity-new').textContent()) === '3')
|
||||||
|
await a.getByTestId('quantity-save').click()
|
||||||
|
const up = await waitFor(async () => (await api('GET', `/api/orders/${om.id}`, { token: boss })).items.find(i => i.id === first.id)?.quantity === 3, 10_000, 500)
|
||||||
|
r.check('6F.5: the line is now 3 (no new line, nothing sent again)', !!up && await count() === 2)
|
||||||
|
await openQty()
|
||||||
|
await a.getByTestId('quantity-less').click()
|
||||||
|
r.check('6F.5: lowering asks about a cancellation ticket', await a.getByTestId('quantity-ticket').isVisible())
|
||||||
|
await a.screenshot({ path: path.join(OUT, 'waiter-quantity.png') })
|
||||||
|
await a.getByTestId('quantity-save').click()
|
||||||
|
const down = await waitFor(async () => {
|
||||||
|
const o = await api('GET', `/api/orders/${om.id}`, { token: boss })
|
||||||
|
const part = o.items.find(i => i.status === 'cancelled' && i.split_from_id === first.id)
|
||||||
|
return o.items.find(i => i.id === first.id)?.quantity === 2 && part?.quantity === 1 && part
|
||||||
|
}, 10_000, 500)
|
||||||
|
r.check('6F.5: lowered to 2: one cancelled, kept apart ("quantity lowered")', !!down && down.cancel_reason === 'quantity lowered', JSON.stringify(down))
|
||||||
|
await setting(boss, 'orders.quantity_change', 'off')
|
||||||
|
await api('PUT', `/api/products/${plain.id}`, { token: boss, body: { one_more_enabled: false } })
|
||||||
|
await api('PUT', `/api/waiters/${maria.id}/permissions`, { token: boss, body: { keys: mariaKeys } })
|
||||||
|
await setting(boss, 'orders.close_with_unpaid', 'true')
|
||||||
|
await api('POST', `/api/orders/${om.id}/close`, { token: boss })
|
||||||
|
await setting(boss, 'orders.close_with_unpaid', 'false')
|
||||||
|
}
|
||||||
|
|
||||||
// ── 4.8: the owner's choices: combine lines, close with unpaid items, seats ─────────
|
// ── 4.8: the owner's choices: combine lines, close with unpaid items, seats ─────────
|
||||||
const t6 = free.find(t => t.id !== t4.id && t.id !== t5.id)
|
const t6 = free.find(t => t.id !== t4.id && t.id !== t5.id)
|
||||||
const o6 = await api('POST', '/api/orders/', { token: tokenA, body: { table_id: t6.id } })
|
const o6 = await api('POST', '/api/orders/', { token: tokenA, body: { table_id: t6.id } })
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
// "+1" on a sent line (plan 6F.5): one more of the same, sent to the kitchen like any new line.
|
||||||
|
// Nothing goes out on one stray tap: the first tap arms it (+1), more taps count up (+2, +3…),
|
||||||
|
// "Send" sends; 4 s without a tap puts it back.
|
||||||
|
import { useEffect, useRef, useState } from 'react'
|
||||||
|
import { useTranslation } from '@xenia/i18n'
|
||||||
|
|
||||||
|
const WAIT_MS = 4000
|
||||||
|
|
||||||
|
export default function OneMore({ onSend }) {
|
||||||
|
const { t } = useTranslation('waiter')
|
||||||
|
const [count, setCount] = useState(0)
|
||||||
|
const [busy, setBusy] = useState(false)
|
||||||
|
const timer = useRef(null)
|
||||||
|
useEffect(() => () => clearTimeout(timer.current), [])
|
||||||
|
const rearm = () => { clearTimeout(timer.current); timer.current = setTimeout(() => setCount(0), WAIT_MS) }
|
||||||
|
const stop = e => { e.stopPropagation() }
|
||||||
|
const tap = e => { stop(e); if (busy) return; setCount(c => Math.min(c + 1, 20)); rearm() }
|
||||||
|
const send = async e => {
|
||||||
|
stop(e)
|
||||||
|
if (busy || !count) return
|
||||||
|
clearTimeout(timer.current)
|
||||||
|
setBusy(true)
|
||||||
|
try { await onSend(count) } finally { setBusy(false); setCount(0) }
|
||||||
|
}
|
||||||
|
const round = {
|
||||||
|
width: 40, height: 40, borderRadius: '50%', flexShrink: 0, cursor: 'pointer', fontWeight: 800, fontSize: 14,
|
||||||
|
border: '1.5px solid rgb(var(--x-success-rgb) / 0.55)', background: count ? 'var(--x-success)' : 'rgb(var(--x-success-rgb) / 0.1)',
|
||||||
|
color: count ? 'rgb(var(--x-success-fg-rgb))' : 'var(--x-success)',
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div onClick={stop} onTouchStart={stop} style={{ display: 'flex', alignItems: 'center', gap: 6, padding: '0 8px 0 4px' }} data-testid="one-more" data-armed={count ? 'true' : 'false'}>
|
||||||
|
{count > 0 && (
|
||||||
|
<button type="button" onClick={send} disabled={busy} data-testid="one-more-send" style={{
|
||||||
|
height: 36, padding: '0 12px', borderRadius: 18, border: 'none', cursor: 'pointer', fontWeight: 800, fontSize: 13,
|
||||||
|
background: 'var(--x-success)', color: 'rgb(var(--x-success-fg-rgb))', whiteSpace: 'nowrap',
|
||||||
|
}}>
|
||||||
|
{busy ? '…' : t('oneMore.send', { count })}
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
<button type="button" onClick={tap} aria-label={t('oneMore.label')} style={round} data-testid="one-more-tap">
|
||||||
|
+{count || 1}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -3,6 +3,8 @@ import useTableViewStore from '../store/tableViewStore'
|
|||||||
import { money } from '../i18n'
|
import { money } from '../i18n'
|
||||||
import { useTranslation } from '@xenia/i18n'
|
import { useTranslation } from '@xenia/i18n'
|
||||||
import { fade } from '../logic/colour'
|
import { fade } from '../logic/colour'
|
||||||
|
import OneMore from './OneMore'
|
||||||
|
import { canOneMore } from '../logic/lines'
|
||||||
|
|
||||||
const fmtPrice = money
|
const fmtPrice = money
|
||||||
|
|
||||||
@@ -688,7 +690,7 @@ function ItemRow({ item, selectable, selected, onToggle, onLongPress, isLast, kd
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function OrderSummary({ order, selectable = false, selectedIds = [], onToggle, onLongPressItem, waiterMap, courses = [], priceEventsMap = {}, movedItems = {} }) {
|
export default function OrderSummary({ order, selectable = false, selectedIds = [], onToggle, onLongPressItem, waiterMap, courses = [], priceEventsMap = {}, movedItems = {}, onOneMore }) {
|
||||||
const { t } = useTranslation('waiter')
|
const { t } = useTranslation('waiter')
|
||||||
const kdsDisplayStyle = useTableViewStore(s => s.kdsDisplayStyle || 'badge')
|
const kdsDisplayStyle = useTableViewStore(s => s.kdsDisplayStyle || 'badge')
|
||||||
const orderItemLayout = useTableViewStore(s => s.orderItemLayout || 'compact')
|
const orderItemLayout = useTableViewStore(s => s.orderItemLayout || 'compact')
|
||||||
@@ -704,8 +706,10 @@ export default function OrderSummary({ order, selectable = false, selectedIds =
|
|||||||
<div className="order-summary">
|
<div className="order-summary">
|
||||||
{activeItems.length === 0 && <p style={{ color: 'var(--x-ink-3)', textAlign: 'center' }}>{t('summary.noItems')}</p>}
|
{activeItems.length === 0 && <p style={{ color: 'var(--x-ink-3)', textAlign: 'center' }}>{t('summary.noItems')}</p>}
|
||||||
{activeItems.map((item, idx) => (
|
{activeItems.map((item, idx) => (
|
||||||
|
// 6F.5: "+1" beside a line whose product allows it, outside the line's own tap area
|
||||||
|
<div key={item.id} style={{ display: 'flex', alignItems: 'center' }}>
|
||||||
|
<div style={{ flex: 1, minWidth: 0 }}>
|
||||||
<ItemRow
|
<ItemRow
|
||||||
key={item.id}
|
|
||||||
item={item}
|
item={item}
|
||||||
selectable={selectable}
|
selectable={selectable}
|
||||||
selected={selectedIds.includes(item.id)}
|
selected={selectedIds.includes(item.id)}
|
||||||
@@ -719,6 +723,9 @@ export default function OrderSummary({ order, selectable = false, selectedIds =
|
|||||||
priceEvents={priceEventsMap[item.id] ?? []}
|
priceEvents={priceEventsMap[item.id] ?? []}
|
||||||
moved={!!movedItems[item.id]}
|
moved={!!movedItems[item.id]}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
{onOneMore && canOneMore(item) && <OneMore onSend={qty => onOneMore(item, qty)} />}
|
||||||
|
</div>
|
||||||
))}
|
))}
|
||||||
<div className="order-summary__total">
|
<div className="order-summary__total">
|
||||||
<span>{t('common.total')}</span>
|
<span>{t('common.total')}</span>
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
// Change a sent line's quantity (plan 6F.5): nothing is sent to the kitchen again. The current
|
||||||
|
// quantity stays big beside the new one so a slip is seen; lowering it cancels the difference and
|
||||||
|
// asks whether to send a cancellation (yes while the kitchen hasn't finished it).
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { useTranslation } from '@xenia/i18n'
|
||||||
|
import { cancelByDefault, lowestQuantity } from '../logic/lines'
|
||||||
|
|
||||||
|
export default function QuantityModal({ item, mode, error, busy, onSave, onClose }) {
|
||||||
|
const { t } = useTranslation('waiter')
|
||||||
|
const now = item.quantity
|
||||||
|
const [qty, setQty] = useState(now)
|
||||||
|
const [ticket, setTicket] = useState(() => cancelByDefault(item))
|
||||||
|
const low = lowestQuantity(item, mode)
|
||||||
|
const lowering = qty < now
|
||||||
|
const step = d => setQty(q => Math.max(low, Math.min(999, q + d)))
|
||||||
|
const btn = { width: 56, height: 56, borderRadius: '50%', border: '1.5px solid var(--border)', background: 'var(--bg3)', fontSize: 26, fontWeight: 700, color: 'var(--text)', cursor: 'pointer' }
|
||||||
|
return (
|
||||||
|
<div className="modal-overlay" onClick={busy ? undefined : onClose}>
|
||||||
|
<div className="modal-sheet" onClick={e => e.stopPropagation()} data-testid="quantity-sheet">
|
||||||
|
<div className="modal-handle" />
|
||||||
|
<h2 className="modal-title">{t('quantity.title')}</h2>
|
||||||
|
<p style={{ textAlign: 'center', color: 'var(--muted)', fontSize: 13, margin: '0 0 14px' }}>{item.product_name || item.product?.name}</p>
|
||||||
|
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 18, marginBottom: 6 }}>
|
||||||
|
<div style={{ textAlign: 'center' }}>
|
||||||
|
<div style={{ fontSize: 12, color: 'var(--muted)', fontWeight: 700 }}>{t('quantity.now')}</div>
|
||||||
|
<div style={{ fontSize: 30, fontWeight: 800, color: 'var(--muted)' }} data-testid="quantity-now">{now}</div>
|
||||||
|
</div>
|
||||||
|
<span style={{ fontSize: 22, color: 'var(--muted)' }}>→</span>
|
||||||
|
<div style={{ textAlign: 'center' }}>
|
||||||
|
<div style={{ fontSize: 12, color: 'var(--muted)', fontWeight: 700 }}>{t('quantity.new')}</div>
|
||||||
|
<div style={{ fontSize: 44, fontWeight: 800, color: qty === now ? 'var(--text)' : lowering ? 'var(--x-danger)' : 'var(--x-success)' }} data-testid="quantity-new">{qty}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div style={{ display: 'flex', justifyContent: 'center', gap: 28, margin: '8px 0 14px' }}>
|
||||||
|
<button type="button" style={btn} onClick={() => step(-1)} disabled={qty <= low} aria-label={t('quantity.less')} data-testid="quantity-less">−</button>
|
||||||
|
<button type="button" style={btn} onClick={() => step(1)} aria-label={t('quantity.more')} data-testid="quantity-more">+</button>
|
||||||
|
</div>
|
||||||
|
<p style={{ textAlign: 'center', fontSize: 13, color: 'var(--muted)', margin: '0 0 12px' }}>
|
||||||
|
{qty > now ? t('quantity.upNote', { count: qty - now }) : lowering ? t('quantity.downNote', { count: now - qty }) : t('quantity.noChange')}
|
||||||
|
</p>
|
||||||
|
{mode === 'add_only' && <p style={{ textAlign: 'center', fontSize: 12, color: 'var(--muted)', margin: '0 0 12px' }}>{t('quantity.onlyUp')}</p>}
|
||||||
|
{lowering && (
|
||||||
|
<label style={{ display: 'flex', alignItems: 'center', gap: 10, padding: '10px 12px', borderRadius: 12, background: 'var(--bg3)', border: '1px solid var(--border)', marginBottom: 12, fontSize: 14 }}>
|
||||||
|
<input type="checkbox" checked={ticket} onChange={e => setTicket(e.target.checked)} data-testid="quantity-ticket" style={{ width: 20, height: 20 }} />
|
||||||
|
<span>{t('quantity.sendCancel')}</span>
|
||||||
|
</label>
|
||||||
|
)}
|
||||||
|
{error && <p role="alert" style={{ color: 'var(--x-danger)', fontSize: 13, textAlign: 'center', margin: '0 0 10px' }}>{error}</p>}
|
||||||
|
<div style={{ display: 'flex', gap: 10 }}>
|
||||||
|
<button className="btn btn--secondary" style={{ flex: 1 }} onClick={onClose} disabled={busy}>{t('common.cancel')}</button>
|
||||||
|
<button className={lowering ? 'btn btn--danger' : 'btn btn--primary'} style={{ flex: 1 }} disabled={busy || qty === now}
|
||||||
|
onClick={() => onSave(qty, lowering && ticket)} data-testid="quantity-save">{t('quantity.save')}</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// The venue's orders.quantity_change (6F.5, logic/lines.js), from the shared settings request.
|
||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import { getVenueSettings } from '../api/venueSettings'
|
||||||
|
import { quantityMode } from '../logic/lines'
|
||||||
|
|
||||||
|
export function useQuantityMode() {
|
||||||
|
const [mode, setMode] = useState('off')
|
||||||
|
useEffect(() => {
|
||||||
|
let alive = true
|
||||||
|
getVenueSettings().then(r => { if (alive) setMode(quantityMode(r.data)) }).catch(() => {})
|
||||||
|
return () => { alive = false }
|
||||||
|
}, [])
|
||||||
|
return mode
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
// A sent line's "one more" and quantity rules (plan 6F.5). Plain JS so Node tests can import it.
|
||||||
|
|
||||||
|
/** The venue's orders.quantity_change: 'off' | 'add_only' | 'add_and_remove'. */
|
||||||
|
export function quantityMode(settings) {
|
||||||
|
const v = settings?.['orders.quantity_change']?.value
|
||||||
|
return ['off', 'add_only', 'add_and_remove'].includes(v) ? v : 'off'
|
||||||
|
}
|
||||||
|
|
||||||
|
const PIECE = item => (item?.unit_type || item?.product?.unit_type || 'piece') === 'piece'
|
||||||
|
|
||||||
|
/** A line that shows +1: its product allows it, counted in pieces, not cancelled, not a deal's. */
|
||||||
|
export function canOneMore(item) {
|
||||||
|
return !!item?.product?.one_more_enabled && PIECE(item) && ['active', 'paid', 'tabbed'].includes(item.status)
|
||||||
|
&& !item.deal_id && !item.linked_item_id
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A line whose quantity may change: unpaid, in whole pieces, not a deal's. */
|
||||||
|
export function canChangeQuantity(item, mode) {
|
||||||
|
return mode !== 'off' && item?.status === 'active' && PIECE(item) && Number.isInteger(item.quantity)
|
||||||
|
&& !item.deal_id && !item.linked_item_id
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Lowering a line: send a cancellation to the kitchen? Yes while it is still waiting or being made. */
|
||||||
|
export function cancelByDefault(item) {
|
||||||
|
return ['pending', 'preparing'].includes(item?.kds_status || 'pending')
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The lowest quantity the dialog allows. */
|
||||||
|
export function lowestQuantity(item, mode) {
|
||||||
|
return mode === 'add_and_remove' ? 1 : item.quantity
|
||||||
|
}
|
||||||
@@ -20,6 +20,9 @@ import PriceReason from '../components/PriceReason'
|
|||||||
import { priceReasonText } from '../logic/priceRules'
|
import { priceReasonText } from '../logic/priceRules'
|
||||||
import PriceHistory from '../components/PriceHistory'
|
import PriceHistory from '../components/PriceHistory'
|
||||||
import MoveHistory, { MovedOrderBanner } from '../components/MoveHistory'
|
import MoveHistory, { MovedOrderBanner } from '../components/MoveHistory'
|
||||||
|
import QuantityModal from '../components/QuantityModal'
|
||||||
|
import { useQuantityMode } from '../hooks/useQuantityMode'
|
||||||
|
import { canChangeQuantity } from '../logic/lines'
|
||||||
import { usePriceRules } from '../hooks/usePriceRules'
|
import { usePriceRules } from '../hooks/usePriceRules'
|
||||||
import { fade } from '../logic/colour'
|
import { fade } from '../logic/colour'
|
||||||
import SeatsHint from '../components/SeatsHint'
|
import SeatsHint from '../components/SeatsHint'
|
||||||
@@ -266,7 +269,7 @@ function PriceAdjustModal({ item, rules, error, onConfirm, onClose }) {
|
|||||||
|
|
||||||
// ─── Item action modal (long-press) ──────────────────────────────────────────
|
// ─── Item action modal (long-press) ──────────────────────────────────────────
|
||||||
|
|
||||||
function ItemActionModal({ target, onOrderAgain, onSplit, onMoveToTable, onCancel, onCombine, canCancel, cancelNeedsApproval, priceAdjAllowed, priceNeedsApproval, canMove, onAdjustPrice, canSeePriceHistory, onPriceHistory, movedLine, onMoveHistory, onClose }) {
|
function ItemActionModal({ target, onOrderAgain, onSplit, onMoveToTable, onCancel, onCombine, canCancel, cancelNeedsApproval, priceAdjAllowed, priceNeedsApproval, canMove, onAdjustPrice, canSeePriceHistory, onPriceHistory, movedLine, onMoveHistory, canChangeQty, onChangeQty, onClose }) {
|
||||||
const { t } = useTranslation('waiter')
|
const { t } = useTranslation('waiter')
|
||||||
const { items, singleStacked, multiSelect } = target
|
const { items, singleStacked, multiSelect } = target
|
||||||
const label = multiSelect
|
const label = multiSelect
|
||||||
@@ -274,6 +277,22 @@ function ItemActionModal({ target, onOrderAgain, onSplit, onMoveToTable, onCance
|
|||||||
: items[0]?.product?.name || `#${items[0]?.product_id}`
|
: items[0]?.product?.name || `#${items[0]?.product_id}`
|
||||||
|
|
||||||
const actionRows = [
|
const actionRows = [
|
||||||
|
// 6F.5: correct how many there are, without sending it to the kitchen again
|
||||||
|
...(!multiSelect && canChangeQty ? [{
|
||||||
|
key: 'change_quantity',
|
||||||
|
color: 'var(--x-accent)',
|
||||||
|
iconBg: 'rgb(var(--x-accent-rgb) / 0.15)',
|
||||||
|
label: t('quantity.title'),
|
||||||
|
sub: t('quantity.actionSub'),
|
||||||
|
icon: (
|
||||||
|
<svg width="18" height="18" viewBox="0 0 24 24" fill="none">
|
||||||
|
<path d="M5 12h4M7 10v4M15 12h4" stroke="var(--x-accent)" strokeWidth="2" strokeLinecap="round" />
|
||||||
|
<rect x="2" y="5" width="20" height="14" rx="3" stroke="var(--x-accent)" strokeWidth="2" />
|
||||||
|
</svg>
|
||||||
|
),
|
||||||
|
onClick: onChangeQty,
|
||||||
|
enabled: true,
|
||||||
|
}] : []),
|
||||||
// 6F.4: where this line has been (tables, orders), however many moves
|
// 6F.4: where this line has been (tables, orders), however many moves
|
||||||
...(!multiSelect && movedLine ? [{
|
...(!multiSelect && movedLine ? [{
|
||||||
key: 'move_history',
|
key: 'move_history',
|
||||||
@@ -1184,6 +1203,12 @@ export default function TableDetailPage() {
|
|||||||
const [priceEventsMap, setPriceEventsMap] = useState({})
|
const [priceEventsMap, setPriceEventsMap] = useState({})
|
||||||
const [moves, setMoves] = useState({ order: [], items: {} }) // 6F.4: where the order and its lines came from
|
const [moves, setMoves] = useState({ order: [], items: {} }) // 6F.4: where the order and its lines came from
|
||||||
const [moveSheet, setMoveSheet] = useState(null) // { title, subtitle, moves, itemId }
|
const [moveSheet, setMoveSheet] = useState(null) // { title, subtitle, moves, itemId }
|
||||||
|
// 6F.5: a line's quantity (no new ticket) and "+1" (one more, sent as new)
|
||||||
|
const quantityMode = useQuantityMode()
|
||||||
|
const quantityAccess = useAllowed('ordering.items.change_quantity')
|
||||||
|
const [qtyItem, setQtyItem] = useState(null)
|
||||||
|
const [qtyError, setQtyError] = useState('')
|
||||||
|
const [qtyBusy, setQtyBusy] = useState(false)
|
||||||
const [cancelConfirm, setCancelConfirm] = useState(null) // null | { mode: 'items', ids: [...] } | { mode: 'order' }
|
const [cancelConfirm, setCancelConfirm] = useState(null) // null | { mode: 'items', ids: [...] } | { mode: 'order' }
|
||||||
const [paidSelectedIds, setPaidSelectedIds] = useState([])
|
const [paidSelectedIds, setPaidSelectedIds] = useState([])
|
||||||
|
|
||||||
@@ -1938,6 +1963,12 @@ export default function TableDetailPage() {
|
|||||||
waiterMap={waiterMap}
|
waiterMap={waiterMap}
|
||||||
priceEventsMap={priceEventsMap}
|
priceEventsMap={priceEventsMap}
|
||||||
movedItems={moves.items}
|
movedItems={moves.items}
|
||||||
|
onOneMore={canInteract && !paying && !isOffline ? async (item, qty) => {
|
||||||
|
try {
|
||||||
|
await client.post(`/api/orders/${order.id}/items/${item.id}/again`, { quantity: qty })
|
||||||
|
await load()
|
||||||
|
} catch (err) { setError(apiError(err, t('detail.err.again'))) }
|
||||||
|
} : undefined}
|
||||||
onLongPressItem={(item) => {
|
onLongPressItem={(item) => {
|
||||||
if (selectedIds.length > 1) {
|
if (selectedIds.length > 1) {
|
||||||
const items = displayActiveItems.filter(i => selectedIds.includes(i.id))
|
const items = displayActiveItems.filter(i => selectedIds.includes(i.id))
|
||||||
@@ -2027,6 +2058,12 @@ export default function TableDetailPage() {
|
|||||||
<>
|
<>
|
||||||
<OrderSummary
|
<OrderSummary
|
||||||
order={{ ...order, items: paidItems }}
|
order={{ ...order, items: paidItems }}
|
||||||
|
onOneMore={canInteract && !paying && !isOffline ? async (item, qty) => { // 6F.5: the beer already paid for
|
||||||
|
try {
|
||||||
|
await client.post(`/api/orders/${order.id}/items/${item.id}/again`, { quantity: qty })
|
||||||
|
await load()
|
||||||
|
} catch (err) { setError(apiError(err, t('detail.err.again'))) }
|
||||||
|
} : undefined}
|
||||||
selectable={canInteract}
|
selectable={canInteract}
|
||||||
selectedIds={paidSelectedIds}
|
selectedIds={paidSelectedIds}
|
||||||
waiterMap={waiterMap}
|
waiterMap={waiterMap}
|
||||||
@@ -2265,6 +2302,13 @@ export default function TableDetailPage() {
|
|||||||
}}
|
}}
|
||||||
canSeePriceHistory={seesPriceChanges && !isOffline}
|
canSeePriceHistory={seesPriceChanges && !isOffline}
|
||||||
movedLine={!!moves.items[itemActionTarget.items[0]?.id]}
|
movedLine={!!moves.items[itemActionTarget.items[0]?.id]}
|
||||||
|
canChangeQty={quantityAccess !== 'no' && !isOffline && canChangeQuantity(itemActionTarget.items[0], quantityMode)}
|
||||||
|
onChangeQty={() => {
|
||||||
|
const item = itemActionTarget.items[0]
|
||||||
|
setItemActionTarget(null)
|
||||||
|
setQtyError('')
|
||||||
|
setQtyItem(item)
|
||||||
|
}}
|
||||||
onMoveHistory={() => {
|
onMoveHistory={() => {
|
||||||
const item = itemActionTarget.items[0]
|
const item = itemActionTarget.items[0]
|
||||||
setItemActionTarget(null)
|
setItemActionTarget(null)
|
||||||
@@ -2320,6 +2364,18 @@ export default function TableDetailPage() {
|
|||||||
|
|
||||||
{historyItem && <PriceHistory orderId={order.id} item={historyItem} onClose={() => setHistoryItem(null)} />}
|
{historyItem && <PriceHistory orderId={order.id} item={historyItem} onClose={() => setHistoryItem(null)} />}
|
||||||
{moveSheet && <MoveHistory {...moveSheet} onClose={() => setMoveSheet(null)} />}
|
{moveSheet && <MoveHistory {...moveSheet} onClose={() => setMoveSheet(null)} />}
|
||||||
|
{qtyItem && (
|
||||||
|
<QuantityModal item={qtyItem} mode={quantityMode} error={qtyError} busy={qtyBusy}
|
||||||
|
onClose={() => { setQtyItem(null); setQtyError('') }}
|
||||||
|
onSave={async (quantity, ticket) => {
|
||||||
|
setQtyBusy(true); setQtyError('')
|
||||||
|
try {
|
||||||
|
await client.post(`/api/orders/${order.id}/items/${qtyItem.id}/quantity`, { quantity, print_cancellation: ticket })
|
||||||
|
setQtyItem(null)
|
||||||
|
await load()
|
||||||
|
} catch (err) { setQtyError(apiError(err, t('detail.err.quantity'))) } finally { setQtyBusy(false) }
|
||||||
|
}} />
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Cancel confirmation */}
|
{/* Cancel confirmation */}
|
||||||
{cancelConfirm && (
|
{cancelConfirm && (
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import { test } from 'node:test'
|
||||||
|
import { cancelByDefault, canChangeQuantity, canOneMore, lowestQuantity, quantityMode } from '../src/logic/lines.js'
|
||||||
|
|
||||||
|
const beer = (o = {}) => ({ status: 'active', quantity: 3, unit_type: 'piece', product: { one_more_enabled: true }, kds_status: 'pending', ...o })
|
||||||
|
|
||||||
|
test('one more: the product allows it, pieces, a line still there (6F.5)', () => {
|
||||||
|
assert.equal(canOneMore(beer()), true)
|
||||||
|
assert.equal(canOneMore(beer({ status: 'paid' })), true)
|
||||||
|
assert.equal(canOneMore(beer({ status: 'cancelled' })), false)
|
||||||
|
assert.equal(canOneMore(beer({ product: { one_more_enabled: false } })), false)
|
||||||
|
assert.equal(canOneMore(beer({ unit_type: 'kg' })), false)
|
||||||
|
assert.equal(canOneMore(beer({ deal_id: 4 })), false)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('changing a quantity: the venue, unpaid whole pieces; how low; the ticket question', () => {
|
||||||
|
const s = v => ({ 'orders.quantity_change': { value: v } })
|
||||||
|
assert.equal(quantityMode(null), 'off')
|
||||||
|
assert.equal(quantityMode(s('add_only')), 'add_only')
|
||||||
|
assert.equal(quantityMode(s('nonsense')), 'off')
|
||||||
|
assert.equal(canChangeQuantity(beer(), 'off'), false)
|
||||||
|
assert.equal(canChangeQuantity(beer(), 'add_only'), true)
|
||||||
|
assert.equal(canChangeQuantity(beer({ status: 'paid' }), 'add_and_remove'), false)
|
||||||
|
assert.equal(canChangeQuantity(beer({ quantity: 1.5 }), 'add_and_remove'), false)
|
||||||
|
assert.equal(lowestQuantity(beer(), 'add_only'), 3)
|
||||||
|
assert.equal(lowestQuantity(beer(), 'add_and_remove'), 1)
|
||||||
|
assert.equal(cancelByDefault(beer({ kds_status: 'preparing' })), true)
|
||||||
|
assert.equal(cancelByDefault(beer({ kds_status: 'served' })), false)
|
||||||
|
assert.equal(cancelByDefault(beer({ kds_status: 'done' })), false)
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user