Skip to content

Compute seller profit from entered costs instead of a flat 20% margin - #204

Open
eicyer wants to merge 1 commit into
mainfrom
feat/seller-entered-costs
Open

eicyer wants to merge 1 commit into
mainfrom
feat/seller-entered-costs

Conversation

@eicyer

@eicyer eicyer commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Summary

Seller analytics showed profit as a flat 20% of revenue, which is wrong for most fundraisers. Sellers can now enter real costs, and profit is calculated from them. If no costs are entered, the Profit Goal card says "Add costs to see profit" instead of showing an estimate. This replaces stale draft #134 rather than rebasing it.

Task: Replace the 20% profit margin with seller-entered costs

Changes

backend

  • Migration 20261122120000_add_seller_costs adds nullable fundraisers.expenses and items.unit_cost (MONEY). No backfill is needed: null means "not entered".
  • PROFIT_MARGIN is removed. In its place, computeProfit / hasCompleteCostData calculate profit in the analytics build and in the cached-analytics updates for payment confirmation and pickup. order.services now selects unitCost so those cached updates have it.
  • New admin-only GET /fundraiser/:id/costs. Costs never appear on public endpoints: buyer-facing schemas strip them, and only org admins can read the new endpoint.
  • Analytics response: profit is now number | null. Added fields: has_cost_data, item_cost, expenses.
  • Saving or deleting an item, or updating the fundraiser, clears the cached analytics. The cache key is now fundraiser_analytics_v2_* so cache entries from before the deploy (which lack the new fields) aren't updated in place.

common

  • expenses on Create/UpdateFundraiserBody and unitCost on Create/UpdateFundraiserItemBody. On updates, undefined leaves the value unchanged and null clears it.
  • New SellerItemSchema and FundraiserCostsSchema.

frontend

  • Expenses field in the basic info step and Cost per Unit in the item dialog. Both appear in item lists and on the review step.
  • Profit Goal card: new empty state. The tooltip explains the formula instead of "20% margin". The chart now shows dollars and cents, and the goal sits on its own line so the amount fits inside the ring. A loss shows as an empty ring instead of breaking the chart.
  • Fixed the analytics card staying stale after Save in the edit modal (it now syncs when the page refreshes).
  • diffSavedItems now detects unit-cost-only edits on unpublished fundraisers.

How to test

Seller account, any fundraiser with confirmed or picked-up orders.

  1. pnpm assemble, then cd backend && pnpm migrate:dev, then run both dev servers (
  2. Open the seller fundraiser page. Profit Goal shows "Add costs to see profit" and revenue is unchanged.
  3. Edit → set Expenses (e.g. 20) → Add Items → give one item a Cost per Unit → Save. Without reloading, the card shows revenue − units × cost − expenses.
  4. Clear both values and save. The card goes back to the empty state.
  5. Buyer view: GET /fundraiser/:id/items has no unitCost. GET /fundraiser/:id/costs returns 403 for a non-admin.
  6. cd backend && pnpm test and cd frontend && pnpm test.

Screenshots

Screenshots will be attached in a comment below: before (flat 20%), empty state, profit from entered costs, the Expenses field, the Cost per Unit field, and the item list showing a cost.

Sellers can enter an optional cost per unit on each item and an optional
expenses total on the fundraiser. Profit = revenue from confirmed or
picked-up orders - quantity * unit cost - expenses, using current costs so
edits apply to past orders. Without enough cost data the Profit Goal card
shows an "add costs to see profit" state instead of an estimate.

Costs are seller-only: public schemas strip them, and the edit forms read
them from a new admin-only GET /fundraiser/:id/costs endpoint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
curaise Ready Ready Preview Nov 22, 2026 7:55pm UTC

@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: QUIET
  • Plan: Advanced
  • Run ID: 1dcbce8e-45c5-4a34-8671-b82b3e4c2e2b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@jiminkim214

Copy link
Copy Markdown
Collaborator

Great job Emir! One question: both money inputs store parseFloat(e.target.value) whenever the field is not empty, and parseFloat returns NaN for a value it cannot read. NaN is not null, so it gets saved as a real cost. Could the handler ignore NaN and leave the field null until the number is valid? The rest of the cost flow looks solid :)

This branch was successfully deployed

1 active deployment
Preview — 6c22278c Deployed Nov 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants