Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Implement diaper purchase log and weighted average cost calculation#1076

Open
clentfort wants to merge 5 commits into
mainfrom
diaper-purchase-log-5131280432727525085
Open

Implement diaper purchase log and weighted average cost calculation#1076
clentfort wants to merge 5 commits into
mainfrom
diaper-purchase-log-5131280432727525085

Conversation

@clentfort

Copy link
Copy Markdown
Owner

Introduced a diaper purchase log system that calculates a weighted average cost per diaper based on purchases. Updated the diaper change tracking to record the cost at the time of the event, ensuring accurate historical stats. Added UI for logging purchases and viewing estimated stock in settings. Includes a backfill migration for legacy data.


PR created automatically by Jules for task 5131280432727525085 started by @clentfort

This change introduces a purchase log for diapers, allowing users to
track packs bought with their count and price. This data is used to
calculate a weighted average cost per diaper for each brand, which is
then recorded on individual diaper changes to ensure accurate historical
statistics even as prices change.

Key changes:
- Added `DiaperPurchase` type and `diaperPurchases` table.
- Added a `cost` field to `DiaperChange` to record the price at the time
  of the event.
- Implemented a migration to backfill costs for existing diaper changes.
- Added UI in Diaper Settings to log new purchases and display estimated
  remaining stock.
- Updated cost statistics and charts to prioritize recorded costs over
  current brand prices.
- Preserved existing behavior for reusable diapers.

Co-authored-by: clentfort <[email protected]>
@vercel

vercel Bot commented Jun 3, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
adameter Ready Ready Preview Jun 3, 2026 2:23pm

@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

- Updated `run-if-needed.test.ts` to include the new diaper cost backfill migration.
- Applied Prettier formatting to modified files.
- Fixed type error in `backfillDiaperChangeCostMigration`.
- Safeguarded weighted average calculation against division by zero.
- Improved cost chart logic to correctly handle zero-cost diapers.

Co-authored-by: clentfort <[email protected]>
@clentfort

Copy link
Copy Markdown
Owner Author

I dont like that adding a product and logging a purchase are somehow different things. that makes very little sense from a UX perspective. it might make sense from a data perspective but UX is not good the way it was implemented.

@google-labs-jules

Copy link
Copy Markdown
Contributor

I dont like that adding a product and logging a purchase are somehow different things. that makes very little sense from a UX perspective. it might make sense from a data perspective but UX is not good the way it was implemented.

I've unified the product management and purchase logging into a single form. Now, when you add a new brand (either from settings or the quick-add menu) or click the purchase icon, you can record the pack details directly within the brand form. This ensures a smoother UX while still maintaining the accurate weighted average calculation.

- Integrated purchase logging directly into the `ProductForm`.
- Users can now record a pack purchase when creating a new brand or
  updating an existing one.
- Removed the separate `PurchaseLogDialog` to improve UX consistency.
- Updated the quick-add product flow in the tracker to support initial
  purchase recording.
- Maintained weighted average calculation logic within the unified flow.

Co-authored-by: clentfort <[email protected]>
- Updated `product-form.test.tsx` to accommodate the new `onSave`
  signature which now includes an optional second argument for purchase
  data.
- Applied Prettier formatting to `page.tsx` and `product-form.tsx` to
  resolve CI linting failures.

Co-authored-by: clentfort <[email protected]>
@clentfort

Copy link
Copy Markdown
Owner Author
grafik

Cost per diaper does no longer make sense unless its a reusable diaper type, right? also could we have something like an autocomplete for logging new packs?

… autocomplete

- Hidden the manual 'Cost per Diaper' input for non-reusable diapers,
  replacing it with a calculated average display.
- Added a brand name autocomplete using a datalist populated from
  common diaper brands.
- Enhanced the 'Log Purchase' section styling to be more integrated
  and prominent.
- Updated unit tests to reflect the new UI logic and visibility
  states.

Co-authored-by: clentfort <[email protected]>
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.

1 participant