"""Order channel prices (UI review 2026-11-20): a product's price at a sales point, per product, per category or for the whole channel; the most precise rule wins (product > category > channel), and the channel price is the base the price modifiers work on, everywhere prices are made.""" from services.pos_cart import unit_prices from tests.test_live import owner_h # noqa: F401 (fixtures) from tests.test_pos import menu # noqa: F401 (fixtures) def _rule(client, h, **body): r = client.post("/api/pricing/channel-prices", headers=h, json=body) assert r.status_code == 201, r.text return r.json() def test_the_most_precise_rule_wins(client, db, owner_h, menu): burger, coffee = menu["burger"], menu["coffee"] on = lambda p, sp: round(unit_prices(db, [p], sp)[0], 2) # noqa: E731 assert on(burger, "online_delivery") == 10.0 # the whole delivery channel: +10 % _rule(client, owner_h, sales_points=["online_delivery"], action_type="add_percent", value=10) assert on(burger, "online_delivery") == 11.0 and on(coffee, "online_delivery") == 3.3 and on(burger, "in_store") == 10.0 # the drinks' category: +0.50 on delivery and takeaway (beats the channel rule) _rule(client, owner_h, sales_points=["online_delivery", "online_takeaway"], category_ids=[coffee.primary_category_id], action_type="add_amount", value=0.5) assert on(coffee, "online_delivery") == 3.5 and on(coffee, "online_takeaway") == 3.5 and on(burger, "online_delivery") == 11.0 # the coffee itself: set to 2.80 on delivery (beats the category) _rule(client, owner_h, sales_points=["online_delivery"], product_ids=[coffee.id], action_type="set", value=2.8) assert on(coffee, "online_delivery") == 2.8 and on(coffee, "online_takeaway") == 3.5 def test_a_set_price_is_for_one_product(client, owner_h, menu): r = client.post("/api/pricing/channel-prices", headers=owner_h, json={ "sales_points": ["qr_table"], "category_ids": [menu["coffee"].primary_category_id], "action_type": "set", "value": 2}) assert r.status_code == 400 and r.json()["error"]["code"] == "channel_price.set_one_product" r = client.post("/api/pricing/channel-prices", headers=owner_h, json={"sales_points": [], "action_type": "add_amount", "value": 1}) assert r.status_code == 400 def test_the_product_editor_quick_edit(client, db, owner_h, menu): burger = menu["burger"] _rule(client, owner_h, sales_points=["online_takeaway"], action_type="add_amount", value=1) r = client.put(f"/api/pricing/channel-prices/product/{burger.id}", headers=owner_h, json={"points": { "in_store_takeaway": {"action_type": "add_percent", "value": -10, "round_to": "0.50"}}}) assert r.status_code == 200, r.text rows = {x["sales_point"]: x for x in r.json()["points"]} assert rows["in_store_takeaway"]["price"] == 9.0 and rows["in_store_takeaway"]["own"]["action_type"] == "add_percent" assert rows["online_takeaway"]["price"] == 11.0 and rows["online_takeaway"]["rule"]["level"] == "channel" and rows["online_takeaway"]["own"] is None assert rows["in_store"]["price"] == 10.0 and rows["in_store"]["rule"] is None # removed: back to the default r = client.put(f"/api/pricing/channel-prices/product/{burger.id}", headers=owner_h, json={"points": {"in_store_takeaway": None}}) assert {x["sales_point"]: x for x in r.json()["points"]}["in_store_takeaway"]["price"] == 10.0