fix: printer history report double-counts order totals on reprints

Backend (reports.py):
  - Cache order DB objects to avoid N+1 queries per log entry
  - Track seen_order_totals keyed by order_id so reprinting the same
    order doesn't inflate the total; returns total_amount pre-computed

Frontend (PrinterHistory.jsx):
  - Remove client-side accumulation that caused the same issue; use
    total_amount directly from the API response

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-31 23:54:07 +03:00
parent 18a75edf2a
commit 38bef6b1f4
2 changed files with 28 additions and 4 deletions

View File

@@ -289,16 +289,16 @@ export default function PrinterHistory() {
const logs = data?.logs || []
const total = data?.total || 0
const failed = data?.failed || 0
// total_amount comes pre-computed from the backend (unique orders, no double-counting reprints)
const totalAmount = data?.total_amount ?? null
// Derived stats for StatCards + Print modal
const itemCounts = {}
const waiterCounts = {}
let totalItemQty = 0
let totalAmount = null
logs.forEach(l => {
if (l.waiter) waiterCounts[l.waiter] = (waiterCounts[l.waiter] || 0) + 1
if (l.order_total != null) totalAmount = (totalAmount || 0) + l.order_total
;(l.items || []).forEach(i => {
itemCounts[i.name] = (itemCounts[i.name] || 0) + i.quantity
totalItemQty += i.quantity