Repository navigation
Stock item cost - #13294
Stock item cost#13294SchrodingersGat wants to merge 53 commits into
Conversation
✅ Deploy Preview for inventree-web-pui-preview canceled.
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #13294 +/- ##
==========================================
+ Coverage 90.56% 90.83% +0.27%
==========================================
Files 915 919 +4
Lines 85236 87475 +2239
Branches 4349 4332 -17
==========================================
+ Hits 77195 79461 +2266
+ Misses 7016 6994 -22
+ Partials 1025 1020 -5
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical defects in cost-range calculations, admin changes, and concurrent writes can roll back disassembly or leave stock cost summaries stale or incomplete.
6 open issues
Refresh cost summaries after bulk admin deletion · New Prevent editing an existing cost entry's stock item · New Serialize cost updates with a per-stock-item lock · New Fix inverted cost bounds when subtracting installed-item costs · New Handle unconvertible installed costs in automatic allocation · New Add data-export mixins to the cost-entry endpoint · New
What changed in this PR
This PR replaces stock items’ single purchase price with per-unit cost entries and cached cost summaries, integrating cost tracking into InvenTree’s inventory operations.
Changes:
- Adds cost models, migrations, permission-controlled APIs, and cost-management UI.
- Carries costs through stock operations and uses summaries for valuation and disassembly.
- Updates tests and documentation for the breaking API and currency-handling changes.
| File | Description |
|---|---|
| src/frontend/tests/pui_forms.spec.ts | Uses URL validation instead of removed price fields. |
| src/frontend/src/tables/stock/StockItemTable.tsx | Displays and filters unit costs. |
| src/frontend/src/tables/stock/StockItemCostEntryTable.tsx | Adds cost-entry management table. |
| src/frontend/src/pages/stock/StockDetailsPanel.tsx | Displays unit and total costs. |
| src/frontend/src/pages/stock/StockDetail.tsx | Adds the Item Costs panel. |
| src/frontend/src/pages/Index/Settings/SystemSettings.tsx | Removes the currency-conversion setting. |
| src/frontend/src/forms/StockForms.tsx | Updates stock duplication and disassembly forms. |
| src/frontend/src/forms/PricingForms.tsx | Adds cost-entry form fields. |
| src/frontend/src/components/wizards/ImportPartWizard.tsx | Removes legacy stock-pricing input. |
| src/frontend/src/components/tables/Filter.tsx | Supports named cost-type statuses. |
| src/frontend/src/components/render/Pricing.tsx | Adds cost-range rendering. |
| src/frontend/src/components/forms/fields/ApiFormField.tsx | Routes table changes through field callbacks. |
| src/frontend/lib/enums/ApiEndpoints.tsx | Defines stock-cost endpoints. |
| src/backend/InvenTree/users/ruleset.py | Includes stock costs in pricing permissions. |
| src/backend/InvenTree/stock/tests.py | Updates merge and removed-field tests. |
| src/backend/InvenTree/stock/test_migrations.py | Tests legacy-price restoration. |
| src/backend/InvenTree/stock/test_api.py | Tests duplication and disassembly costs. |
| src/backend/InvenTree/stock/serializers.py | Exposes summaries and unit-cost inputs. |
| src/backend/InvenTree/stock/models.py | Integrates costs into stock operations. |
| src/backend/InvenTree/stock/migrations/0132_remove_stockitem_purchase_price.py | Removes legacy purchase-price fields. |
| src/backend/InvenTree/stock/fixtures/stock.yaml | Removes obsolete fixture fields. |
| src/backend/InvenTree/stock/api.py | Adds cost copying, filtering, and ordering. |
| src/backend/InvenTree/pricing/test_stock_cost_lifecycle.py | Tests costs across inventory operations. |
| src/backend/InvenTree/pricing/test_pricing.py | Tests purchase-cost contributions to part pricing. |
| src/backend/InvenTree/pricing/test_migrations.py | Tests legacy-cost migration and reversal. |
| src/backend/InvenTree/pricing/test_api.py | Tests cost endpoints and permissions. |
| src/backend/InvenTree/pricing/system_settings.py | Updates stock-pricing setting descriptions. |
| src/backend/InvenTree/pricing/status_codes.py | Defines cost categories. |
| src/backend/InvenTree/pricing/serializers.py | Adds entry and summary serializers. |
| src/backend/InvenTree/pricing/migrations/0004_legacy_purchase_price_entries.py | Migrates existing prices into cost entries. |
| src/backend/InvenTree/pricing/migrations/0003_stock_item_cost.py | Creates cost-entry and summary tables. |
| src/backend/InvenTree/pricing/helpers.py | Adds bulk cost recording helper. |
| src/backend/InvenTree/pricing/api.py | Adds permission-controlled cost APIs. |
| src/backend/InvenTree/pricing/admin.py | Registers cost models in Django admin. |
| src/backend/InvenTree/part/stocktake.py | Values stock using cost summaries. |
| src/backend/InvenTree/order/tests.py | Tests costs recorded during receipt. |
| src/backend/InvenTree/order/system_settings.py | Removes optional receipt currency conversion. |
| src/backend/InvenTree/order/models.py | Records receipt costs and copies shipment costs. |
| src/backend/InvenTree/InvenTree/api_version.py | Documents API version 583 changes. |
| src/backend/InvenTree/build/test_build.py | Tests cost copying during consumption. |
| src/backend/InvenTree/build/models.py | Copies costs to split consumed stock. |
| src/backend/InvenTree/audit/tests.py | Tests cost auditing and relation exclusions. |
| src/backend/InvenTree/audit/registry.py | Excludes reverse one-to-one audit fields. |
| docs/mkdocs.yml | Adds stock-cost documentation navigation. |
| docs/docs/stock/disassemble.md | Explains component-cost allocation. |
| docs/docs/stock/costs.md | Documents stock-cost management. |
| docs/docs/settings/permissions.md | Links stock-cost permission guidance. |
| docs/docs/purchasing/supplier.md | Updates pack-size cost guidance. |
| docs/docs/purchasing/purchase_order.md | Explains costs recorded at receipt. |
| docs/docs/part/stocktake.md | References unit costs for valuation. |
| docs/docs/part/pricing.md | Explains stock-cost pricing contributions. |
| docs/docs/concepts/pricing.md | Introduces stock-cost concepts. |
| CHANGELOG.md | Records features and breaking changes. |
| .github/workflows/frontend.yaml | Selects migration-compatible frontend test data. |
Review effort: Balanced
- Enable data export for stock pricing - Update admin readonly fields - Fix min/max validation - additional unit tests
|
Very interesting change; I think it might be worthwhile to consider adding ancestry to entries such that it is possible to connect costs to events. That would be helpful if a pricing entry was made with an error, someones tariffs are declared illegal or there are some rebates are applied after the fact for a shipment. |
|
@matmair the pricing entries are tracked in the audit log, perhaps that is enough, without requiring a specific different tracking table? |
|
they might be cleaned up and they only link one element deep |
|
@matmair I have added historical tracking as a future goal for this |


Large (breaking) change to how unit costs are stored against stock items. This change allows multiple costs to be recorded against a single stock item, and for other "cost sources" (not just purchase price). This enabled us (in a future PR) to support build costs, custom plugin costs, manufacturing cost, etc
Existing Behaviour
StockItemmodel in thepurchase_pricefieldNew Behaviour
purchase_pricefieldStockCostEntrytable which stores mutiple unit cost entries from different sourcesStockCostSummaryfor any given stock itemImplemented
Future Work
This PR provides for future implementation of: