feat: one way to count sales in every report; exports for Excel; the report kit and Today on v2 (platform-v2 step 6.12a)
- services/sales.py: sold = active + paid lines; a line's value net of what
was refunded of it; system lines (the delivery fee) counted apart as fees;
cost/profit with has_gap. Products, categories, tables, traffic, revenue
trends, business days (list and current), per-waiter sales, order history
totals and the printed products/categories/tables reports all use it (they
used to differ: closed-only vs all orders, fee as a product, refunds never
subtracted)
- the overview's day summary values lines with their price change (discounts
were valued at full price)
- services/csv_export.py: UTF-8 BOM, times in venue time with the zone in the
header, ';' and decimal commas for a Greek venue (',' and '.' otherwise);
every report export uses it; orders export has products / fees / refunded
- fix: /api/reports/shift/orders with business_day_id crashed (no window)
- manager: src/pages/reports/kit (page with tabs, period picker, panels,
figures, sortable table, export button, order dialog reusing the order
page's parts, hour chart on tokens) and reports/today on it; v1 Today removed
- tests: test_sales_accounting.py (a day with a fee and a partial refund adds
up the same in every report), test_reports_export.py (Excel format),
reports.test.mjs, e2e manager.mjs (Today, order dialog, export, Greek)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -246,6 +246,7 @@ def business_day_summary(
|
||||
if not day:
|
||||
raise XeniaError("business_day.none_open")
|
||||
|
||||
from services.sales import gross # 6.12a: a line's value includes its price change (discounts)
|
||||
orders = db.query(Order).filter(Order.business_day_id == day.id).all()
|
||||
order_ids = [o.id for o in orders]
|
||||
|
||||
@@ -309,12 +310,12 @@ def business_day_summary(
|
||||
continue
|
||||
e = _waiter_entry(item.added_by)
|
||||
e["items_ordered"] += item.quantity
|
||||
e["total_items_value"] += item.unit_price * item.quantity
|
||||
e["total_items_value"] += gross(item)
|
||||
|
||||
for item in paid_items:
|
||||
if item.paid_by:
|
||||
e = _waiter_entry(item.paid_by)
|
||||
val = item.unit_price * item.quantity
|
||||
val = gross(item)
|
||||
e["items_paid"] += item.quantity
|
||||
e["total_collected"] += val
|
||||
method = (item.payment_method or "cash").lower()
|
||||
@@ -392,11 +393,11 @@ def business_day_summary(
|
||||
continue
|
||||
entry["items"] += item.quantity
|
||||
if item.status == "paid":
|
||||
entry["revenue"] += item.unit_price * item.quantity
|
||||
entry["revenue"] += gross(item)
|
||||
|
||||
# ── Per-printer summary ─────────────────────────────────────────────────
|
||||
# Build item_id → value lookup for revenue-per-printer calculation
|
||||
items_value_map = {i.id: i.unit_price * i.quantity for i in all_items if i.status != "cancelled"}
|
||||
items_value_map = {i.id: gross(i) for i in all_items if i.status != "cancelled"}
|
||||
|
||||
printer_stats: dict = {}
|
||||
if order_ids:
|
||||
@@ -438,7 +439,7 @@ def business_day_summary(
|
||||
)
|
||||
active_shift_count = sum(1 for s in shifts if s.ended_at is None)
|
||||
|
||||
total_revenue = sum(i.unit_price * i.quantity for i in paid_items)
|
||||
total_revenue = sum(gross(i) for i in paid_items)
|
||||
total_items_ordered = sum(i.quantity for i in all_items if i.status != "cancelled")
|
||||
total_orders = sum(1 for o in orders if o.status != "cancelled")
|
||||
|
||||
@@ -462,7 +463,7 @@ def business_day_summary(
|
||||
cogs_uncosted_revenue = 0.0
|
||||
cogs_uncosted_count = 0
|
||||
for item in paid_items:
|
||||
rev = item.unit_price * item.quantity
|
||||
rev = gross(item)
|
||||
if item.unit_cost is not None:
|
||||
cogs_trackable += item.unit_cost * item.quantity
|
||||
else:
|
||||
@@ -494,7 +495,7 @@ def business_day_summary(
|
||||
|
||||
# TABBED REVENUE (items moved to tabs — not yet collected)
|
||||
tabbed_items = [i for i in all_items if i.status == "tabbed"]
|
||||
tabbed_revenue = round(sum(i.unit_price * i.quantity for i in tabbed_items), 2)
|
||||
tabbed_revenue = round(sum(gross(i) for i in tabbed_items), 2)
|
||||
|
||||
# NET estimate (revenue - COGS - labor - waste - expenses paid)
|
||||
net_estimate = round(
|
||||
|
||||
Reference in New Issue
Block a user