Implement diaper purchase log and weighted average cost calculation#1076
Implement diaper purchase log and weighted average cost calculation#1076clentfort wants to merge 5 commits into
Conversation
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]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
👋 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 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]>
|
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]>
… 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]>

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