Skip to content

[Refactor] Stock tracking audit - #13101

Merged
SchrodingersGat merged 26 commits into
inventree:masterfrom
SchrodingersGat:stock-tracking-audit
Oct 27, 2026
Merged

SchrodingersGat merged 26 commits into
inventree:masterfrom
SchrodingersGat:stock-tracking-audit

Conversation

@SchrodingersGat

@SchrodingersGat SchrodingersGat commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Related PRs

This PR migrates the legacy "stock item tracking" table (which was manually crafted, and only tracked a subset of model changes) to the new audit log table.

Existing (legacy) entries are migrated to the new system.

Breaking Change

This is a breaking change - the existing "stock tracking" API endpoints are removed, and stock tracking entries have been migrated into the global audit log model

Example Screenshot

image image

@SchrodingersGat SchrodingersGat added this to the 1.7.0 milestone Oct 25, 2026
@SchrodingersGat SchrodingersGat added api Relates to the API breaking Indicates a major update or change which breaks compatibility documentation refactor migration Data or schema migrations User Interface Related to the frontend / User Interface full-run Always do a full QC CI run labels Oct 25, 2026
@netlify

netlify Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for inventree-web-pui-preview ready!

Name Link
🔨 Latest commit e301d17
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/6adff6473a7b8f14d017e75a
😎 Deploy Preview https://deploy-preview-13101--inventree-web-pui-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 93 (🔴 down 2 from production)
Accessibility: 82 (no change from production)
Best Practices: 92 (no change from production)
SEO: 78 (no change from production)
PWA: -
View the detailed breakdown and full score reports
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.88121% with 210 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.77%. Comparing base (f61e6d7) to head (e301d17).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #13101      +/-   ##
==========================================
- Coverage   86.87%   86.77%   -0.11%     
==========================================
  Files        1557     1561       +4     
  Lines      109449   110189     +740     
  Branches    12091    12080      -11     
==========================================
+ Hits        95087    95618     +531     
- Misses      14296    14505     +209     
  Partials       66       66              
Flag Coverage Δ
backend 91.18% <77.24%> (-0.34%) ⬇️
migrations-mysql 33.46% <21.67%> (-0.11%) ⬇️
migrations-postgresql 33.47% <21.67%> (-0.11%) ⬇️
migrations-sqlite 33.47% <21.67%> (-0.11%) ⬇️

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

Components Coverage Δ
Backend Apps 92.71% <98.47%> (+0.07%) ⬆️
Backend General 94.78% <ø> (ø)
Frontend 79.28% <ø> (-0.10%) ⬇️
🚀 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 audit-history loss risks, hidden transaction details, and per-allocation database lookups need correction before approval.

4 open issues
What changed in this PR

Migrates stock tracking into the shared audit log, extending the existing change-history system to cover stock operations and preserve legacy history.

Changes:

  • Adds named audit events, transaction notes, reference details, and legacy-data migration.
  • Replaces stock-tracking endpoints and UI with permission-filtered audit history.
  • Updates stock, order, and build integrations, regression tests, and documentation.
File Description
src/​frontend/​tests/​pages/​pui_stock.spec.ts Tests stock and part audit-history views.
src/​frontend/​src/​tables/​stock/​StockTrackingTable.tsx Removes the legacy tracking table.
src/​frontend/​src/​tables/​general/​AuditLogTable.tsx Displays event labels, details, and notes.
src/​frontend/​src/​pages/​stock/​StockDetail.tsx Replaces tracking with the History panel.
src/​frontend/​src/​pages/​part/​PartStockHistoryDetail.tsx Removes the legacy tracking accordion.
src/​frontend/​src/​pages/​Index/​Settings/​SystemSettings.tsx Removes stock-specific retention settings.
src/​frontend/​src/​forms/​StockForms.tsx Removes the copy-history option.
src/​frontend/​src/​components/​panels/​HistoryPanel.tsx Allows history visibility for non-staff users.
src/​frontend/​lib/​enums/​ModelInformation.tsx Points stock history to the audit endpoint.
src/​frontend/​lib/​enums/​ApiEndpoints.tsx Removes the stock-tracking endpoint constant.
src/​backend/​InvenTree/​users/​ruleset.py Removes legacy tracking-model permissions.
src/​backend/​InvenTree/​stock/​tests.py Converts stock-history assertions to audit entries.
src/​backend/​InvenTree/​stock/​test_migrations.py Tests legacy history conversion.
src/​backend/​InvenTree/​stock/​test_audit.py Adds stock-event and permission tests.
src/​backend/​InvenTree/​stock/​test_api.py Updates API tests for audit-backed history.
src/​backend/​InvenTree/​stock/​tasks.py Removes the legacy retention task.
src/​backend/​InvenTree/​stock/​serializers.py Uses audit batching and removes tracking serialization.
src/​backend/​InvenTree/​stock/​migrations/​0130_delete_stockitemtracking.py Drops the legacy tracking model.
src/​backend/​InvenTree/​stock/​migrations/​0129_migrate_stock_tracking_to_audit_log.py Converts legacy tracking rows into audit entries.
src/​backend/​InvenTree/​stock/​api.py Removes tracking routes and audits serialized creation.
src/​backend/​InvenTree/​stock/​admin.py Removes legacy tracking administration.
src/​backend/​InvenTree/​stock/​__init__.py Updates the documented model list.
src/​backend/​InvenTree/​order/​test_sales_order.py Updates shipment-history assertions.
src/​backend/​InvenTree/​order/​test_audit.py Tests stock events generated by orders.
src/​backend/​InvenTree/​order/​test_api.py Tests receipt history and serialized statuses.
src/​backend/​InvenTree/​order/​serializers.py Adopts audit batching and shared note limits.
src/​backend/​InvenTree/​order/​models.py Records receiving, shipping, and return events.
src/​backend/​InvenTree/​InvenTree/​unit_test.py Adds stock audit-query helpers.
src/​backend/​InvenTree/​InvenTree/​test_commands.py Removes obsolete tracking-model test coverage.
src/​backend/​InvenTree/​InvenTree/​tasks.py Updates the batching docstring reference.
src/​backend/​InvenTree/​InvenTree/​serializers.py Updates duplication documentation.
src/​backend/​InvenTree/​InvenTree/​models.py Adds model-level audit event declarations.
src/​backend/​InvenTree/​InvenTree/​management/​commands/​bulkloaddata.py Updates documentation examples only.
src/​backend/​InvenTree/​InvenTree/​apps.py Cleans up obsolete tracking schedules.
src/​backend/​InvenTree/​InvenTree/​api_version.py Documents API version 566 and breaking changes.
src/​backend/​InvenTree/​common/​setting/​user.py Updates history-setting help text.
src/​backend/​InvenTree/​common/​setting/​system.py Removes legacy stock-retention settings.
src/​backend/​InvenTree/​build/​test_build.py Uses audit history for idempotency checks.
src/​backend/​InvenTree/​build/​test_audit.py Tests build-generated stock events.
src/​backend/​InvenTree/​build/​test_api.py Converts consumption-history assertions.
src/​backend/​InvenTree/​build/​serializers.py Uses the stock transaction-note limit.
src/​backend/​InvenTree/​build/​models.py Records build stock operations through audit events.
src/​backend/​InvenTree/​audit/​tests.py Tests events, batching, permissions, and redaction.
src/​backend/​InvenTree/​audit/​serializers.py Exposes event details with reference redaction.
src/​backend/​InvenTree/​audit/​registry.py Resolves model-specific event choices and labels.
src/​backend/​InvenTree/​audit/​models.py Stores event types, notes, and deltas.
src/​backend/​InvenTree/​audit/​migrations/​0003_event_type.py Adds event and note database fields.
src/​backend/​InvenTree/​audit/​helpers.py Adds event contexts and bulk-creation recording.
src/​backend/​InvenTree/​audit/​context.py Tracks pending events and batch correlation IDs.
src/​backend/​InvenTree/​audit/​api.py Broadens authenticated access and adds event filtering.
docs/​docs/​stock/​tracking.md Documents audit-backed stock history and retention.
docs/​docs/​stock/​index.md Updates the stock-tracking overview.
docs/​docs/​stock/​disassemble.md Describes disassembly audit events.
docs/​docs/​stock/​adjust.md Documents movement events.
docs/​docs/​sales/​return_order.md Links returns to stock audit history.
docs/​docs/​plugins/​mixins/​validation.md Corrects traceability documentation links.
docs/​docs/​manufacturing/​output.md Corrects the serial-generation guide link.
docs/​docs/​concepts/​audit.md Documents events, permissions, and stock coverage.
CHANGELOG.md Announces the breaking tracking migration.

Review effort: Balanced

Comment thread src/backend/InvenTree/audit/helpers.py Resolved
Comment thread src/backend/InvenTree/build/models.py Resolved
@SchrodingersGat
SchrodingersGat merged commit c4280c2 into inventree:master Oct 27, 2026
53 checks passed
@SchrodingersGat
SchrodingersGat deleted the stock-tracking-audit branch October 27, 2026 04:14
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 documentation full-run Always do a full QC CI run migration Data or schema migrations refactor User Interface Related to the frontend / User Interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactor] Move stock history tracking to audit log table

2 participants