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:
2026-11-23 08:26:46 +02:00
co-authored by Claude Opus 5.5
parent 0a353c5f97
commit 72e175ab73
35 changed files with 813 additions and 35 deletions
+123
View File
@@ -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"