Skip to content

Stock item cost - #13294

Open
SchrodingersGat wants to merge 53 commits into
inventree:masterfrom
SchrodingersGat:stock-item-cost
Open

SchrodingersGat wants to merge 53 commits into
inventree:masterfrom
SchrodingersGat:stock-item-cost

Conversation

@SchrodingersGat

@SchrodingersGat SchrodingersGat commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

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

  • Cost data stored against StockItem model in the purchase_price field
  • Only a single cost entry is stored, with no historical tracking, cost type, or justification
  • Only "purchase" cost is stored

New Behaviour

  • Removed the purchase_price field
  • New StockCostEntry table which stores mutiple unit cost entries from different sources
  • Stores original currency data, cost source, and other optional metadata
  • Consolidates multiple cost entries into a single StockCostSummary for any given stock item

Implemented

Future Work

This PR provides for future implementation of:

  • Track cost history over time, keep historical cost entries
  • Build / assembly costs
  • Landed costs / shipping costs / fees
  • Separation and introspection of different cost sources
  • Allowing plugins to inject additional costs as required

@SchrodingersGat SchrodingersGat added this to the 1.8.0 milestone Nov 16, 2026
@SchrodingersGat SchrodingersGat added enhancement This is an suggested enhancement or new feature api Relates to the API pricing Pricing functionality breaking Indicates a major update or change which breaks compatibility refactor User Interface Related to the frontend / User Interface labels Nov 16, 2026
@netlify

netlify Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for inventree-web-pui-preview canceled.

Name Link
🔨 Latest commit df25e6d
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/6b0befab1e0d7328416b565d

@SchrodingersGat
SchrodingersGat marked this pull request as draft November 16, 2026 07:35
@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.81729% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.83%. Comparing base (2560725) to head (df25e6d).

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     
Flag Coverage Δ
backend 94.25% <98.81%> (+0.20%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Backend Apps 94.53% <98.05%> (+0.05%) ⬆️
Backend General 95.05% <ø> (ø)
Frontend 77.71% <ø> (+0.06%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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
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

Comment thread src/backend/InvenTree/pricing/admin.py Resolved
Comment thread src/backend/InvenTree/pricing/admin.py Resolved
Comment thread src/backend/InvenTree/pricing/api.py Resolved
Comment thread src/backend/InvenTree/stock/models.py Resolved
Comment thread src/frontend/src/forms/StockForms.tsx Resolved
@matmair

matmair commented Nov 23, 2026

Copy link
Copy Markdown
Member

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.

@SchrodingersGat

Copy link
Copy Markdown
Member Author

@matmair the pricing entries are tracked in the audit log, perhaps that is enough, without requiring a specific different tracking table?

@matmair

matmair commented Nov 23, 2026

Copy link
Copy Markdown
Member

they might be cleaned up and they only link one element deep

@SchrodingersGat

Copy link
Copy Markdown
Member Author

@matmair I have added historical tracking as a future goal for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Relates to the API breaking Indicates a major update or change which breaks compatibility enhancement This is an suggested enhancement or new feature pricing Pricing functionality refactor User Interface Related to the frontend / User Interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants