Skip to content

bug(api/purchases): Total Upfront/Monthly/Annual Savings KPIs include cancelled purchases #736

Description

@cristim

Symptom (QA row 278, Purchases page > Approval queue step 1.6)

When an admin clicks Cancel on a pending purchase request in the Approval queue:

  • Counts for pending and cancelled purchases update correctly.
  • BUT Total Upfront Spent, Monthly Saving, and Annual Savings all update as if the cancelled purchase had been approved, adding its committed/saved amounts to the KPIs.

A cancelled purchase represents zero committed spend and zero realized savings. The KPIs must exclude cancelled-status executions.

Reproduction

  1. Send a high-cost commitment for approval (so the delta is large and visible).
  2. Note the Total Upfront Spent / Monthly Saving / Annual Savings KPIs on the Purchases page.
  3. Click Cancel on that pending request in the Approval queue.
  4. Observe: pending count -1, cancelled count +1 (correct). But Total Upfront Spent +cost_of_cancelled_purchase, Monthly Saving +its_savings, etc. (wrong — these should stay unchanged.)

Fix direction

Trace the KPI aggregation:

  • Likely a backend handler that sums all execution rows without filtering on status (or status set is too permissive, e.g., status IN ('approved', 'completed', 'cancelled') instead of status IN ('approved', 'completed')).
  • Search for "Total Upfront Spent" / "Monthly Saving" / "Annual Savings" in internal/api/ and frontend/src/.
  • The cancel-purchase mutation likely transitions to cancelled but doesn't subtract from these aggregates (or the GET handler includes cancelled in the SUM).

Whichever is the data source, exclude status='cancelled' from these three aggregates.

Tests required

  • API integration test: create N approved purchases + 1 pending; capture KPI values; cancel the pending; assert KPIs unchanged.
  • UI test: same scenario in the browser; assert the displayed numbers don't change after cancellation.

Source of finding

QA verification spreadsheet row 278 (step 1.6 of Approval queue).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions