1
0
Fork 0
mirror of https://github.com/maziggy/bambuddy.git synced 2026-05-09 08:25:54 +02:00

[PR #705] [CLOSED] [Feature] - Printer optional depreciation cost #1102

Closed
opened 2026-05-07 00:16:01 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/maziggy/bambuddy/pull/705
Author: @wreuel
Created: 3/14/2026
Status: Closed

Base: devHead: feature/printerOptionalDepreciationCost


📝 Commits (4)

  • 5bfd55f Adding the information to have the depreciation cost on the archives
  • b244a73 Adding test fir the depreciation
  • 11a3935 Adding the depreciation cost on stas and archives
  • d949d5b Merge branch 'dev' into feature/printerOptionalDepreciationCost

📊 Changes

20 files changed (+1184 additions, -18 deletions)

View changed files

📝 backend/app/api/routes/archives.py (+39 -0)
📝 backend/app/core/database.py (+16 -0)
📝 backend/app/models/archive.py (+3 -0)
📝 backend/app/models/printer.py (+2 -0)
📝 backend/app/schemas/archive.py (+5 -0)
📝 backend/app/schemas/printer.py (+8 -0)
📝 backend/app/services/usage_tracker.py (+13 -1)
backend/tests/integration/test_depreciation_cost_api.py (+290 -0)
backend/tests/unit/test_depreciation_cost.py (+320 -0)
frontend/src/__tests__/pages/DepreciationCost.test.tsx (+299 -0)
📝 frontend/src/__tests__/pages/StatsPage.test.tsx (+26 -1)
📝 frontend/src/api/client.ts (+6 -0)
📝 frontend/src/components/FilamentTrends.tsx (+2 -2)
📝 frontend/src/components/MetricToggle.tsx (+3 -2)
📝 frontend/src/i18n/locales/de.ts (+6 -0)
📝 frontend/src/i18n/locales/en.ts (+6 -0)
📝 frontend/src/pages/ArchivesPage.tsx (+8 -1)
📝 frontend/src/pages/PrintersPage.tsx (+58 -0)
📝 frontend/src/pages/StatsPage.tsx (+56 -9)
📝 pyproject.toml (+18 -2)

📄 Description

Description

Adds optional per-print depreciation cost tracking based on a printer's purchase price and expected lifespan.

How it works

Users can optionally set Purchase Price and Lifespan (hours) on any printer via the Add or Edit printer modal. When both values are configured, the system automatically calculates a depreciation cost for each print:

depreciation_cost = (purchase_price / lifespan_hours) × (print_time_seconds / 3600)

For example, a $600 printer with a 3,000-hour lifespan costs $0.20/hour. A 2-hour print would have a depreciation cost of $0.40.

Where it appears

  • Archive cards — displayed as a third cost item (Factory icon) alongside filament cost and energy cost
  • Stats page — Prints by Printer — new "Cost" toggle option showing depreciation cost per printer as a horizontal bar chart
  • Stats page — Printer Cost — new bar chart showing depreciation cost distribution by day of week, matching the style of Print Duration, Print Habits, and Print Time of Day

Recalculation

Depreciation cost is calculated:

  • Automatically when a print completes
  • On archive rescan
  • When "Recalculate Costs" is triggered from the Stats page

This means if a printer's purchase price is corrected after the fact, hitting Recalculate Costs will update all associated archives.

Fully optional

Both fields default to null. If either is missing, no depreciation cost is calculated and nothing changes in the UI — existing workflows are completely unaffected.

#694

Fixes #

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Test addition or update

Changes Made

  • Added purchase_price and lifespan_hours fields to the Printer model and schemas
  • Added depreciation_cost field to the PrintArchive model, full response, slim response, and stats aggregation
  • Depreciation is calculated on print completion, archive rescan, and bulk recalculate
  • Added database migration for the 3 new columns
  • Added Purchase Price and Lifespan fields to the Add and Edit Printer modals
  • Added depreciation cost display on archive cards (Factory icon alongside filament and energy costs)
  • Added "Cost" toggle to the Prints by Printer bar chart on the Stats page
  • Added "Printer Cost" bar chart showing depreciation by day of week on the Stats page
  • Added 'cost' option to the MetricToggle component, excluded from unrelated charts
  • Added i18n keys in English and German
  • 18 backend unit tests covering models, schemas, calculation logic, and edge cases
  • 16 backend integration tests covering all API endpoints (printer CRUD, archive responses, slim endpoint, stats, recalculate)
  • 7 frontend tests covering archive card display and printer modal fields
  • 2 frontend tests covering the Stats page charts

Screenshots

image image image image

Testing

  • I have tested this on my local machine
  • I have tested with my printer model:

Checklist

  • My code follows the project's coding style
  • I have commented my code where necessary
  • I have updated the documentation (if needed)
  • My changes generate no new warnings
  • I have tested my changes thoroughly

Additional Notes


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/maziggy/bambuddy/pull/705 **Author:** [@wreuel](https://github.com/wreuel) **Created:** 3/14/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `feature/printerOptionalDepreciationCost` --- ### 📝 Commits (4) - [`5bfd55f`](https://github.com/maziggy/bambuddy/commit/5bfd55f358d1e2baaf5bc3db286872db8f3a3999) Adding the information to have the depreciation cost on the archives - [`b244a73`](https://github.com/maziggy/bambuddy/commit/b244a73ee53faad1a787d8d9eaaca06e1c15c8fe) Adding test fir the depreciation - [`11a3935`](https://github.com/maziggy/bambuddy/commit/11a3935dd586a42704c561a350b73e06b18f78f9) Adding the depreciation cost on stas and archives - [`d949d5b`](https://github.com/maziggy/bambuddy/commit/d949d5b32197865d7f933e4e602b50fa844b13fc) Merge branch 'dev' into feature/printerOptionalDepreciationCost ### 📊 Changes **20 files changed** (+1184 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `backend/app/api/routes/archives.py` (+39 -0) 📝 `backend/app/core/database.py` (+16 -0) 📝 `backend/app/models/archive.py` (+3 -0) 📝 `backend/app/models/printer.py` (+2 -0) 📝 `backend/app/schemas/archive.py` (+5 -0) 📝 `backend/app/schemas/printer.py` (+8 -0) 📝 `backend/app/services/usage_tracker.py` (+13 -1) ➕ `backend/tests/integration/test_depreciation_cost_api.py` (+290 -0) ➕ `backend/tests/unit/test_depreciation_cost.py` (+320 -0) ➕ `frontend/src/__tests__/pages/DepreciationCost.test.tsx` (+299 -0) 📝 `frontend/src/__tests__/pages/StatsPage.test.tsx` (+26 -1) 📝 `frontend/src/api/client.ts` (+6 -0) 📝 `frontend/src/components/FilamentTrends.tsx` (+2 -2) 📝 `frontend/src/components/MetricToggle.tsx` (+3 -2) 📝 `frontend/src/i18n/locales/de.ts` (+6 -0) 📝 `frontend/src/i18n/locales/en.ts` (+6 -0) 📝 `frontend/src/pages/ArchivesPage.tsx` (+8 -1) 📝 `frontend/src/pages/PrintersPage.tsx` (+58 -0) 📝 `frontend/src/pages/StatsPage.tsx` (+56 -9) 📝 `pyproject.toml` (+18 -2) </details> ### 📄 Description ## Description Adds optional per-print depreciation cost tracking based on a printer's purchase price and expected lifespan. How it works Users can optionally set Purchase Price and Lifespan (hours) on any printer via the Add or Edit printer modal. When both values are configured, the system automatically calculates a depreciation cost for each print: depreciation_cost = (purchase_price / lifespan_hours) × (print_time_seconds / 3600) For example, a $600 printer with a 3,000-hour lifespan costs $0.20/hour. A 2-hour print would have a depreciation cost of $0.40. Where it appears - Archive cards — displayed as a third cost item (Factory icon) alongside filament cost and energy cost - Stats page — Prints by Printer — new "Cost" toggle option showing depreciation cost per printer as a horizontal bar chart - Stats page — Printer Cost — new bar chart showing depreciation cost distribution by day of week, matching the style of Print Duration, Print Habits, and Print Time of Day Recalculation Depreciation cost is calculated: - Automatically when a print completes - On archive rescan - When "Recalculate Costs" is triggered from the Stats page This means if a printer's purchase price is corrected after the fact, hitting Recalculate Costs will update all associated archives. Fully optional Both fields default to null. If either is missing, no depreciation cost is calculated and nothing changes in the UI — existing workflows are completely unaffected. ## Related Issue #694 Fixes # ## Type of Change <!-- Mark the relevant option with an "x" --> - [ ] Bug fix (non-breaking change that fixes an issue) - [X] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Code refactoring - [ ] Performance improvement - [ ] Test addition or update ## Changes Made - Added purchase_price and lifespan_hours fields to the Printer model and schemas - Added depreciation_cost field to the PrintArchive model, full response, slim response, and stats aggregation - Depreciation is calculated on print completion, archive rescan, and bulk recalculate - Added database migration for the 3 new columns - Added Purchase Price and Lifespan fields to the Add and Edit Printer modals - Added depreciation cost display on archive cards (Factory icon alongside filament and energy costs) - Added "Cost" toggle to the Prints by Printer bar chart on the Stats page - Added "Printer Cost" bar chart showing depreciation by day of week on the Stats page - Added 'cost' option to the MetricToggle component, excluded from unrelated charts - Added i18n keys in English and German - 18 backend unit tests covering models, schemas, calculation logic, and edge cases - 16 backend integration tests covering all API endpoints (printer CRUD, archive responses, slim endpoint, stats, recalculate) - 7 frontend tests covering archive card display and printer modal fields - 2 frontend tests covering the Stats page charts ## Screenshots <!-- If applicable, add screenshots to demonstrate your changes --> <img width="275" height="539" alt="image" src="https://github.com/user-attachments/assets/584d08f1-6c5b-4030-8fe6-40161af37cfd" /> <img width="555" height="1018" alt="image" src="https://github.com/user-attachments/assets/5b9dd1c6-fac6-4358-9127-1d79d9a4aeac" /> <img width="510" height="271" alt="image" src="https://github.com/user-attachments/assets/30b4e85b-5727-4268-8d12-8c5b59a6f1dd" /> <img width="2155" height="982" alt="image" src="https://github.com/user-attachments/assets/e011207f-1480-46f5-b0ae-722871c3ead8" /> ## Testing <!-- Describe how you tested your changes --> - [X] I have tested this on my local machine - [ ] I have tested with my printer model: <!-- e.g., X1C, P1S, A1 --> ## Checklist - [ ] My code follows the project's coding style - [ ] I have commented my code where necessary - [ ] I have updated the documentation (if needed) - [ ] My changes generate no new warnings - [X] I have tested my changes thoroughly ## Additional Notes <!-- Add any additional information that reviewers should know --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-07 00:16:01 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/bambuddy-maziggy-1#1102
No description provided.