Review follow-ups: PR #638 — fix(analytics): honest sales/profit numbers — losses, $0 cost is unknown, no double-counting, no voided, date-based horizons #881
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Non-blocking findings from the auto code review of PR #638 (fix(analytics): honest sales/profit numbers — losses, $0 cost is unknown, no double-counting, no voided, date-based horizons) — captured for batch cleanup rather than blocking the PR.
Commit
9c4e2e3· https://github.com/Gambit-Inc/gambit/pull/638SHOULD-FIX:
frontend/app/gambit/GambitLiveScreens.jsx:970(and:35-41,formatCurrencyFromCents) — theDashboardPage's "Profit" tile renderssales30.estimated_profit_centsthroughformatCurrencyFromCents, which is`$${(value/100).toLocaleString(...)}`— for a negative value this produces$-12.34instead of-$12.34. Before this PRestimated_profit_centswas floored at 0 (max(0, price - cost)), so this path never carried a negative number; this diff's backend change (backend/app/routes/inventory_items.py:2982/3003, dropping the floor so real losses show) now feeds negatives straight into a formatter that was never fixed for sign placement (unlikecompactCentsin the same file, andformatCompactCentsin mobile, which this diff did fix). A shop running a net loss over 30 days sees a malformed dollar figure on the live dashboard.backend/app/routes/inventory_items.py:2770-2781— themarket_trends_by_gamefix assumesEbaySale.estimated_profit_centsis stored per unit ("see the summary/list endpoints"), aligning it withinventory_ebay_sales_summary's pre-existing* qtyhandling (line 2974, unchanged by this diff). There is no production code path that ever writes this column (onlybackend/scripts/seed_showcase_vendor.py, and thereqtyis always 1, so it can't distinguish per-unit vs. total). The two endpoints are now internally consistent with each other, but that consistency is unverified against the column's actual real-world semantics — if a future writer (or a legacy value already sitting in prod) populates it as a line-total, both endpoints will silently overcount by the sale's qty.NITS:
backend/app/routes/inventory_items.py:2065/2136— "ask AND cost known" only checkscost_each_cents > 0but merelyask_each_cents is not None(an ask of exactly$0is treated as "known" and still contributes(0 - cost) * qtyas a negative potential-profit with0basis). Consistent between the Python and SQL paths, so no parity bug, but it's an asymmetric application of the "honest numbers" rule the rest of this PR establishes for cost.Filed from a Claude Code session